#K5261. Lexicographically Smallest Substring

    ID: 29348 Type: Default 1000ms 256MiB

Lexicographically Smallest Substring

Lexicographically Smallest Substring

Given a string \( s \) of length \( n \) and \( q \) queries, each query specifying a substring length \( L_i \), find the lexicographically smallest substring of \( s \) of length \( L_i \). Here, the lexicographical order is the standard dictionary order. For each query, output the answer on a new line.

Example:

Input:
7 3
abcdeed
2 3 4

Output: ab abc abcd

</p>

inputFormat

The first line contains two integers \( n \) and \( q \) separated by a space, where \( n \) is the length of the string \( s \) and \( q \) is the number of queries.

The second line contains the string \( s \) consisting of lowercase letters.

The third line contains \( q \) space-separated integers. Each integer \( L_i \) denotes the length of the substring to be found.

outputFormat

For each query, print the lexicographically smallest substring of length \( L_i \) from the string \( s \) on a new line.

## sample
7 3
abcdeed
2 3 4
ab

abc abcd

</p>