Decoding Ancient Messages
Time limit2sMemory limit128 MB
Choose one cell in each row and column so the chosen letters, sorted ascending, are lexicographically smallest.
Problem
Professor Y digs up ancient artifacts. The stone plates he found recently carry letters each, arranged in an grid, and one plate holds one message of length . The procedure for reading a plate is this.
- Pick letters from the grid so that no two picked letters lie in the same row and no two lie in the same column.
- Concatenate the picked letters in any order you like to form a string of length .
- The message of the plate is the lexicographically smallest string that step 2 can produce.
Letters compare by their ASCII values, so .
Given one plate, find its message.
Input
The input format is this.
N
c11c12...c1N
c21c22...c2N
:
:
cN1cN2...cNN
The first line contains an integer (). Each of the next lines contains a string of characters. Every character is an uppercase or lowercase English letter (A-Z, a-z).
Output
Print the message of the plate on one line.