시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB124436.364%

문제

Inês is new to programming. She is writing a simple application to handle text. So far, the app only supports adding text to a blank document. Rita, her restless little sister, is fascinated with all the different symbols on Inês’ screen and wants to play with it, not letting Inês work any longer. In order to be able to continue working, Inês decides to turn it into a game for Rita.

Inês will let Rita write whatever she likes in the app. Then, Inês will select portions of the document with width W and challenge Rita to guess how many distinct sequences of symbols there are in that portion of text. Rita is excited to play, but there is a problem: Inês doesn’t know yet how to write a program to find the right answer for her own questions. Can you help her out?

Given the description of the game being played by the two sisters: the text written in the document, and Inês’ questions, find the number of distinct (non-empty) substrings for each of the questions. A substring is a sequence of contiguous letters in the document.

입력

The first line of the input contains the text written by Rita. The text is composed only by letters [a − z]. The second line has two space separated integers: Q and W. Q is the number of questions and W the fixed width of Inês’ questions. Each of the following Q lines contains a single integer i, describing a question to know the number of distinct substrings in the range [i, i + W − 1].

출력

The output contains the answer to each question in the same order as in the input, one per line.

제한

  • 1 ≤ |D| ≤ 100 000 Number of letters in a document.
  • 1 ≤ Q ≤ 100 000 Number of questions.
  • 1 ≤ W ≤ |D| Width of Inês’ questions.
  • 1 ≤ i ≤ |D| − W + 1 The question range is one-indexed and inside the document bounds.

예제 입력 1

acat
2 3
1
2

예제 출력 1

5
6

The first question concerns the range [1, 3] → aca, which has 5 distinct substrings {a, c, ac, ca, aca}. The second question corresponds to cat, which has 6 distinct substrings: {a, c, t, ca, at, cat}.

예제 입력 2

portoisamazing
2 7
6
3

예제 출력 2

26
28