#K78947. Most Frequent Substring

    ID: 35199 Type: Default 1000ms 256MiB

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:

  1. The first line contains a positive integer \( k \), representing the length of the substring.
  2. 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.

## sample
3
abcabcabc
abc