#K54897. Most Common Repeated Subsequence

    ID: 29855 Type: Default 1000ms 256MiB

Most Common Repeated Subsequence

Most Common Repeated Subsequence

Given a string ( S ), find the most common repeated subsequence of exactly three consecutive characters (i.e., a substring) that does not overlap. If multiple subsequences have the same highest frequency, return the lexicographically smallest one. If no such subsequence exists, output "NONE".

For example, for ( S = \texttt{abacabadabacaba} ), the subsequence ( aba ) appears most frequently.

Note: In this problem, a subsequence is considered as a contiguous block of exactly three characters.

inputFormat

Input consists of a single line containing the string ( S ). The string ( S ) contains only lowercase English letters.

outputFormat

Output the most common repeated three-character subsequence. If there is no such subsequence, output ( NONE ).## sample

abacabadabacaba
aba