P26433 [AtCoder] Comment Display
提高+
题目描述

Problem Description

Niwango is thinking of a new way to display comments on a video site.

Comments will be streamed from left to right at a speed of 1 character per second. For a video with $N$ comments, they will be streamed in any order, one per second. That is, the $i$-th comment streamed will be displayed $i-1$ characters offset from the first comment.

Niwango wants to create the situation where "all characters at the same position in $N$ comments are the same character" at least once. This situation means that there exists an integer $X$ and a character $Y$ such that for all $i$, the $X-i$-th character of the $i$-th comment streamed is $Y$.

Input Format

The input is given from the standard input in the following format:

$N$ $S_1$ $S_2$ : $S_N$

  • The first line contains a single integer $N\ (2\ ≦\ N\ ≦\ 200)$, representing the number of comments.
  • The next $N$ lines contain the comment information. The $i$-th line contains a single string $S_i$. $S_i$ is a string of length at least 1 consisting only of lowercase alphabets (a-z), representing the $i$-th comment. The sum of the lengths of all comment strings is at most $10^5$.

Output Format

If it is possible to determine the order of streaming comments such that "all characters at the same position in $N$ comments are the same character" at least once, output YES. Otherwise, output NO. End the output with a newline.

Sample Input and Output

Sample Input #1

3
abcd
bdac
aca

Sample Output #1

YES

Sample Input #2

4
dwango
niconico
niwango
ginza

Sample Output #2

NO

Notes/Hints

Partial Points

This problem has partial points.

  • If you correctly solve dataset 1 where $N\ ≦\ 52$ and the sum of the lengths of comment strings is at most $2,525$, you will be awarded 30 points.
  • If you correctly solve all test cases, you will be awarded an additional 60 points.

Sample Explanation 1

If comments are streamed in the order of the 2nd comment, 1st comment, and 3rd comment, they will be displayed as follows:

bdac
 abcd
  aca

The characters at the 4th position from the left are all c.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 abcd bdac aca
样例输出
YES