#K78947. Most Frequent Substring
Most Frequent Substring
Most Frequent Substring
Given an integer \( k \) and a string \( S \), your task is to determine the most frequent substring of length \( k \) in \( S \). If there are multiple substrings that occur with the same maximum frequency, output the lexicographically smallest one.
Note: A substring is a contiguous sequence of characters within a string.
Example: For \( k = 3 \) and \( S = \texttt{abcabcabc} \), the substring \( \texttt{abc} \) appears most frequently.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a positive integer \( k \), representing the length of the substring.
- The second line contains the string \( S \).
outputFormat
Output the most frequent substring of length \( k \) to standard output (stdout). If more than one substring is tied for maximum frequency, output the lexicographically smallest one.
## sample3
abcabcabc
abc