CF731D 80-th Level Archeology
Description
Archeologists have found a secret pass in the dungeon of one of the pyramids of Cycleland. To enter the treasury they have to open an unusual lock on the door. The lock consists of $ n $ words, each consisting of some hieroglyphs. The wall near the lock has a round switch. Each rotation of this switch changes the hieroglyphs according to some rules. The instruction nearby says that the door will open only if words written on the lock would be sorted in lexicographical order (the definition of lexicographical comparison in given in notes section).
The rule that changes hieroglyphs is the following. One clockwise rotation of the round switch replaces each hieroglyph with the next hieroglyph in alphabet, i.e. hieroglyph $ x $ ( $ 1
Input Format
N/A
Output Format
N/A
Explanation/Hint
Word $ a_{1},a_{2},...,a_{m} $ of length $ m $ is lexicographically not greater than word $ b_{1},b_{2},...,b_{k} $ of length $ k $ , if one of two conditions hold:
- at first position $ i $ , such that $ a_{i}≠b_{i} $ , the character $ a_{i} $ goes earlier in the alphabet than character $ b_{i} $ , i.e. $ a $ has smaller character in the first position where they differ;
- if there is no such position $ i $ and $ m