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: Wrong Answer

Solution code:
# Hello World program in Python
 
def smallestRepeat(items):
    idx = -1
    
    for i in range(0, len(items) - 1):
        
        if(items[i] == items[i+1]):
            idx = i
            break
    
    return idx

def processString(string):
    c = -1
    idx = -1 
    run = 0
    charsLeft = False
    
    s = list(string)

    while len(s) > 0:
        run += 1
        
        idx = smallestRepeat(s)   
    
        if(idx == -1):
            if(len(s) >= 1):
                charsLeft = True
                break
            else:
                charsLeft = False
                break
                
        else:
            
            c = s[idx]
        
            if c == "z":
                s.pop(idx)
                s.pop(idx)
            else:
                s[idx] = chr(ord(c)+1)
                s.pop(idx+1)
           
    return (not charsLeft)

import sys   
    
if __name__ == "__main__":
    string = ""
    numIndex = 0
    indexes = []

    string = sys.stdin.readline()
    numIndex = int(sys.stdin.readline())
     
    for line in sys.stdin.readlines():
        line = line.split()
        start = int(line[0])
        end =   int(line[1])
        indexes.append((start, end))


    for start,end in indexes:
        sub = string[start-1 : end]
        print processString(sub)

Submission status: Wrong Answer

Solution code:
alphabet = [letter for letter in "abcdefghijklmnopqrstuvwxyz"]

def Check(s):
    s = [x for x in s]
    res = []
    terminated = len(s) == 0
    while not terminated:
        if len(res) == 0:
            res.append(s.pop(0))

        if len(s) == 0:
            terminated = True
            break
        letter = s.pop(0)
        if letter == res[-1]:
            res.pop()
            index = alphabet.index(letter) + 1
            if not (index == 26):
                res.append(alphabet[index])

            newlist = res + s
            s = newlist
            res = []
        else:
            res.append(letter)
        print "res", res
        print "s", s
        print
        if len(s) == 0:
            terminated = True
    if len(res) == 0:
        print "Yes"
    else:
        print "No"
    return

sentence = raw_input()
Q = int(raw_input())
for i in xrange(Q):
    l, r = map(int, raw_input().split())
    word = sentence[l - 1:r]
    Check(word)

Submission status: Wrong Answer

Solution code:
def solve_loop(s):
    count = 0
    while len(s) > 1 and count < 10000000:
        s = solve(s)
        count += 1
    return s

def solve(s):
    for i in range(0, len(s)-1):
        if s[i] == s[i+1]:
            if s[i] == 'z':
                s = s.replace(s[i:i+2], '')
            else:
                next_chr = chr(ord(s[i])+1)
                s = s.replace(s[i:i+2], next_chr)
            return s
    return s



s = input()
q = int(input())

start = []
end = []
for i in range(0, q):
    _input = input()
    start.append(int(_input.split(' ')[0]))
    end.append(int(_input.split(' ')[1]))

for i in range(0, q):
    test_st = s[start[i]-1:end[i]]
    opt_str = solve_loop(test_st)
    if len(opt_str) == 0:
        print('YES')
    else:
        print('NO')

Submission status: Wrong Answer

Solution code:
alphabet = [letter for letter in "abcdefghijklmnopqrstuvwxyz"]


def Check(s):
    s = [x for x in s]
    res = []
    terminated = len(s) == 0
    while not terminated:
        if len(res) == 0:
            res.append(s.pop(0))

        if len(s) == 0:
            terminated = True
            break
        letter = s.pop(0)
        if letter == res[-1]:
            res.pop()
            index = alphabet.index(letter) + 1
            if not (index == 26):
                res.append(alphabet[index])

            newlist = res + s
            s = newlist
            res = []
        else:
            res.append(letter)
        if len(s) == 0:
            terminated = True
    if len(res) == 0:
        print "Yes"
    else:
        print "No"
    return

sentence = raw_input()
Q = int(raw_input())
for i in xrange(Q):
    l, r = map(int, raw_input().split())
    word = sentence[l - 1:r]
    print word
    Check(word)

Submission status: Wrong Answer

