Challenge for Akshay

3.8

13 votes
Easy-Medium
Problem

Karan and Akshay love challenging each other with awesome algorithmic questions. Today, Karan decided to give Akshay a relatively easy question. Karan has string s of length N consisting entirely of lowercase latin characters and he loves double palindromes (defined below). So he asks Akshay Q questions about the string of the type -

l r - consider the substring s[l...r] and report if the characters in this substring can be rearranged to form a double palindrome.

A palindrome is a string that read same forwards and backwards.

Let's define a double palindrome as a string that is concatenation of two palindrome, "AB" is a double palindrome if "A" and "B" are palindrome.

Eg. "abbacddc" is a double palindrome because "abba" and "cddc" are both palindromes.

But, Akshay is a very lazy guy. He asks you to solve the task at hand!(Height of laziness!)

If it is possible then print "YES", without quotes else print "NO".

Input format

The first line of input contains one integer N denoting the size of the string.

The second line of input contains the string s itself. It is guaranteed that the string consists only of lowercase latin characters.

The third line contains one integer Q denoting the total number of queries.

Next Q lines each contain two integers l r denoting the queries.

Output format

For each query output a single line with the string "YES" if the characters in the substring represented by the corresponding query can be rearranged to form double palindrome else output the string "NO".

Constraints

  • 1<=N<=105
  • 1<=Q<=105
  • 1<=l<=r<=N

Sub-tasks

For 25% points : 1<=N,Q<=103

For 75% points : original constraints

Note : Output is case sensitive

Note : Palindrome can't be empty

Sample Input
8
abcdabcd
2
1 8
3 5
Sample Output
YES
NO
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For query 1, the substring can be rearranged to make the string "abbacddc" which is a double palindrome because "abba" and "cddc" are both palindromes.

Contributers:
Editor Image

?