#K44092. Tile Arrangement

    ID: 27454 Type: Default 1000ms 256MiB

Tile Arrangement

Tile Arrangement

You are given a collection of tile rows, each represented by a string of lowercase letters. Each character in the string represents a colored tile. Your task is to verify whether an arrangement of these tile rows satisfies the condition that no two adjacent rows have tiles of the same color in the same column. In other words, given nn rows, for every adjacent pair of rows (row ii and row i+1i+1) and for every column index jj, the condition [ tile[i][j] \neq tile[i+1][j] ] must hold.

The input will contain multiple test cases. For each test case, the first line contains an integer nn representing the number of rows. This is followed by nn lines, each containing a string. A test case with n=0n=0 indicates the end of input. For each test case, output "YES" if the arrangement satisfies the condition, or "NO" otherwise.

inputFormat

The input consists of multiple test cases. Each test case begins with a line containing an integer nn (n1n \ge 1) indicating the number of tile rows. It is followed by nn lines, each containing a string representing a row of tiles. The input terminates with a line containing a single zero (0), which should not be processed.

outputFormat

For each test case, output a single line containing either "YES" if the arrangement is valid, or "NO" if it is not.## sample

3
abc
def
ghi
0
YES

</p>