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.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.