Solution code:
def solve_loop(s):
    count = 0
    while len(s) > 1 and count < 100:
        s = solve(s)
        count += 1
    return s

def solve(s):
    for i in range(0, len(s)-1):
        if s[i] == s[i+1]:
            if s[i] == 'z':
                s = s.replace(s[i:i+2], '')
            else:
                next_chr = chr(ord(s[i])+1)
                s = s.replace(s[i:i+2], next_chr)
            return s
    return s



s = input()
q = int(input())

start = []
end = []
for i in range(0, q):
    _input = input()
    start.append(int(_input.split(' ')[0]))
    end.append(int(_input.split(' ')[1]))

for i in range(0, q):
    test_st = s[start[i]-1:end[i]]
    opt_str = solve_loop(test_st)
    if len(opt_str) == 0:
        print('YES')
    else:
        print('NO')

Submission status: Time Limit Exceeded

Solution code:
# Hello World program in Python
 
def smallestRepeat(items):
    idx = -1
    
    for i in range(0, len(items) - 1):
        
        if(items[i] == items[i+1]):
            idx = i
            break
    
    return idx
 
def processString(string):
    c = -1
    idx = -1 
    run = 0
    charsLeft = False
    
    s = list(string)
 
    while len(s) > 0:
        run += 1
        
        idx = smallestRepeat(s)   
    
        if(idx == -1):
            if(len(s) >= 1):
                charsLeft = True
                break
            else:
                charsLeft = False
                break
                
        else:
            
            c = s[idx]
        
            if c == "z":
                s.pop(idx)
                s.pop(idx)
            else:
                s[idx] = chr(ord(c)+1)
                s.pop(idx+1)
           
    return (not charsLeft)
 
import sys   
    
if __name__ == "__main__":
 
    string = sys.stdin.readline()
    numIndex = int(sys.stdin.readline())
     
    for line in sys.stdin.readlines():
        line = line.split()
		
        start = int(line[0])
        end   = int(line[1])
		
	sub = string[start-1 : end]
		
	if processString(sub):
            print "Yes"
        else:
            print "No"

Submission status: Time Limit Exceeded

Solution code:
s=input()
Q=int(input())
for q in range(Q):
	temp=input().split()
	l=int(temp[0])-1
	r=int(temp[1])-1
	s_q=s[l:r+1]
	
	s_list=[]
	for s_i in s_q:
	    s_list.append(ord(s_i)-97)
	flag=False
	while True:
		length=len(s_list)
		for i in range(length-1):
			if s_list[i]==s_list[i+1]:
				del s_list[i+1]
				s_list[i]+=1
				if s_list[i]==26:
				    del s_list[i]
				flag=True
				#print(s_list)
				break
		if flag==True:
			flag=False
			continue
		break
	if s_list==[]:
	    print("Yes")
	else:
	    print("No")

Submission status: Time Limit Exceeded

Solution code:
#MOD = 10**9 + 7
from math import log2

s = input().strip()
#print(s,len(s))
L = len(s)
Q = int(input().strip())
ORD = ord('a')

nextC = [27*[L+1] for _ in range(L+2)]
nextC[L-1][ord(s[-1])-ORD] = L
for i in range(L-2,-1,-1):
  char = ord(s[i]) - ORD
  nextC[i][char] = i+1
  #if i == 0: print('###',nextC[i])
  for c in range(char+1,27):
    nextC[i][c] = min(nextC[nextC[i][c-1]][c-1], nextC[nextC[i][26]][c])
  #if i == 0: print('###',nextC[i])
  if char != 0:
    nextC[i][0] = nextC[nextC[i][26]][0]
    for c in range(1,char):
      nextC[i][c] = min(nextC[nextC[i][c-1]][c-1], nextC[nextC[i][26]][c])
      
#for i in range(L+2):
#  print(nextC[i])
numPowers = int(log2(L))
nextPow = [(L+2)*[L+1] for _ in range(numPowers+1)]
for i in range(L+2):
  nextPow[0][i] = nextC[i][26]
for power in range(1,numPowers+1):
  for i in range(L):
    nextPow[power][i] = nextPow[power-1][nextPow[power-1][i]]
