Computational Biology

No attempts yetTime limit5sMemory limit128 MB

Problem

Byteasar works at the Byteland Centre for Computational Biology. He has just received a long sequence of nn genomes and wants to find the cyclic fragments that occur most often in it.

The sequence is a word s=s1s2sns = s_1 s_2 \ldots s_n over capital English letters. A cyclic rotation of a word is obtained by moving its last letter to the front, possibly several times in a row. For example, ABAABA has three distinct cyclic rotations: ABAABA, BAABAA, and AABAAB. A word uu is a subword of a word vv if uu occurs in vv as a block of consecutive letters.

A word tt is a cyclic fragment of ss if every cyclic rotation of tt is a subword of ss. For such a tt, its number of cyclic occurrences in ss is the total number of occurrences in ss of the distinct cyclic rotations of tt.

For each query length mm, report the largest number of cyclic occurrences achievable by a cyclic fragment of ss of length mm. If ss has no cyclic fragment of length mm, the answer is 0.

Input

The first line contains two integers nn and qq (2n500,0002 \le n \le 500{,}000, 1q81 \le q \le 8): the length of the genome sequence and the number of queries. The second line contains the word ss, made of nn capital letters of the English alphabet. Each of the next qq lines contains one integer mim_i (2min2 \le m_i \le n), the length of the cyclic fragments to consider in that query.

Output

Output qq lines. The ii-th line must contain a single integer: the maximum number of cyclic occurrences over all cyclic fragments of ss of length mim_i (or 0 if none exists).

Note

Take s=s = AABAABACDABAABAA. For length 6, the cyclic fragment AABAAB has three distinct cyclic rotations, and together they occur 4 times in ss: once as AABAAB, twice as ABAABA, and once as BAABAA. No length-6 cyclic fragment does better, so the answer is 4. For length 3, the cyclic fragment AAB occurs 10 times in total across its rotations AAB, ABA, and BAA, which is the maximum.