Sam is starting a new company, and has just chosen its name.
The name is a string of length . The name is so long that
customers won’t remember the full name. Rather, each customer
is going to remember only a substring of the full name, and different
customers may remember different substrings.
Sam is curious how memorable the substring will be to a customer. Sam
believes that the more palindromes contains, the more memorable it
is. Recall that a string is a palindrome if reads the same forwards and
backwards (for example, the strings radar and level are
palindromes, while the string ever is
not). After all, customers are sensitive to symmetries in the
substring that he or
she remembers, and palindromes are full of symmetries. As such,
Sam wants to find out the number of substrings of such that is a palindrome.
The challenge is that Sam’s company will have tons of
customers. It is difficult for Sam to know how memorable his
company name is to all these customers. Can you help Sam?
Input
The first line of input contains a string consisting of
lowercase letters
(). The second line contains an integer (), denoting the number of
customers. Then lines
follow, each containing a pair of integers and (), indicating that a customer
remembers precisely the substring
between the th and
th characters
inclusive.
Output
For each customer, output a line containing an integer that
indicates how memorable the company name is to the customer.
More specifically, if this customer remembers the substring
, output the number of pairs of indices such that and
is a palindrome.
Sample Input 1 |
Sample Output 1 |
aabacab
5
1 7
1 4
3 7
2 5
5 7
|
11
6
7
5
3
|