#for i in range(L+2): print(nextC[i])
#print(nextPow, L)

for q in range(Q):
  l,r = [int(_) for _ in input().split()]
  l -= 1
  #print(l,r, s[l:r])
  p = 0
  n = nextPow[0][l]
  while n < r:
    p += 1
    n = nextPow[p][l]
  if n == r:
    print("Yes")
  elif p == 0:
    print("No")
  else:
    n = nextPow[p-1][l]
    while n < r:
      n = nextC[n][26]
    if n == r:
      print("Yes")
    else:
      print("No")

Submission status: Time Limit Exceeded

Solution code:
#MOD = 10**9 + 7
s = input().strip()
#print(s,len(s))
L = len(s)
Q = int(input().strip())
ORD = ord('a')

nextC = [27*[L+1] for _ in range(L+2)]
nextC[L-1][ord(s[-1])-ORD] = L
for i in range(L-2,-1,-1):
  char = ord(s[i]) - ORD
  nextC[i][char] = i+1
  #if i == 0: print('###',nextC[i])
  for c in range(char+1,27):
    nextC[i][c] = min(nextC[nextC[i][c-1]][c-1], nextC[nextC[i][26]][c])
  #if i == 0: print('###',nextC[i])
  if char != 0:
    nextC[i][0] = nextC[nextC[i][26]][0]
    for c in range(1,char):
      nextC[i][c] = min(nextC[nextC[i][c-1]][c-1], nextC[nextC[i][26]][c])
      
#for i in range(L+2):
#  print(nextC[i])

for q in range(Q):
  l,r = [int(_) for _ in input().split()]
  l -= 1
  #print(l,r, s[l:r])
  n = nextC[l][26]
  while n < r:
    n = nextC[n][26]
  if n == r:
    print("Yes")
  else:
    print("No")

Submission status: Time Limit Exceeded

Solution code:
def stringProcessor(sequence):                                                  
    i = 0                                                                       
    while i < len(sequence) - 1:                                                
        if sequence[i] == sequence[i + 1]:                                      
            if sequence[i] == ord('z'):                                         
                del sequence[i]                                                 
                del sequence[i]                                                 
            else:                                                               
                del sequence[i]                                                 
                sequence[i] += 1                                                
                                                                                
            if i > 0:                                                           
                i -= 1                                                          
            continue                                                            
                                                                                
        i += 1                                                                  
                                                                                
    return sequence                                                             
                                                                                
sequence = map(ord, list(raw_input()))                                          
                                                                                
Q = int(raw_input())                                                            
                                                                                
queries = []                                                                    
for i in range(0, Q):                                                           
    queries.append(map(int, raw_input().split()))                               
                                                                                
for query in queries:                                                           
    subSeq = sequence[query[0]-1:query[1]]                                      
                                                                                
    if len(stringProcessor(subSeq)) == 0:                                       
        print 'Yes'                                                             
    else:                                                                       
        print 'No'

Submission status: Time Limit Exceeded

Solution code:
def stringProcessor(sequence):                                                  
    for i in range(0, len(sequence) - 1):                                       
        if sequence[i] == sequence[i + 1]:                                      
            if sequence[i] == ord('z'):                                         
                del sequence[i]                                                 
                del sequence[i]                                                 
            else:                                                               
                del sequence[i]                                                 
                sequence[i] += 1                                                
            break                                                               
    return sequence                                                             
                                                                                
sequence = map(ord, list(raw_input()))                                          
                                                                                
Q = int(raw_input())                                                            
                                                                                
queries = []                                                                    
for i in range(0, Q):                                                           
    queries.append(map(int, raw_input().split()))                               
                                                                                
for query in queries:                                                           
    subSeq = sequence[query[0]-1:query[1]]                                      
                                                                                
    prevLen = len(subSeq)                                                       
    subSeq = stringProcessor(subSeq)                                            
    while prevLen != len(subSeq):                                               
        prevLen = len(subSeq)                                                   
        subSeq = stringProcessor(subSeq)                                        
                                                                                
    if prevLen == 0:                                                            
        print 'Yes'                                                             
    else:                                                                       
        print 'No'

