eolymp
bolt
Try our new interface for solving problems
Problems

Tetris Alphabet

Tetris Alphabet

The game of Tetris is played with four-connected blocks falling down the well having \textbf{N} rows and \textbf{20} columns. Each figure is marked with a unique English letter from '\textbf{A}' to '\textbf{Z}'. Your program must, given the state of the well, determine the order in which the blocks fell down. \InputFile The first line of input file contains integer \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{50}) --- number of rows. Following \textbf{N} lines contain \textbf{20} characters each, with characters that are either a letter from '\textbf{A}' to '\textbf{Z}' or the dot character (\textbf{ASCII 46}), representing an empty cell. \OutputFile Output file must contain a string of letters indicating the order in which figures fell down. If there is more than one order, lexicographically smallest one must be printed. Input data will guarantee that at least one nonempty order exists.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6
...........XX.......
..........MMMM......
..........K.........
........KKK.........
.....ZAAA.FFF.......
.....ZZZA..F.B......
Output example #1
BFZAKMX
Source ACM ICPC 2002/2003 Quarterfinal (Far-Eastern Subregion) Vladivostok, November 2, 2002.