Interesting breaks
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Finally, Zenik and Marichka have reached the Carpathians! But this is only the beginning of their adventures. Next comes the hiking part of the journey.
Of course, from time to time, they need to take breaks to restore their strength, drink delicious Transcarpathian wine, and have a little fun. As you might have guessed, Zenik and Marichka love games very much. This time they decided to play an incredibly interesting (and strange) game again. Zenik comes up with a list of \(n\) strings, and Marichka has to say whether it is possible to change the order of characters in the alphabet so that the list invented by Zenik is lexicographically sorted.
Input
The first line contains a single integer \(n\) — the number of strings.
The next \(n\) lines contain the strings from Zenik’s list.
Output
In a single line, output Yes if the required character
order in the alphabet exists. Otherwise, output No.
Constraints
\(1 \le n\le 10^{5}\),
\(1 \le \sum_{i=1} ^n |s_i| \le 10^5\),
all strings consist of lowercase Latin letters.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 3 ba ac ab | Yes |
| Input (stdin) | Output (stdout) |
|---|---|
| 3 ab ba ad | No |
Notes
A list of \(n\) strings is called lexicographically sorted if \(s_i\) is not lexicographically greater than \(s_{i+1}\) for all \(i\) from 1 to \(n - 1\).
A string \(a\) is called lexicographically greater than a string \(b\) if \(b\) is a prefix of \(a\) or the character \(a_k\) appears in the alphabet after the character \(b_k\), where \(k\) is the smallest index such that \(a_k \ne b_k\).
In the first example, an alphabet with the following character order
would work: cba.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|