QOJ.ac

QOJ

Time Limit: 3.5 s Memory Limit: 512 MB Total points: 100

#7364. Palindrome

Statistics

A palindrome is defined as a string $t = t_1 t_2 \dots t_n$ that satisfies the following property: $t_i = t_{n-i+1}$ for $1 \le i \le n$

Given a string $s$ and $q$ queries. For each query, you are given two integers $l_i, r_i$. Can you answer the length of the longest palindromic substring of $s[l_i, r_i]$?

Input

The first line contains a string $s$. The second line contains an integer $q$, representing the number of queries. The next $q$ lines each contain two integers $l_i, r_i$, representing a query for the length of the longest palindromic substring of $s[l_i, r_i]$.

Output

For each query, output an integer representing the length of the longest palindromic substring of $s[l_i, r_i]$.

Examples

Input 1

aaacbdccccadaadabbdbadcbcbbadcadb
6
5 22
1 18
15 33
1 33
8 12
15 27

Output 1

6
6
3
6
3
3

Constraints

For 10% of the data, $n \le 300, q \le 300$. For 30% of the data, $n \le 5000, q \le 5000$. For 70% of the data, $n \le 5 \times 10^4, q \le 5 \times 10^4$. For 100% of the data, $n \le 5 \times 10^5, q \le 5 \times 10^5$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.