#K70147. First Appearing Letter

    ID: 33244 Type: Default 1000ms 256MiB

First Appearing Letter

First Appearing Letter

You are given a list of lowercase alphabetic strings. Your task is to determine the letter that first appears (i.e. the letter with the smallest index position in any of the strings) and count its total occurrences across the entire list. In case of a tie (i.e. two or more letters have the same minimal index position in their first occurrence), choose the lexicographically smallest letter.

The input begins with an integer n indicating the number of strings, followed by n strings (each on a new line). The output should print the selected letter followed by its total count, separated by a space.

Note: The index considered is the position within each individual string (starting from 0), and if a letter appears for the first time at index 0 in any string, it is eligible. The final answer is determined by selecting the letter with the smallest such index; if multiple letters share this minimal index, the one with the lower alphabetical value is chosen.

inputFormat

The input consists of several lines. The first line contains a single integer n (1 ≤ n ≤ 105), representing the number of strings. Each of the following n lines contains a non-empty string composed of lowercase English letters.

Example:

4
hello
world
hi
wow

outputFormat

Output a single line containing the first appearing letter (as defined above) and its total frequency, separated by a space.

Example:

h 2
## sample
4
hello
world
hi
wow
h 2