#MUJINPC2017C. Robot and String

Robot and String

Score : 13001300 points

Problem Statement

You are developing a robot that processes strings. When the robot is given a string tt consisting of lowercase English letters, it processes the string by following the procedure below:

  1. Let ii be the smallest index such that ti=ti+1t_i = t_{i + 1}. If such an index does not exist, terminate the procedure.
  2. If tit_i is z, remove tit_i and ti+1t_{i + 1} from tt. Otherwise, let cc be the next letter of tit_i in the English alphabet, and replace tit_i and ti+1t_{i + 1} together with cc, reducing the length of tt by 11.
  3. Go back to step 1.

For example, when the robot is given the string axxxxza, it will be processed as follows: axxxxzaayxxzaayyzaazzaaab.

You are given a string ss consisting of lowercase English letters. Answer QQ queries. The ii-th query is as follows:

  • Assume that the robot is given a substring of ss that runs from the lil_i-th character and up to the rir_i-th character (inclusive). Will the string be empty after processing?

Constraints

  • 1s5×1051 \leq |s| \leq 5 \times 10^5
  • ss consists of lowercase English letters.
  • 1Q1051 \leq Q \leq 10^5
  • 1liris1 \leq l_i \leq r_i \leq |s|

Input

The input is given from Standard Input in the following format:

ss

QQ

l1l_1 r1r_1

l2l_2 r2r_2

::

lQl_Q rQr_Q

Output

Print QQ lines. The ii-th line should contain the answer to the ii-th query: Yes or No.

axxxxza
2
1 7
2 6
No
Yes
  • Regarding the first query, the string will be processed as follows: axxxxzaayxxzaayyzaazzaaab.
  • Regarding the second query, the string will be processed as follows: xxxxzyxxzyyzzz → ``.
aabcdefghijklmnopqrstuvwxyz
1
1 27
Yes
yzyyyzyzyyyz
8
1 6
7 12
1 12
6 11
1 1
1 3
4 9
3 8
Yes
Yes
Yes
Yes
No
No
No
No