Mikhail's Problem

아직 제출이 없습니다시간 제한3초메모리 제한512 MB

문제

You are given a string ss and several queries. For the ii-th query, calculate the number of different palindromic substrings of s\[l_i..r_i]s\[l\_i .. r\_i]. A substring is called palindromic if it reads the same from right to left as from left to right. Two substrings are considered different if they differ as strings.

입력

The first line contains a non-empty string ss consisting of lowercase English letters. The length of the string does not exceed 10510^5 characters.

The second line contains an integer qq, the number of queries (1q1051 \leq q \leq 10^5). Next qq lines contain queries. Each of these lines contains integers l_il\_i and r_ir\_i separated by a space (1l_ir_is1 \leq l\_i \leq r\_i \leq |s|).

출력

Output qq lines. The ii-th line must contain one integer: the answer to the ii-th query.