#K13171. Find the Lexicographically Smallest Permutation

    ID: 23854 Type: Default 1000ms 256MiB

Find the Lexicographically Smallest Permutation

Find the Lexicographically Smallest Permutation

You are given an integer N and a grid of N strings. Each string in the grid is a permutation of a secret word. Your task is to determine the lexicographically smallest permutation of the secret word that appears in every row of the grid.

Since every row is a permutation of the secret word, it is guaranteed that sorting the characters of any row will result in the lexicographically smallest possible ordering of the characters. Use this fact to determine the secret word.

Note: All input strings consist of lowercase English letters and have length N.

Example:

Input:
4
bcad
adcb
dbac
cabd

Output: abcd

</p>

inputFormat

The input is read from standard input (stdin) and has the following format:

N
s1
s2
...
sN

Where:

  • N is an integer representing the number of rows in the grid as well as the length of each string.
  • s1, s2, ..., sN are the rows of the grid, each being a permutation of the secret word.

outputFormat

Output a single line to standard output (stdout) containing the lexicographically smallest permutation that is derived by sorting the characters of the first row. This permutation will be the secret word.

## sample
4
bcad
adcb
dbac
cabd
abcd