401363: GYM100418 C Substrings

Memory Limit:64 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Substringstime limit per test3 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

You are given a string S consisting of capital Latin letters. Consider the queries consisting of pairs of integer numbers Li and Ri. For each of them you should find the number of substrings which are less than substring S[Li...Ri].

Input

The first line contains the string S(1 ≤ |S| ≤ 105). The second line contains the number N (1 ≤ N ≤ 105), denoting the number of queries. The next N lines contain pairs of numbers Li, Ri (1 ≤ Li ≤ Ri ≤ |S|).

Output

For each query you should output the number of substrings which satisfy specified conditions.

ExamplesInput
BSUIROPENPROGRAMMINGCHAMPIONSHIP
1
1 15
Output
42

加入题单

算法标签: