Prefix Relay Log
A communication log is represented by a string of length , indexed from through . Relays may begin whenever the start of the log appears again.
Choose a nonempty prefix length , where . A position , where , is an occurrence start for this prefix if
Write all occurrence starts in increasing order as
The prefix itself always occurs at the beginning, so . Append a terminal marker . This marker is not another occurrence; it represents the moment immediately after the log ends.
The relay gap of prefix length is
Each query gives a tolerance . A prefix length qualifies for that query when . Determine the largest qualifying prefix length. If no nonempty prefix qualifies, the answer is .
Input
The first line contains two integers and (), the length of the log and the number of queries.
Output
For each of the queries, print one integer: the largest prefix length satisfying for that query. If no nonempty prefix satisfies the condition, print .
Samples
Sample 1
Input
5 4 ababa 1 2 3 5
Output
0 1 3 5
For , no nonempty prefix qualifies. For , , and , the longest qualifying prefixes have lengths , , and , respectively.