atcoder#ABC302C. [ABC302C] Almost Equal
[ABC302C] Almost Equal
Score : points
Problem Statement
You are given strings , each of length , consisting of lowercase English letter. Here, are pairwise distinct.
Determine if one can rearrange these strings to obtain a new sequence of strings such that:
- for all integers such that , one can alter exactly one character of to another lowercase English letter to make it equal to .
Constraints
- is a string of length consisting of lowercase English letters.
- are pairwise distinct.
Input
The input is given from Standard Input in the following format:
Output
Print Yes
if one can obtain a conforming sequence; print No
otherwise.
4 4
bbed
abcd
abed
fbed
Yes
One can rearrange them in this order: abcd
, abed
, bbed
, fbed
. This sequence satisfies the condition.
2 5
abcde
abced
No
No matter how the strings are rearranged, the condition is never satisfied.
8 4
fast
face
cast
race
fact
rice
nice
case
Yes