AlgoUniversity
  • Go Back
Discussion
Palindrome Query :

Author

Akash

Difficulty Level : Hard

Submissions : 283

Asked In : Trilogy-Innovations

Marks :10

: 8 | : 1

Given a string $$$S$$$ (consisting of only lower characters) and $$$Q$$$ queries.

In each query, you will given an integer $$$i$$$ and your task is to find the length of the longest $$$(length>1)$$$ odd palindromic substring whose middle index is $$$i$$$ .

$$$\bf Note:$$$

1. Assume $$$1$$$-based indexing

2. Longest odd palindrome: A palindrome substring whose length is odd.

Input

The first line contains the string $$$S$$$ $$$(1 \le |S| \le 10^5)$$$.

The second line contains an integer $$$Q$$$ $$$(1 \le Q \le 10^5)$$$ denoting the number of queries.

The third line contains the $$$Q$$$ queries, $$$Q_1,Q_2...Q_n$$$ where $$$(1 \le Q_i \le |S|)$$$.

Output

Return an array of integers where $$$i^{th}$$$ integer denotes the answer of $$$i^{th}$$$ query.

Examples

Input
aaaaa
2
2 3
Output
3 5 
Input
abcd
1
2
Output
0 

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.