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

Задача 39618. 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. We call a subsequence original if it is bounded on the left by the substring  AB, and on the right by the substring BA  (these substrings are also included in the subsequence) and there are no other letters in this subsequence A and B. The original subsequence cannot start on one line and end on another.
Determine how much  total  original subsequences in the entire file, as well as the length of the maximum of them.

In your answer, write together two integers, first the number of original subsequences, then the length of the maximum of them.

Example
Source file:
AAABCAABCBAA
ZZABZZZBABCBA
QRABUTUUBA

There are 4 original subsequences in this example (ABUTUTBA, ABZZZBA, ABCBA, ABUTUTBA)
The longest subsequence (ABUTUTBA) has a length of 8.
Answer: 48


Assignment file