/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
問題文
文字列が書かれたカードが N 枚与えられます。i 番目のカードには文字列 S_i が書かれています (1\leq i\leq N) 。
以下の条件を満たすように N 枚のカードから相異なる 3 枚のカードを選ぶことができるか判定してください。
- 選んだ 3 枚のカードのうちある 2 枚のカードに書かれている文字列をいずれかの順番で連結したものが、残りの 1 枚のカードに書かれている文字列と一致する。
制約
- 3\leq N\leq 10
- N は整数
- S_i は英小文字からなる長さ 1 以上 10 以下の文字列
- S_i\neq S_j(i\neq j)
入力
入力は以下の形式で標準入力から与えられる。
N S_1 S_2 \vdots S_N
出力
条件を満たすような 3 枚のカードの選び方が存在する場合は Yes を、存在しない場合は No を出力せよ。
入力例 1
4 ing string abc str
出力例 1
Yes
1,2,4 枚目のカードを選び、4,1 枚目に書かれている文字列をこの順に連結させることで 2 枚目のカードに書かれている文字列と一致させることができます。
入力例 2
3 abc def abcabc
出力例 2
No
選ぶカードは相異なる必要があります。
入力例 3
6 vxyzbkfvmb wjrbbfogg jmeedirhy bkfvmb vxyz acheswkrui
出力例 3
Yes
Problem Statement
You are given N cards with strings written on them. The i-th card has a string S_i written on it (1\leq i\leq N).
Determine if one can choose three distinct cards from the N cards so that:
- the concatenation of the strings on two of the cards in any order coincides with the string written on the other.
Constraints
- 3\leq N\leq 10
- N is an integer.
- S_i is a string of lowercase English letters of length between 1 and 10, inclusive.
- S_i\neq S_j(i\neq j)
Input
The input is given from Standard Input in the following format:
N S_1 S_2 \vdots S_N
Output
Print Yes if there is a conforming choice of three cards, and No otherwise.
Sample Input 1
4 ing string abc str
Sample Output 1
Yes
Choosing the 1-st, 2-nd, and 4-th cards is valid because the concatenation of the strings written on the 4-th and 1-st in this order coincides with the string written on the 2-nd.
Sample Input 2
3 abc def abcabc
Sample Output 2
No
The chosen cards must be pairwise distinct.
Sample Input 3
6 vxyzbkfvmb wjrbbfogg jmeedirhy bkfvmb vxyz acheswkrui
Sample Output 3
Yes