Problem:


Score : 1300 points

Problem Statement

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

Let i be the smallest index such that t_i = t_{i + 1}. If such an index does not exist, terminate the procedure.

If t_i is z, remove t_i and t_{i + 1} from t. Otherwise, let c be the next letter of t_i in the English alphabet, and replace t_i and t_{i + 1} together with c, reducing the length of t by 1.

Go back to step 1.

For example, when the robot is given the string axxxxza, it will be processed as follows: axxxxza → ayxxza → ayyza → azza → aa → b.

You are given a string s consisting of lowercase English letters.
Answer Q queries. The i-th query is as follows:

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

Constraints

1 ≤ |s| ≤ 5 × 10^5

s consists of lowercase English letters.

1 ≤ Q ≤ 10^5

1 ≤ l_i ≤ r_i ≤ |s|

Input

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

s
Q
l_1 r_1
l_2 r_2
:
l_Q r_Q

Output

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

Sample Input 1

axxxxza
2
1 7
2 6

Sample Output 1

No
Yes

Regarding the first query, the string will be processed as follows: axxxxza → ayxxza → ayyza → azza → aa → b.

Regarding the second query, the string will be processed as follows: xxxxz → yxxz → yyz → zz → .

Sample Input 2

aabcdefghijklmnopqrstuvwxyz
1
1 27

Sample Output 2

Yes

Sample Input 3

yzyyyzyzyyyz
8
1 6
7 12
1 12
6 11
1 1
1 3
4 9
3 8

Sample Output 3

Yes
Yes
Yes
Yes
No
No
No
No



Sample input:
axxxxza
2
1 7
2 6


Sample output:
No
Yes

Submission status: Runtime Error

Solution code:


def proc(s, s_old):
    arg = -1

    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            arg = i
            break

    if arg == -1 or len(s) < 2:
        """
        ti=ti+1 であるような最小の i を選ぶ。
        そのような i が存在しない場合、処理を終える。
        """
        return s

    if s[arg] == 'z':
        """
        ti が z である場合、
        ti, ti+1 を取り除く。
        """
        s = s[0:arg] + s[arg+2:]

    else:
        """
        ti が z でない場合、
        ti の次のアルファベットを c として、
        ti, ti+1 をまとめて1 文字の c へ置き換える。
        """
        c = S[S.index(s[arg])+1]
        s = s[0:arg] + c + s[arg+2:]

    if s_old == s:
        return s
    else:
        s_old = s

    # 1. へ戻る
    return proc(s, s_old)


S = list('abcdefghijklmnopqrstuvwxyz')
s = input()
Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    _s = s[l-1:r]
    if proc(_s) == '':
        print('Yes')
    else:
        print('No')

    del _s

Submission status: Runtime Error

Solution code:


def proc(s):
    arg = -1

    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            arg = i
            break

    if arg == -1 or len(s) < 2:
        """
        ti=ti+1 であるような最小の i を選ぶ。
        そのような i が存在しない場合、処理を終える。
        """
        return s

    if s[arg] == 'z':
        """
        ti が z である場合、
        ti, ti+1 を取り除く。
        """
        s = s[0:arg] + s[arg+2:]

    else:
        """
        ti が z でない場合、
        ti の次のアルファベットを c として、
        ti, ti+1 をまとめて1 文字の c へ置き換える。
        """
        c = S[S.index(s[arg])+1]
        s = s[0:arg] + c + s[arg+2:]

    # 1. へ戻る
    return proc(s)


S = list('abcdefghijklmnopqrstuvwxyz')
s = input()
Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    _s = s[l-1:r]
    if proc(_s) == '':
        print('Yes')
    else:
        print('No')

    del _s

Submission status: Runtime Error

Solution code:


def proc(s):
    arg = -1

    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            arg = i
            break

    if arg == -1 or len(s) < 2:
        return s

    if s[arg] == 'z':
        s = s[0:arg] + s[arg+2:]

    else:
        c = S[S.index(s[arg])+1]
        s = s[0:arg] + c + s[arg+2:]

    return proc(s)


S = list('abcdefghijklmnopqrstuvwxyz')
s = input()
Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    _s = s[l-1:r]
    if proc(_s) == '':
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:


def proc(s):
    arg = -1

    for i in range(len(s)-1):
        if s[i] == s[i+1]:
            arg = i
            break

    if arg == -1:
        return s

    if s[arg] == 'z':
        s = s[0:arg] + s[arg+2:]

    else:
        c = S[S.index(s[arg])+1]
        s = s[0:arg] + c + s[arg+2:]

    return proc(s)


S = list('abcdefghijklmnopqrstuvwxyz')

s = input()
Q = int(input())

for _ in range(Q):
    l, r = map(int, input().split())
    _s = s[l-1:r]
    if proc(_s) == '':
        print('Yes')
    else:
        print('No')