Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
s=input()
for i in range(q):
	l,r=map(int,input().split())
	print(s[l-1:r].count('AC'))

Fixed submission:
def resolve():
	n,q=map(int,input().split())
	s=input()
	lr=[list(map(int,input().split())) for i in range(q)]

	t=[0]*(n+1)
	for i in range(n):
		t[i+1]=t[i]+(s[i:i+2]=='AC')
	
	for i in range(q):
		l=lr[i][0]
		r=lr[i][1]

		print(t[r-1]-t[l-1])
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	n,q=map(int,input().split())
	s=input()
	lr=[list(map(int,input().split())) for i in range(q)]
	
	for i in range(q):
		l=lr[i][0]-1
		r=lr[i][1]
		t=s[l:r]
		print(t.count('AC'))
resolve()

Fixed submission:
def resolve():
	n,q=map(int,input().split())
	s=input()
	lr=[list(map(int,input().split())) for i in range(q)]

	t=[0]*(n+1)
	for i in range(n):
		t[i+1]=t[i]+(s[i:i+2]=='AC')
	
	for i in range(q):
		l=lr[i][0]
		r=lr[i][1]

		print(t[r-1]-t[l-1])
resolve()
Buggy python submission (verdict: Runtime Error):
from functools import reduce

def resolve():
	A,B=map(int,input().split())
	l=list(range(A,B+1))
	print(reduce(lambda a,b:a^b,l))
resolve()

Fixed submission:
def F(n):
	if n%2==1:
		ans=0 if (n+1)%4==0 else 1
	else:
		ans=n^0 if n%4==0 else n^1
	return ans
def resolve():
	A,B=map(int,input().split())
	print(F(A-1)^F(B))
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			cnt+=S.count('10')
			S=S.replace('10','')
			chk=1
		if '01' in S:
			cnt+=S.count('01')
			S=S.replace('01','')
			chk=1
	print(cnt*2)
resolve()

Fixed submission:
def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		if '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)
resolve()

Fixed submission:
def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		elif '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)
resolve()

Fixed submission:
def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	S=input()
	chk=1
	cnt=0
	while chk==1:
		chk=0
		if len(S)==0:
			break
		if '10' in S:
			S=S.replace('10','',1)
			chk=1
			cnt+=1
		elif '01' in S:
			S=S.replace('01','',1)
			chk=1
			cnt+=1
	print(cnt*2)

resolve()

Fixed submission:
def resolve():
	S=input()
	print(min(S.count('1'),S.count('0'))*2)
resolve()
Buggy python submission (verdict: Runtime Error):
s=input()
print('YES' if (len(s)>=7 and s[:3]=='key' and s[-4:]=='ence') or s[:7]=='keyence' or s[-7:]='keyence' else 'NO')

Fixed submission:
s=input()
for i in range(len(s)):
	for j in range(i,len(s)+1):
		if s[:i]+s[j:]=='keyence':
			print('YES')
			break
	else:
		continue
	break
else:
	print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import fractions


def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	a=[abs(i-j) for i in x_list for j in x_list if i!=j]
	print(functools.reduce(fractions.gcd,a))

resolve()

Fixed submission:
import functools
import fractions

def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	x_list.sort()
	a=[abs(x_list[i]-x_list[i+1]) for i in range(n)]
	print(functools.reduce(fractions.gcd,a))
resolve()

Buggy python submission (verdict: Runtime Error):
import functools
import math


def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	a=[i-j for i in x_list for j in x_list if i!=j]
	print(functools.reduce(math.gcd,a))
resolve()

Fixed submission:
import functools
import fractions

def resolve():
	n,x=map(int,input().split())
	x_list=list(map(int,input().split()))
	x_list.append(x)
	x_list.sort()
	a=[abs(x_list[i]-x_list[i+1]) for i in range(n)]
	print(functools.reduce(fractions.gcd,a))
resolve()
Buggy python submission (verdict: Runtime Error):
d,n=map(int,input())
ans=100**d*n if n<100 else 100*d*101
print(ans)

Fixed submission:
def resolve():
	d,n=map(int,input().split())
	ans=100**d*n if n<100 else 100**d*101
	print(ans)
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools


def resolve():
	n,m=map(int,input().split())
	l=[]
	for i in range(n):
		x,y,z=map(int,input().split())
		l.append([x,y,z])
	lst=list(itertools.combinations(l,m))
	ms=0
	for i in lst:
		xx=abs(sum([p[0] for p in i]))
		yy=abs(sum([p[1] for p in i]))
		zz=abs(sum([p[2] for p in i]))
		ms=max(ms,xx+yy+zz)
	print(ms)
resolve()

Fixed submission:
def resolve():
	ans=0
	n,m=map(int,input().split())
	xyz=[list(map(int,input().split())) for i in range(n)]
	t=[(1,1,1),(1,1,-1),(1,-1,1),(1,-1,-1),(-1,1,1),(-1,1,-1),(-1,-1,1),(-1,-1,-1)]
	for k in t:
		l=[k[0]*x+k[1]*y+k[2]*z for x,y,z in xyz ]
		l.sort(reverse=True)
		ans=max(ans,sum(l[:m]))
	print(ans)

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def gen_prime():
	yield 2
	yield 3
	n=0
	while 1:
		yield n+5
		yield n+7
		n+=6


def resolve():
	l=list(range(55556))
	l[1]=0
	p=gen_prime()
	for i in p:
		if i in l:
			t=i+i
			while t<55556:
				l[t]=0
				t+=i
	prime=[i for i in l if i%5==1]
	n=int(input())
	ans=l[:n]
	x=''
	for i in ans:
		x+=i+' '
	print(x[:-1])
resolve()

Fixed submission:
def gen_prime():
	yield 2
	yield 3
	n=0
	while 1:
		yield n+5
		yield n+7
		n+=6


def resolve():
	l=list(range(55556))
	l[1]=0
	p=gen_prime()
	for i in p:
		if i**2>55556:
			break
		if i in l:
			t=i+i
			while t<55556:
				l[t]=0
				t+=i
	prime=[i for i in l if i%5==1]
	n=int(input())
	ans=prime[:n]
	x=''
	for i in ans:
		x+=str(i)+' '
	print(x[:-1])

resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	n=int(input())
	x=list(map(int,input().split()))
	for i in x:
		s=sorted(x)
		s.remove(i)
		print(s[(n-2)//2])
	
resolve()

Fixed submission:
def resolve():
	n=int(input())
	x=list(map(int,input().split()))
	s=sorted(x)
	m=s[(n-2)//2]
	for i in x:
		ans=s[(n-2)//2+1] if i<=m else m
		print(ans)
	
resolve()
Buggy python submission (verdict: Runtime Error):
def resolve():
    a,b,k=map(int,input().split())
    l=list(range(a,b+1))
    ans=l[:k]
    ans+=l[-k:]
    answer=sorted(list(set(ans)))
    for i in answer:
        print(i)
resolve()

Fixed submission:
def resolve():
    a,b,k=map(int,input().split())
    realk=min(b-a+1,k)
    ans=list(range(a,a+realk))
    ans+=list(range(b-realk+1,b+1))
    answer=sorted(list(set(ans)))
    for i in answer:
        print(i)
    

resolve()
Buggy python submission (verdict: Runtime Error):
x,y=map(input())
if x<y:
  print('<')
elif x>y:
  print('>')
else:
  print('=')

Fixed submission:
x,y=map(str,input().split())
if x<y:
  print('<')
elif x>y:
  print('>')
else:
  print('=')
Buggy python submission (verdict: Runtime Error):
print(sum(int(input())))

Fixed submission:
print(sum([int(i) for i in input()]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
s=sorted(list(set(a)))
m=0
for i in s:
	m=max(m,a.count(i-1)+a.count(i)+a.count(i+1))
print(m)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in a:
	if i-1 in dic:
		dic[i-1]+=1
	else:
		dic[i-1]=1
	if i in dic:
		dic[i]+=1
	else:
		dic[i]=1
	if i+1 in dic:
		dic[i+1]+=1
	else:
		dic[i+1]=1
print(max(dic.values()))

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
	n=int(input())
	a=list(map(int,input().split()))
	l=min(a)+1
	g=max(a)
	if n==1:
		ans=1
	else:
		ans=0
		for i in a:
			ans=max(ans,a.count(i))
		for i in range(l,g):
			ans=max(ans,a.count(i-1)+a.count(i)+a.count(i+1))
	print(ans)
resolve()

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in a:
	if i-1 in dic:
		dic[i-1]+=1
	else:
		dic[i-1]=1
	if i in dic:
		dic[i]+=1
	else:
		dic[i]=1
	if i+1 in dic:
		dic[i+1]+=1
	else:
		dic[i+1]=1
print(max(dic.values()))
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print(max(b-c),0)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(min(b,d)-max(a,c),0))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print(max(b-c),0)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max(min(b,d)-max(a,c),0))
Buggy python submission (verdict: Runtime Error):
n,m=map(int(input().split())
print((n-1)*(m-1))

Fixed submission:
n,m=map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
a=input()
print('{}{}{}'.format(a[0],str(len(a)-2),a[-1])

Fixed submission:
a=input()
print('{}{}{}'.format(a[0],str(len(a)-2),a[-1]))
Buggy python submission (verdict: Time Limit Exceeded):
a,b,x=map(int,input().split())
while a%x!=0:
	a+=1
while b%x!=0:
	b-=1
print((b-a)//x +1)


Fixed submission:
a,b,x=map(int,input().split())
a+=(-a)%x
b-=a%x
print((b-a)//x +1)
Buggy python submission (verdict: Runtime Error):
N=input()
ans=0
l=itertools.product(range(2),repeat=len(N)-1)
for i in l:
	tmp=''
	for j in range(len(i)):
		if i[j]==0:
			tmp+=N[j]
		else:
			tmp+=N[j]+'+'
	tmp+=N[-1]
	ans+=eval(tmp)
print(ans)


Fixed submission:
import itertools
N=input()
ans=0
l=itertools.product(range(2),repeat=len(N)-1)
for i in l:
	tmp=''
	for j in range(len(i)):
		if i[j]==0:
			tmp+=N[j]
		else:
			tmp+=N[j]+'+'
	tmp+=N[-1]
	ans+=eval(tmp)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
pre = 1

for i in a[:k]:
    pre *= i
    
for i in range(k,n):
    now = pre * a[i] // a[i-k]
    
    if pre < now:
        print("Yes")
    
    else:
        print("No")
        
    pre = now

Fixed submission:
x = int(input()) - 400
ans = 8

while x >= 200:
    x -= 200
    ans -= 1
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
pre = 1

for i in a[:k]:
    pre *= i
    
for i in range(k,n):
    now = pre * a[i] // a[i-k]
    
    if pre < now:
        print("Yes")
    
    else:
        print("No")
        
    pre = now

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
    
for i in range(k,n):
    if a[i-k] < a[i]:
        print("Yes")
        
    else:
        print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
pre = 1

for i in a[:k]:
    pre *= i
    
for i in range(k,n):
    now = pre * a[i] // a[i-k]
    
    if pre < now:
        print("Yes")
    
    else:
        print("No")
        
    pre = now

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
    
for i in range(k,n):
    if a[i-k] < a[i]:
        print("Yes")
        
    else:
        print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134]
ans = ""

for i in range(len(kugiri)):
    if n <= kugiri[i]:
        keta = i
        break
        
n -= kugiri[i-1]

for i in range(keta):
    moji = -(-n // 26**(keta-1))
    ans += chr(moji+96)
    n -= (moji-1) * 26**(keta-1)
    keta -= 1
    
print(ans)

Fixed submission:
n = int(input())
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134,146813779479510,3817158266467286]
ans = ""

for i in range(len(kugiri)):
    if n <= kugiri[i]:
        keta = i
        break
        
n -= kugiri[i-1]

for i in range(keta):
    moji = -(-n // 26**(keta-1))
    ans += chr(moji+96)
    n -= (moji-1) * 26**(keta-1)
    keta -= 1
    
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134]
ans = ""

for i in range(len(kugiri)):
    if n <= kugiri[i]:
        keta = i
        break
        
n -= kugiri[i-1]

for i in range(keta):
    moji = n // 26**(keta-1)
    
    if keta == 1:
        moji -= 1
    
    ans += chr(moji+97)
    n -= moji * 26**(keta-1)
    keta -= 1
    
print(ans)

Fixed submission:
n = int(input())
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134,146813779479510,3817158266467286]
ans = ""

for i in range(len(kugiri)):
    if n <= kugiri[i]:
        keta = i
        break
        
n -= kugiri[i-1]

for i in range(keta):
    moji = -(-n // 26**(keta-1))
    ans += chr(moji+96)
    n -= (moji-1) * 26**(keta-1)
    keta -= 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ans = [-1] * n
edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
    
import collections
que = collections.deque()
que.append(0)
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        if ans[to] == -1:
            ans[to] = x + 1
            que.append(to)
            
print("Yes")
print(*ans[1:],sep="\n")

Fixed submission:
n = int(input())

if n % 10 == 3:
    print("bon")

elif n % 10 in [0,1,6,8]:
    print("pon")
    
else:
    print("hon")

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
AB = []
ans = [0] * (n-1)

for i in range(m):
    AB.append(list(map(int,input().split())))
    
import collections
que = collections.deque()
que.append(1)
    
while que:
    x = que.popleft()
    
    for i in AB:
        a = i[0]
        b = i[1]
        
        if a == x and ans[b-2] == 0:
            ans[b-2] = x
            que.append(b)
        elif b == x and ans[a-2] == 0:
            ans[a-2] = x
            que.append(a)
            
if 0 in ans:
    print("No")
else:
    print("Yes")
    
    for i in ans:
        print(i)

Fixed submission:
n = int(input())

if n % 10 == 3:
    print("bon")

elif n % 10 in [0,1,6,8]:
    print("pon")
    
else:
    print("hon")
Buggy python submission (verdict: Runtime Error):
n,m,x = map(int,input().split())
ans = 12*(10**5)+1
C = []
A = []

for _ in range(n):
    AC = list(map(int,input().split()))
    C.append(AC[0])
    A.append(AC[1:])

for i in range(2**n):
    understood = [0]*m
    cost = 0
    
    for j in range(n):
        if (i>>j)&1:
            cost += C[j]
            
            for k in range(m):
                understood[k] += A[j][k]
            
    if min(understood) >= x:
        ans = min(ans,cost)

if ans == 12*(10**5)+1:
    ans = -1
        
print(ans)

Fixed submission:
s = input()
t = input()
ans = "No"

if s == t[:-1]:
    if len(s)+1 == len(t):
        ans = "Yes"
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [0]
now = 0
flag = 0

for i in range(k):
    now = a[now]
    
    if now in set(visited):
        loop_start = now
        flag = 1
        break
        
    else:
        visited.append(now)
        
if flag == 1:
    loop = visited[visited.index(loop_start):]
    m = len(loop)
    
    now = loop[(k-(len(visited)-m))%m]
    
print(now + 1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [-1] * n
now = 0

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [0]
now = 0
flag = 0

for i in range(k):
    now = a[now]
    
    if now in set(visited):
        loop_start = now
        flag = 1
        break
        
    else:
        visited.append(now)
        
if flag == 1:
    loop = visited[visited.index(loop_start):]
    m = len(loop)
    
    now = loop[(k-(len(visited)-m))%m]
    
print(now + 1)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(n):
    a[i] -= 1
    
visited = [-1] * n
now = 0

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
ans = 0

import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

import itertools
A = list(itertools.product(range(1,k+1), repeat=3))

for i in range(len(A)):
    ans += gcd_list(A[i])
    
if k == 1:
    print(1)
elif k == 2:
    print(9)
else:
    print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)

Fixed submission:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0

for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            ans += gcd(x,y,z)
            
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
B = sorted(set(A))
ans = 0

for i in range(len(B)):
    m = A.count(B[i])
    if m > 1:
        ans += m*(m-1)//2
        
for i in range(n):
    m = A.count(A[i])
    print(ans + 1 - m)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

import collections
c = collections.Counter(a)

for i in c.values():
    ans += i*(i-1)//2
    
for i in a:
    print(ans - c[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
B = sorted(set(A))
dic = {}
ans = 0

for i in range(len(B)):
    if A.count(B[i]) > 1:
        C = A.count(B[i])
        dic[B[i]] = C
        ans += C*(C-1)//2
    else:
        dic[B[i]] = 1
        
for i in range(len(B)):
    x = dic[B[i]]
    dic[B[i]] = ans + 1 - x

for i in range(n):
    print(dic[A[i]])

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

import collections
c = collections.Counter(a)

for i in c.values():
    ans += i*(i-1)//2
    
for i in a:
    print(ans - c[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int,input().split()))
B = sorted(set(A))
dic = {}
ans = 0

for i in range(len(B)):
    if A.count(B[i]) > 1:
        C = A.count(B[i])
        dic[B[i]] = C
        ans += C*(C-1)//2
    else:
        dic[B[i]] = 1
        
for i in range(n):
    x = dic[A[i]]
    print(ans - x*(x-1)//2 + (x-1)*(x-2)//2)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = 1

import collections
c = collections.Counter(a)

for i in c.values():
    ans += i*(i-1)//2
    
for i in a:
    print(ans - c[i])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
a = "*"
n = int(input())
kaitenn = 1

for i in range(n):
    q = input()
    if q[0] == "1":
        kaitenn *= -1
        a = a[::-1]
    else:
        if q[2] == "1":
            a = q[4] + a
        else:
            a = a + q[4]
            
print(a[:a.index("*")]+s[::kaitenn]+a[a.index("*")+1:])

Fixed submission:
s = input()
n = int(input())
a = "*"
spin = 1

for i in range(n):
    q = input()
    if q[0] == "1":
        spin *= -1
        a = a[::-1]
    else:
        if q[2] == "1":
            a = q[4] + a
        else:
            a = a + q[4]
            
    if len(a) == 100:
        s = a[:a.index("*")] + s[::spin] + a[a.index("*")+1:]
        a = "*"
        spin = 1
            
print(a[:a.index("*")] + s[::spin] + a[a.index("*")+1:])

Buggy python submission (verdict: Time Limit Exceeded):
a = input()
n = int(input())

for i in range(n):
    q = input()
    if q[0] == "1":
        a = a[::-1]
    else:
        if q[2] == "1":
            a = q[4] + a
        else:
            a = a + q[4]
            
print(a)

Fixed submission:
s = input()
n = int(input())
a = "*"
spin = 1

for i in range(n):
    q = input()
    if q[0] == "1":
        spin *= -1
        a = a[::-1]
    else:
        if q[2] == "1":
            a = q[4] + a
        else:
            a = a + q[4]
            
    if len(a) == 100:
        s = a[:a.index("*")] + s[::spin] + a[a.index("*")+1:]
        a = "*"
        spin = 1
            
print(a[:a.index("*")] + s[::spin] + a[a.index("*")+1:])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
ans = [1]
for i in range(n-1):
    ans.append("0")

for i in range(m):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    
for i in range(m):
    ans[s[i]-1] = c[i]
    
    if i == m-1:
        ANS = ""
        for j in range(n):
            ANS += str(ans[j])
            
for i in range(m):
    if s[i] == 1 and c[i]==0:
        ANS = -1
    
    for j in range(m):
        if s[i] == s[j] and c[i] != c[j]:
            ANS = -1
            
print(ANS)

Fixed submission:
n,m = map(int,input().split())
s = []
c = []
ans = [1]
for i in range(n-1):
    ans.append("0")
ANS = ""

for i in range(m):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    
for i in range(m):
    ans[s[i]-1] = c[i]
    
    if i == m-1:
        for j in range(n):
            ANS += str(ans[j])
            
for i in range(m):
    if s[i] == 1 and c[i]==0 and n!=1:
        ANS = -1
    
    for j in range(m):
        if s[i] == s[j] and c[i] != c[j]:
            ANS = -1
            
if m == 0:
    if n == 1:
        ANS = 0
    else:
        ANS = "1"+"0"*(n-1)
            
print(ANS)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = []
c = []
ans = ["0" for i in range(n)]

for i in range(m):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    
for i in range(m):
    ans[s[i]-1] = c[i]
    
    if i == m-1:
        ANS = ""
        for j in range(n):
            ANS += str(ans[j])
            
for i in range(m):
    if s[i] == 1 and c[i]==0:
        ANS = -1
    
    for j in range(m):
        if s[i] == s[j] and c[i] != c[j]:
            ANS = -1
            
print(ANS)

Fixed submission:
n,m = map(int,input().split())
s = []
c = []
ans = [1]
for i in range(n-1):
    ans.append("0")
ANS = ""

for i in range(m):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    
for i in range(m):
    ans[s[i]-1] = c[i]
    
    if i == m-1:
        for j in range(n):
            ANS += str(ans[j])
            
for i in range(m):
    if s[i] == 1 and c[i]==0 and n!=1:
        ANS = -1
    
    for j in range(m):
        if s[i] == s[j] and c[i] != c[j]:
            ANS = -1
            
if m == 0:
    if n == 1:
        ANS = 0
    else:
        ANS = "1"+"0"*(n-1)
            
print(ANS)