Submission status: Time Limit Exceeded

Solution code:
import sys

def func(s):
    i = 0
    found = False
    for i, c in enumerate(s):
        if i < len(s) - 1 and c == s[i+1]:
            found = True
            break
    
    if found:
        a = s[i]
        s = s[:i] + s[i+2:]
        if a != "z":
            s = s[:i] + chr(ord(a) + 1) + s[i:]
        return s

    return "-"

if __name__ == "__main__":
    input = sys.stdin.readlines()
    string = input[0]
    n = int(input[1])

    for i in range(2, 2 + n):
        lr = input[i]
        l, r = lr.split(" ")
        
        s = string[int(l)-1:int(r)]
        result = func(s)
        while result != "-":
            if result == "":
                print("Yes")
                break
            result = func(result)
        else:
            print("No")

Submission status: Time Limit Exceeded

Solution code:
enter = raw_input()
Q = int(raw_input())
que = []
for i in range(Q):
    que.append(map(int, raw_input().split()))

listletter = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
 
for i in range(Q):
    start = que[i][0]-1
    end = que[i][1]
    substring = enter[start:end]
    end = True
    while (len(substring)>0):
        has = False
        if len(substring)==1:
            if substring[0] != 'z':
                print 'No'
                end = False
                break
        for j in range(len(substring)-1):
            if substring[j] == substring[j+1]:
                has = True
                if substring[j] =='z':
                    newsubstring = substring[:j]+substring[(j+2):]
                    substring = newsubstring
                    break
                else:
                    newsubstring = substring[:j] + listletter[listletter.index(substring[j])+1] +substring[(j+2):]
                    substring = newsubstring
                    break
        if (not has):
            print 'No'
            end = False
            break
    if end:
        print 'Yes'

Submission status: Time Limit Exceeded

Solution code:
enter = raw_input()
Q = int(raw_input())
que = []
for i in range(Q):
    que.append(map(int, raw_input().split()))

listletter = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
 
for i in range(Q):
    start = que[i][0]-1
    end = que[i][1]
    substring = enter[start:end]
    end = True
    while (len(substring)>0):
        has = False
        if len(substring)==2:
            if (substring =='yy') or (substring =='zz'):
                break
            else:
                print 'No'
                end = False
                break
        if len(substring)==1:
            if substring[0] != 'z':
                print 'No'
                end = False
                break
        for j in range(len(substring)-1):
            if substring[j] == substring[j+1]:
                has = True
                if substring[j] =='z':
                    newsubstring = substring[:j]+substring[(j+2):]
                    substring = newsubstring
                    break
                else:
                    newsubstring = substring[:j] + listletter[listletter.index(substring[j])+1] +substring[(j+2):]
                    substring = newsubstring
                    break
        if (not has):
            print 'No'
            end = False
            break
    if end:
        print 'Yes'

Submission status: Time Limit Exceeded

Solution code:
class stack(list):
    def push(self, item):
        self.append(item)
        self._Validate()
        
    def isEmpty(self):
        return not self

    def _Validate(self):
        while len(self) >= 2:
            if self[-1] == self[-2]:
                self.pop()
                a = self.pop()
                if not (a == 'z'):
                    self.append(chr(ord(a) + 1))
            else:
                return

                
def ParseString(inputString):
    mStack = stack()
    skip = False
    for i in range(len(inputString)):
        if skip:
            skip = False
            continue
        if (not mStack.isEmpty) and inputString[i] == mStack[-1]:
            mStack.pop()
            mStack.push(chr(ord(inputString[i]) + 1))
        elif i < len(inputString) - 1 and inputString[i] == inputString[i + 1]:
            skip = True
            if not (inputString[i] == 'z'):
                mStack.push(chr(ord(inputString[i]) + 1))
        else:
            mStack.push(inputString[i])
    if len(mStack) == 0:
        return 'Yes'
    else:
        return 'No'

R = raw_input()
c = int(raw_input())
for i in xrange(c):
    L, N = raw_input().split()
    L = int(L)
    N = int(N)
    print ParseString(R[L - 1 : N])

