#ARC141F. [ARC141F] Well-defined Abbreviation

[ARC141F] Well-defined Abbreviation

Score : 11001100 points

Problem Statement

You are given NN srings Si (1iN)S_i\ (1\le i \le N) consisting of A, B, C, D.

Consider the operation below on a string TT consisting of A, B, C, D.

  • Repeat the following until TT contains none of the strings SiS_i as a substring.- Choose an SiS_i and one of its occurrences in TT, remove that occurrence from TT, and concatenate the remaining parts.
  • Choose an SiS_i and one of its occurrences in TT, remove that occurrence from TT, and concatenate the remaining parts.
What is a substring? A substring of a string is its contiguous subsequence. For example, A, AB, and BC are substrings of ABC, while BA and AC are not.
We say that the string $T$ is *bad* when multiple strings can result from the operation above.

Determine whether a bad string exists.

Constraints

  • 1N1061 \leq N \leq 10^6
  • 1Si2×1061 \leq |S_i| \leq 2 \times 10^6
  • S1+S2++SN2×106|S_1|+|S_2|+\dots +|S_N| \leq 2 \times 10^6
  • SiSjS_i \neq S_j if iji\neq j.
  • SiS_i is a string consisting of A, B, C, D.

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

If a bad string exists, print Yes.

Otherwise, print No.

3
A
B
C
No

The only string we can get from TT is what remains after removing all occurrences of A, B, C from TT.

1
ABA
Yes

For example, from T=T= ABABA, we can get two strings: AB and BA, so TT is a bad string.

4
CBA
ACB
AD
CAB
Yes