#C2716. Most Frequent Flower

    ID: 46063 Type: Default 1000ms 256MiB

Most Frequent Flower

Most Frequent Flower

You are given a garden represented as a grid of characters. Each character represents a type of flower. Your task is to determine which flower appears most frequently in the entire garden. In case there is a tie (i.e. two or more flowers appear with the same maximum frequency), choose the flower that is lexicographically smallest.

Formally, let the garden be represented by an n×mn \times m grid where each cell contains a lowercase letter. Find a character cc such that its total count f(c)f(c) is maximized. In case of a tie, output the smallest character in lexicographic order.

inputFormat

The first line contains two positive integers nn and mm (1n,m1051 \le n, m \le 10^5 possibly, depending on constraints) separated by a space, where nn is the number of rows and mm is the number of columns in the garden. This is followed by nn lines, each containing a string of exactly mm lowercase letters; each string represents one row of the garden.

outputFormat

Output a single character --- the type of flower that occurs most frequently in the garden. If there is a tie, output the lexicographically smallest flower among those with the maximum frequency.## sample

4 5
abbca
abcdef
ghiaj
kllmn
a