Submission status: Time Limit Exceeded

Solution code:
enter = raw_input()
Q = int(raw_input())
que = []
for i in range(Q):
    que.append(map(int, raw_input().split()))
listletter = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(Q):
    start = que[i][0]-1
    end = que[i][1]
    substring = enter[start:end]
    end = True
    while (len(substring)>0):
        has = False
        for j in range(len(substring)-1):
            if len(substring)==1:
                if substring[0] != 'z':
                    break
            if substring[j] == substring[j+1]:
                has = True
                if substring[j] =='z':
                    newsubstring = substring[:j]+substring[(j+2):]
                    substring = newsubstring
                    break
                else:
                    newsubstring = substring[:j] + listletter[listletter.index(substring[j])+1] +substring[(j+2):]
                    substring = newsubstring
                    break
        if (not has):
            print 'No'
            end = False
            break
    if end:
        print 'Yes'

Submission status: Time Limit Exceeded

Solution code:
alphabet = [letter for letter in "abcdefghijklmnopqrstuvwxyz"]
def Check(s):
    s = [x for x in s]
    res = []
    terminated = len(s) == 0
    while not terminated:
        if len(res) == 0:
            res.append(s.pop(0))

        if len(s) == 0:
            terminated = True
            break
        letter = s.pop(0)
        if letter == res[-1]:
            res.pop()
            index = alphabet.index(letter) + 1
            if not (index == 26):
                res.append(alphabet[index])

            newlist = res + s
            s = newlist
            res = []
        else:
            res.append(letter)
        if len(s) == 0:
            terminated = True
    if len(res) == 0:
        print "Yes"
    else:
        print "No"
    return

sentence = raw_input()
Q = int(raw_input())
for i in xrange(Q):
    l, r = map(int, raw_input().split())
    word = sentence[l - 1:r]
    Check(word)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

def solve(s):
    while len(s) > 1:
        i = 0
        j = 1
        while (j < len(s) and s[i] != s[j]):
            i = i + 1
            j = j + 1
        while (j < len(s) and s[i] == s[j]):
            j = j + 1
        
        if (j-i) % 2 != 0:
            j = j - 1
        if j == i:
            break
        if s[i] == 'z':
            s = s[:i]+s[j:]
        else:
            s = s[:i]+(int((j-i)/2))*chr(ord(s[i])+1)+s[j:]

    if len(s) == 0:
        print('Yes')
    else:
        print('No')

s=input()
q=int(input())

for i in range(0,q):
    l,r=input().split()
    solve(s[int(l)-1:int(r)])

Submission status: Time Limit Exceeded

Solution code:
import sys

s = sys.stdin.readline().strip()
Q = int(sys.stdin.readline().strip())

alphabet = 'abcdefghijklmnopqrstuvwxyz'

def isEmpty(word):
    stack = []
    wordLen = len(word)
    curIndex = 0
    for i in range(wordLen):
        current = word[i]
        stack.append(current)
        if len(stack) == 1:
            continue
        else:
            stillCompressing = True
            while stillCompressing:
                current = stack.pop()
                prev    = stack.pop()
                if current == prev:
                    if prev != 'z':
                        stack.append(alphabet[alphabet.index(current) + 1])
                else:
                    stack.append(prev)
                    stack.append(current)
                    stillCompressing = False
                if len(stack) < 2:
                    stillCompressing = False
        
    return len(stack) == 0
            

for i in range(Q):
    bounds = sys.stdin.readline().strip().split()
    bounds = [int(bounds[j]) for j in range(2)]
    substr = s[bounds[0] - 1: bounds[1]]
    if isEmpty(substr):
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
def find_i(s):
	for i, c in enumerate(s[:-1]):
		if c == s[i+1]:
			return i
	return -1

def solution(s):
	#s = 'axxxxza'
	i = find_i(s)
	while i >= 0:
		if s[i] == 'z':
			if i == 0:
				s = s[2:]
			else:
				s = s[:i]+s[i+2:]
		else:
			r1 = chr(ord(s[i]) + 1)
			if i == 0:
				s = r1 + s[2:]
			else:
				s = s[:i]+r1+s[i+2:]
		i = find_i(s)
		#print (s)
	return s

