Олимпиадный тренинг

Задача 39192. File analysis


Задача

Темы: ЕГЭ
The text file consists of no more than 106 characters and contains only uppercase Latin letters (ABC…Z). The text is divided into lines of various lengths. It is necessary to find a string that contains the longest subsequence between two letters  (the first and last letters of A are also included in the subsequence) and other letters A is not in this subsequence. If there are several such lines, you need to take the one that was encountered earlier in the file. Determine which letter occurs most often in this subsequence. If there are several such letters, you need to take the one that is earlier in the alphabet. Write down the found letter in the answer, as well as how many times it occurs in the entire file.

Example
Source file:
AABABC
ZZAACZCCA
QRAAUTUTA

In this example, in the first line the searched subsequence (ABA) has length 3, in the second line (ACZСA) and in the third line (AUTUTA)  ; - length 6. We take the second line, because it is in the file before. In this subsequence, the letter C occurs most often, it occurs 4 times in the entire file. In the answer for this example, write C4.

Assignment file