eolymp
bolt
Try our new interface for solving problems
Problems

KINA is not abbreviation

KINA is not abbreviation

When introducing new terms consisting of several words, it is useful to use abbreviations. An \textit{abbreviation} is a word that consists of the first letters of several consecutive words. An abbreviation is called \textit{unambiguous} if the following two conditions are satisfied: \begin{itemize} \item It corresponds to exactly one sequence of words in a given text (although this sequence can appear in the text more than once); \item It does not appear in the text by itself. \end{itemize} For example, in the text "\textbf{A recursive acronym KINA means "KINA is not abbreviation"}", strings "\textbf{ARA}" and "\textbf{K}" are unambiguous abbreviations, strings "\textbf{A}" and "\textbf{KINA}" are ambiguous abbreviations, and strings "\textbf{RAA}" and "\textbf{KNA}" are not abbreviations. To introduce an abbreviation in a text, it is placed in parentheses right after the sequence of words it corresponds to. Future occurrences of this sequence of words can be replaced by the abbreviation. In the example text above, introduction of the abbreviation "\textbf{K}" produces the following text: "\textbf{A recursive acronym KINA (K) means "K is not abbreviation"}". If two occurrences of a sequence of words overlap, only one of them can be replaced by the abbreviation. Words in a sequence are separated by one or more non-alphabetic characters. Comparison of words is case-insensitive. For example, "\textbf{i18n}" is an occurrence of the word sequence "\textbf{I n}". The \textit{effectiveness} of an abbreviation is the decrease in the number of letters after introduction of this abbreviation. Only letters are taken into account; spaces, parentheses and all other non-alphabetical characters do not count. Given a text, find an unambiguous abbreviation with the maximum effectiveness. \InputFile The input contains a text with at most \textbf{4 000} characters. The text contains only characters with ASCII codes \textbf{32} (space) to \textbf{126} ("~"), \textbf{13} (carriage return), and \textbf{10} (line feed). \OutputFile If there is no unambiguous abbreviation with positive effectiveness, then the output should contain the single number \textbf{0}. Otherwise, the first line of the output should contain the effectiveness of the optimal abbreviation. The second line should contain the unambiguous abbreviation itself. If there are multiple unambiguous abbreviations with the maximum effectiveness, output any one of them. \textbf{Note:} In the first example, the optimal abbreviations are "\textbf{NA}" and "\textbf{INA}". In the third example, the optimal abbreviations are "\textbf{JB}" and "\textbf{BJ}".
Time limit 1 second
Memory limit 64 MiB
Input example #1
This problem name is "KINA is not abbreviation".
Once again: KINA is not abbreviation.
Output example #1
11
INA