def change(a):
	return int(a) -1

s = input()
q = int(input())
bb = []
for i in range(q):
	b = list(map(change, input().split()))
	test = s[b[0]:b[1]+1]
	if solution(test) == '':
		print('Yes')
	else:
		print('No')

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

def solve(s):
    while len(s) > 1:
        found = False
        for i in range(0,len(s)-1):
            if s[i] == s[i+1]:
                found = True
                if s[i] == 'z':
                    s = s[:i]+s[i+2:]
                else:
                    s = s[:i]+chr(ord(s[i])+1)+s[i+2:]
                break
        if not found:
            break


    if len(s) == 0:
        print('Yes')
    else:
        print('No')

s=input()
q=int(input())

for i in range(0,q):
    l,r=input().split()
    solve(s[int(l)-1:int(r)])

Submission status: Runtime Error

Solution code:
def stringProcessor(sequence):                                                  
    for i in range(0, len(sequence) - 1):                                       
        if sequence[i] == sequence[i + 1]:                                      
            if sequence[i] == ord('z'):                                         
                del sequence[i]                                                 
                del sequence[i]                                                 
            else:                                                               
                del sequence[i]                                                 
                sequence[i] += 1                                                
            return stringProcessor(sequence)                                    
    return sequence                                                             
                                                                                
sequence = map(ord, list(raw_input()))                                          
                                                                                
Q = int(raw_input())                                                            
                                                                                
queries = []                                                                    
for i in range(0, Q):                                                           
    queries.append(map(int, raw_input().split()))                               
                                                                                
for query in queries:                                                           
    if len(stringProcessor(sequence[query[0]-1:query[1]])) == 0:                
        print 'Yes'                                                             
    else:                                                                       
        print 'No'

Submission status: Runtime Error

Solution code:
# coding: utf-8

str_que = list(input())
num_que = int(input())
l_que = [list(map(int, input().split())) for i in range(num_que)]

print(str_que)
print(num_que)
print(l_que)

l_alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

n_ind = 0
count = 0
b_count = True
list_add = []

def check_min(list):
	global n_ind
	global count
	global b_count
	global list_add

	if len(list) == 0:
		print("yes")
		b_count = False

	else:
		count = 0
		list_add = [i for i in list]
		list_add.append(0)
		
		for index, item in enumerate(list):
			if index == len(list):
				break
			else:
				if list_add[index + 1] == item:
					n_ind = index
					count += 1
					break
				else:
					continue

		if count == 0:
			print("no")
			b_count = False

def change_list(index, list):
	global list_check
	if list[index] == "z":
		del list[index + 1]
		del list[index]
		list_check = list
		
	else:
		alp_index = l_alp.index(list[index])
		list[index] = l_alp[alp_index + 1]
		list[index + 1] = l_alp[alp_index + 1]
		list_check = list

for i in l_que:
	print(i)
	i_0 = i[0]
	i_1 = i[1]
	range_check = list(range((i_0 - 1), i_1))
	list_check = [str_que[j] for j in range_check]
	print(list_check)
	while b_count:
		check_min(list_check)
		change_list(n_ind, list_check)
	b_count = True

Submission status: Runtime Error

Solution code:
enter = raw_input()
Q = int(raw_input())
que = []
for i in range(Q):
    que.append(map(int, raw_input().split()))
que = [[1, 7], [2, 6]]
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(Q):
    start = que[i][0]-1
    end = que[i][1]
    substring = enter[start:end]
    end = True
    while (len(substring)>0):
        has = False
        for j in range(len(substring)-1):
            if len(substring)==1:
                if substring[0] != 'z':
                    break
            if substring[j] == substring[j+1]:
                has = True
                if substring[j] =='z':
                    newsubstring = substring[:j]+substring[(j+2):]
                    substring = newsubstring
                    break
                else:
                    newsubstring = substring[:j] + list[list.index(substring[j])+1] +substring[(j+2):]
                    substring = newsubstring
                    break
        if (not has):
            print 'No'
            end = False
            break
    if end:
        print 'Yes'