Hamming

3.9

9 votes
Algorithms, Easy, String Manipulation
Problem

It is Raful's birthday, and his friends gave him N strings of length M. But he is not happy, because he wants only one beautiful string S.

His friends are upset now. You, as the best programmer in Lalalandia, decided to help them.

The string S is considered beautiful only when the sum of the Hamming distances between it and each of the N strings is minimal. If there exist several such strings, print out the lexicographically smallest one.

Input format

The first line of the input contains two integers N, M - number of strings and their lengths respectively.

Then N lines follow, each containing a string si (1iN), each consists of lowercase English letters.

Output format

The only line of the output should contain the string S.

Constraints:

1NM100000

Note

You can learn more about Hamming distance here:

https://en.wikipedia.org/wiki/Hamming_distance

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In this sample, "a" is lexicographically minimal string among all valid answers.

Editor Image

?