| UDESC Selection Contest 2025-1 |
|---|
| Finished |
Rondônia Jones is an archaeologist and explorer known for his extensive knowledge of ancient civilizations and their languages.
During one of his expeditions, he discovered a stone from the Brutense people (dated $$$998244353$$$ B.C.) containing a short introductory text followed by $$$N$$$ mysterious inscriptions: all of them were words made up of Latin alphabet letters (from "a" to "z"). The text explained, in a long-forgotten language, that all these words were non-decreasing. This led Jones to expect that they would look like "abcdef" or "aacgmz" — non-decreasing words, assuming the standard Latin alphabetical order. However, contrary to expectations, the letters appeared to follow a strange order unfamiliar to him.
Now, Jones wants to know whether there exists some ordering of the Latin alphabet letters that makes the inscribed words obey the rule stated in the text. If so, he asks you to print one such possible order of the alphabet, as it would be crucial for his studies of the Brutense people.
The first line of input contains an integer $$$N$$$ $$$(1 \leq N \leq 10^5)$$$.
The next $$$N$$$ lines follow. The $$$i$$$-th of these contains a word $$$s_i$$$.
It is guaranteed that the sum of all $$$|s_i|$$$ is less than or equal to $$$10^6$$$.
Print one line with "SIM" (YES) or "NAO" (NO), depending on whether a valid answer exists.
If the answer is YES, print an additional line with a permutation of the 26 Latin alphabet letters that satisfies the requirements. If multiple answers are possible, print any one.
3abcdefghi
SIM abcdefghijklmnopqrstuvwxyz
3acbzcbghi
SIM adefghijklmnopqrstuvwxyzcb
4brutebrutabrutotrem
NAO
| Name |
|---|


