QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#12293. Computational Biology

統計

Byteasar works in Byteland Centre for Computational Biology. He has just received a long sequence of $n$ genomes. His task is to find frequently occurring cyclic fragments of this sequence.

Byteasar's sequence can be represented as a word $s = s_{1}\ldots s_{n}$ of capital English letters. A cyclic fragment of s is a word t such that all its cyclic rotations^{1} are subwords of $s$.

Byteasar is interested in cyclic fragments of a given length $m$. For a given cyclic fragment $t$ of $s$, we define the number of cyclic occurrences of $t$ in $s$ as the total number of occurrences of distinct cyclic rotations of $t$ within $s$. Byteasar wants to find a cyclic fragment of length $m$ of the word s that has the largest number of cyclic occurrences. Please, write a program to help him.

^{1}A cyclic rotation of a word is constructed by moving its last letter to its beginning (possibly multiple times). For example, there are three different cyclic rotations of ABAABA, namely ABAABA, BAABAA and AABAAB. A word $u$ is a subword of $v$, if $u$ is a subsequence of $v$ consisting of several consecutive letters of $v$.

Input Format

The first line of the input contains two integers $n$ and $q$ ($2 ≤ n ≤ 500\,000$, $1 ≤ q ≤ 8$) which denote the length of the sequence of genomes and the number of queries to answer. The second line contains a word s composed of $n$ capital letters of the English alphabet. The following $q$ lines contain numbers $m_{i}$ ($2 ≤ m_{i} ≤ n$) defining the length of the cyclic fragments to consider.

Output Format

Your program should output $q$ lines. The $i$-th line should contain one integer denoting the maximal number of cyclic occurrences of any $m_{i}$-letter cyclic fragment of $s$.

Example

Input

16 2
AABAABACDABAABAA
6
3

Output

4
10

Notes

The cyclic fragment AABAAB occurs in the given word 4 times: once as AABAAB, twice as ABAABA and once as BAABAA. The cyclic fragment AAB occurs in this word 10 times.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.