Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def isInvalid(maze,i,j,dr,dc,visited):
    if i>dr or i<0 or j>dc or j<0:
        return True
    
    if visited[i][j]:
        return True
    
    if maze[i][j] == "#":
        return True
    
    return False

def grid(maze,i,j,dr,dc,visited):
    global count

    if i == dr and j == dc:
        count+=1
        
        return 
    
    if isInvalid(maze,i,j,dr,dc,visited):
        return
    visited[i][j] = True

    grid(maze,i,j+1,dr,dc,visited)
    grid(maze,i+1,j,dr,dc,visited)
    visited[i][j]= False

    



h,w = map(int,input().split())

maze = []

for _ in range(h):
    maze.append(list(input()))

count=0

visited = [[False]*w for _ in range(h)]
grid(maze,0,0,h-1,w-1,visited)
mod = 7+10**9
print(count%mod)


Fixed submission:
def grid(maze,h,w):
    mod = 7+10**9
    visited = [[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if maze[i][j] == "#":
                continue

            if i==0 and j==0:
                visited[i][j] = 1
                
            
            elif i == 0:
                visited[i][j] = visited[i][j-1]
            elif j == 0:
                visited[i][j] = visited[i-1][j]
            else:
                visited[i][j] = (visited[i-1][j]%mod + visited[i][j-1]%mod)%mod
    
    return visited[h-1][w-1]


h,w = map(int,input().split())

maze = []

for _ in range(h):
    maze.append(list(input()))

print(grid(maze,h,w))
Buggy python submission (verdict: Time Limit Exceeded):
import math

K =int(input())
sum = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            d = math.gcd(a,b)
            sum += math.gcd(c,d)
print(sum)



Fixed submission:
import math
from functools import reduce

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

K =int(input())
sum = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            sum += gcd(a,b,c)
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = []
for i in range(n):
  num = int(input())
  nums.append(num)
count = 0
setnums = set(nums)
for j in setnums:
  test = nums.count(j)
  if test % 2 == 1:
    count += 1
print(count)

Fixed submission:
from collections import defaultdict

cnt = defaultdict(int)

n = int(input())
for i in range(n):
    value = int(input())
    cnt[value] += 1

ret = 0
for c in cnt.values():
    if c % 2 == 1:
        ret += 1
print(ret)
Buggy python submission (verdict: Runtime Error):
o = str(input())
s = str(input())
n = ""

if not len(o) == len(s):
	for i in range(min(len(o),len(s))):
		n += o[i]
		n += s[i]

	if len(o) > len(s):
		n += o[len(o)-1]

	if len(s) > len(o):
		n += s[len(s)-1]

else:
	for i in rage(len(o)):
		n += o[i]
		n += s[i]
		
print(n)


Fixed submission:
o = str(input())
s = str(input())
n = ""

if not len(o) == len(s):
	for i in range(min(len(o),len(s))):
		n += o[i]
		n += s[i]

	if len(o) > len(s):
		n += o[len(o)-1]

else:
	for i in range(len(o)):
		n += o[i]
		n += s[i]
		
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_a = [int(x) for x in input().split()]
ans = 1

for i in range(0, n):
    ans *= list_a[i]

if ans > 10 ** 18:
    print('-1')
    exit()

else: print(ans)

Fixed submission:
n = int(input())
list_a = [int(x) for x in input().split()]
list_a_str = [str(s) for s in list_a]
ans = 1

for i in range(0, n):
    if list_a_str[i] in '0':
        print('0')
        exit()

for i in range(0, n):
    ans *= list_a[i]
    if ans > 10 ** 18:
        print('-1')
        exit()

else: print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a, b = 0
for i in range(1, 10):
    b = i
    a = n // i
    if n % i !=0: continue
    elif a <= 9 and b <= 9: 
        print('Yes')
        break
    else :
        print('No')
        break

Fixed submission:
n = int(input())
a = 0
b = 0
for i in range(1, 10):
    b = i
    a = n // i
    if n % i !=0: continue
    elif a <= 9 and b <= 9:
        print('Yes')
        exit()
print('No')
Buggy python submission (verdict: Runtime Error):
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, w)]
list_tmp = []
for i in range(0, w):
    for j in range(0, h):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, h):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))

Fixed submission:
h, w = (int(i) for i in input().split())
list_a = [input() for s in range(0, h)]
list_tmp = []
for i in range(0, h):
    for j in range(0, w):
        if list_a[i][j] == '#':
            list_tmp.append(list(list_a[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_tmp_t = [list(x) for x in zip(*list_tmp)]
list_tmp2 = []
for i in range(0, len(list_tmp_t)):
    for j in range(0, len(list_tmp_t[i])):
        if list_tmp_t[i][j] == '#':
            list_tmp2.append(list(list_tmp_t[i]))
            break
# 転置... https://note.nkmk.me/python-list-transpose/　参照
list_ans = [list(x) for x in zip(*list_tmp2)]
for i in range(0, len(list_ans)):
    print("".join(list_ans[i]))
Buggy python submission (verdict: Runtime Error):
# 105の約数は1, 3, 5, 7, 3 * 5, 3 * 7, 5 * 7, 3 * 5 * 7
# ほかにありえるのは
# ①1, 3, 5, 9, ...
# ②1, 3, 5, 11, ...
# ③1, 3, 5, 13, ...
n = int(input())
if n < 105: print(0)
elif n < 135: print(1)
elif n < 165: print(2)
elif n < 195: print(3)
else print(4)

Fixed submission:
# 105の約数は1, 3, 5, 7, 3 * 5, 3 * 7, 5 * 7, 3 * 5 * 7
# ほかにありえるのは
# ①1, 3, 5, 9, ...
# ②1, 3, 5, 11, ...
# ③1, 3, 7, 9, ...
# ④1, 3, 5, 13, ...
n = int(input())
if n < 105: print(0)
elif n < 135: print(1)
elif n < 165: print(2)
elif n < 189: print(3)
elif n < 195: print(4)
else: print(5)
Buggy python submission (verdict: Runtime Error):
a,b = map(str, input().split())
print(b+s)

Fixed submission:
a,b = map(str, input().split())
print(b+a)
Buggy python submission (verdict: Runtime Error):
n=input()
sm=0
for i in n:
  sm+=int(i)
return sm%9

Fixed submission:
n=int(input())
if n%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
a,b=map(input())
a=a+b
if (a)%2==0:
  print(a//2)
else:
  print('IMPOSSIBLE')

Fixed submission:
a,b=map(int,input().split())
a=a+b
if (a)%2==0:
  print(a//2)
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
P = 1000000000
for i in range(N):
    tmp = input().split(".")
    if len(tmp) == 2:
        a = int(tmp[1])
        for j in range(9-len(tmp[1])):
            a *= 10
        A.append(int(tmp[0]) * P + a)
    else:
        A.append(int(tmp[0]) * P)

div2 = [0 for i in range(N)]
div5 = [0 for i in range(N)]

for i in range(N):
    tmp = A[i]
    while tmp % 2 == 0:
        div2[i] += 1
        tmp = tmp//2
    while tmp % 5 == 0:
        div5[i] += 1
        tmp = tmp//5

cnt = [[0 for i in range(19)] for i in range(19)]

for i in range(N):
    d2 = div2[i]
    d5 = div5[i]
    if d2 > 18:
        d2 = 18
    if d5 > 18:
        d5 = 18
    cnt[d2][d5] += 1

ans = 0

for i in range(N):
    lower2 = 18 - div2[i]
    lower5 = 18 - div5[i]

    if lower2 < 0:
        lower2 = 0
    if lower5 < 0:
        lower5 = 0

    for j in range(lower2, 19):
        for k in range(lower5, 19):
            ans += cnt[j][k]

for a in A:
    if a % P == 0:
        ans -= 1

print(ans//2)


Fixed submission:
N = int(input())
A = []
P = 1000000000
for i in range(N):
    tmp = input().split(".")
    if len(tmp) == 2:
        a = int(tmp[1])
        for j in range(9-len(tmp[1])):
            a *= 10
        A.append(int(tmp[0]) * P + a)
    else:
        A.append(int(tmp[0]) * P)

div2 = [0 for i in range(N)]
div5 = [0 for i in range(N)]

for i in range(N):
    tmp = A[i]
    while tmp % 2 == 0:
        div2[i] += 1
        tmp = tmp//2
    while tmp % 5 == 0:
        div5[i] += 1
        tmp = tmp//5

cnt = [[0 for i in range(19)] for i in range(19)]

for i in range(N):
    d2 = div2[i]
    d5 = div5[i]
    if d2 > 18:
        d2 = 18
    if d5 > 18:
        d5 = 18
    cnt[d2][d5] += 1

ans = 0

for i in range(N):
    lower2 = 18 - div2[i]
    lower5 = 18 - div5[i]

    if lower2 < 0:
        lower2 = 0
    if lower5 < 0:
        lower5 = 0

    for j in range(lower2, 19):
        for k in range(lower5, 19):
            ans += cnt[j][k]

for a in A:
    if a % P == 0:
        ans -= 1

print(ans//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = map(int,input().split())

if D[0] != 0:
  print(0)
  exit(0)
D.sort()

if D[1] != 0:
  print(0)
  exit(0)

for i in range(0,N-1):
  if abs(D[i] - D[i+1]) > 1:
    print(0)
    exit(0)

cnt = [0 for _ in range(N)]

for i in range(1,N):
  cnt[D[i]] += 1

ans = 1

for i in range(1,N):
  if cnt[i+1] == 0:
    break
  ans *= cnt[i] * cnt[i+1]
  ans %= 998244353
  
print(ans)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
    print(0)
    exit(0)
D.sort()

if D[1] == 0:
    print(0)
    exit(0)

for i in range(0, N-1):
    if abs(D[i] - D[i+1]) > 1:
        print(0)
        exit(0)

cnt = [0 for _ in range(N)]

for i in range(0, N):
    cnt[D[i]] += 1

ans = 1

for i in range(0, N-1):
    if cnt[i+1] == 0:
        break
    ans *= pow(cnt[i], cnt[i+1])
    ans %= 998244353

print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as n;print([input(),n.gcd.reduce(list(map(int,input().split())))][1])

Fixed submission:
from fractions import gcd
print [input(),reduce(gcd,map(int,raw_input().split()))][1]

Buggy python submission (verdict: Runtime Error):
print [input(),reduce(raw_input().split(),gcd)][1]

Fixed submission:
from fractions import gcd
print [input(),reduce(gcd,map(int,raw_input().split()))][1]
Buggy python submission (verdict: Runtime Error):
input();s=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])


Fixed submission:
print((lambda l:['No','Yes'][sum(l[:-1])>l[-1]])(sorted(list(map(int,input().split()+input().split()))[1:])))
Buggy python submission (verdict: Time Limit Exceeded):
imos = [[0 for j in range(501)]for i in range(501)]
query = []
N,M,Q = map(int,input().split())
for i in range(M):
    L,R = map(int,input().split())
    imos[L][R] += 1
for i in range(Q):
    p,qq = map(int,input().split())
    query.append([p,qq])
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i][j-1]
for q in query:
    ans = 0
    for i in range(q[0],N+1):
        ans += imos[i][q[1]]
    print(ans)


Fixed submission:
imos = [[0 for j in range(501)]for i in range(501)]
query = []
N,M,Q = map(int,input().split())
for i in range(M):
    L,R = map(int,input().split())
    imos[L][R] += 1
for i in range(Q):
    p,qq = map(int,input().split())
    query.append([p,qq])
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i][j-1]
for i in range(501):
    for j in range(1,501):
        imos[i][j] += imos[i-1][j]
for q in query:
    print(imos[N][q[1]]-imos[q[0]-1][q[1]])
Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        for z in range(0, N+1):
            if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
                print(x, y, z)
                exit(0)
print(-1, -1, -1)


Fixed submission:
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        z = N - x - y
        if z < 0:
            continue
        if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)

Buggy python submission (verdict: Time Limit Exceeded):
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        for z in range(0, N+1):
            if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
                print(x, y, z)
                exit(0)
print(-1, -1, -1)


Fixed submission:
N, Y = map(int, input().split())
for x in range(0, N+1):
    for y in range(0, N+1):
        z = N - x - y
        if z < 0:
            continue
        if x + y + z == N and 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit(0)
print(-1, -1, -1)
Buggy python submission (verdict: Runtime Error):
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+i]) != 1):flag = 0
if flag:print("Yes")
else:print("No")


Fixed submission:
def number(c):
    c = str(c)
    ans = 0
    s = "0123456789"
    for i in range(10):
        if c == s[i]:ans = 1
    return ans

A,B = map(int,input().split())
S = input()
flag = 1
for i in range(A):
    if(number(S[i]) != 1):flag = 0
if S[A] != "-":flag = 0
for j in range(B):
    if(number(S[A+1+j]) != 1):flag = 0
if flag:print("Yes")
else:print("No")
Buggy python submission (verdict: Runtime Error):
import math;print(int((lambda l:math.floor(1e-5+math.log2(l[1]/l[0]))+1))(list(map(int,input().split()))))


Fixed submission:
X,Y = map(int,input().split())
ans = 0
while X <= Y:
	ans += 1
	X *= 2
print(ans)

Buggy python submission (verdict: Runtime Error):
import math;print(int((lambda l:math.floor(1e-9+math.log2(l[1]/l[0]))+1))(list(map(int,input().split()))))

Fixed submission:
X,Y = map(int,input().split())
ans = 0
while X <= Y:
	ans += 1
	X *= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
 print(["Yes","No"][(lambda x:bool(x/100-x%10))(input())])

Fixed submission:
print(["Yes","No"][(lambda x:(abs(x//100-x%10)+99)//100)(input())])
Buggy python submission (verdict: Runtime Error):
l = map(int,input().split());print(max(l[0]*l[1],l[2]*l[3]))

Fixed submission:
a,b,c,d=map(int,input().split());print(max(a*b,c*d))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(a==b+c)+bool(b==a+c)+bool(c==a+b)])


Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c)+(b==a+c)+(c==a+b)])


Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(bool(a==b+c)or(bool(b==a+c))or(bool(c==a+b)))])


Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool((a==b+c)or(b==a+c)or(c==a+b))])


Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][bool(a==b+c or b==a+c or c==a+b)])


Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c or b==a+c or c==a+b)])

Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][(a==b+c or b==a+c or c==a+b)])

Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][a==b+c or b==a+c or c==a+b])

Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])

Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input.split());print(["No","Yes"][a==b+c or b=a+c or c==a+b])

Fixed submission:
a,b,c=map(int,input().split());print(["No","Yes"][(a+b==c)+(b+c==a)+(c+a==b)])
Buggy python submission (verdict: Runtime Error):
print(sum([x for i in range(int(input())+1)]))

Fixed submission:
print(sum([int(i) for i in range(int(input())+1)]))

Buggy python submission (verdict: Runtime Error):
print((lambda x:x* x-~/2)(int(input())))

Fixed submission:
print(sum([int(i) for i in range(int(input())+1)]))

Buggy python submission (verdict: Runtime Error):
print((lambda x:x* x-~/2)(int(input())))

Fixed submission:
print(sum([int(i) for i in range(int(input())+1)]))
Buggy python submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(map(int,input().split()))-multiset([5,5,7]))))])

Fixed submission:
l=input().split();list.sort(l);print(["NO","YES"][l==["5","5","7"]])

Buggy python submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(input().split())-multiset([5,5,7]))))])

Fixed submission:
l=input().split();list.sort(l);print(["NO","YES"][l==["5","5","7"]])

Buggy python submission (verdict: Runtime Error):
print(["YES","NO"][bool(len(list(multiset(input.split())-multiset([5,5,7]))))])

Fixed submission:
l=input().split();list.sort(l);print(["NO","YES"][l==["5","5","7"]])

Buggy python submission (verdict: Runtime Error):
print(["YES","NO"][bool(len([set(input.split())-set([5,5,7])]))])

Fixed submission:
l=input().split();list.sort(l);print(["NO","YES"][l==["5","5","7"]])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
enum = enumerate
inf = 1001001002002002002

import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def bye(res):
	sT = "No Yes".split()
	print(sT[res])
	#exit(0)

def sol(N,vA,S):
	sZ = {0,}
	for a,c in zip(vA[::-1],S[::-1]):
		if c=="0":
			sZ |= {a^z for z in sZ}
		elif a not in sZ:
			sZ = set({})
		else:
			pass	# sZ = sZ
		#print(sZ)##
	
	res = 1
	if sZ:
		res = 0
	
	#print(sZ)###
	print(res)


def main():
	T, = linput()
	for _ in "*"*T:
		N, = linput()
		vA = linput()
		S, = linput(str)
		sol(N, vA, S)

def ran():
	#N = 200
	N=8
	vRan = [random.randint(1,10) for _ in "*"*N]
	S = "".join(str(random.randint(0,1)) for _ in "*"*N)
	#print(max(vRan))#
	print(vRan,S)
	sol(N, vRan, S)
	
if __name__ == "__main__":
	main()
	#ran()


Fixed submission:
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
enum = enumerate
inf = 1001001002002002002

import random

def linput(ty=int, cvt=list):
	return cvt(map(ty,input().rstrip().split()))

def vinput(rep=1, ty=int, cvt=list):
	return cvt(ty(input().rstrip()) for _ in "*"*rep)

def gcd(a: int, b: int):
	while b: a, b = b, a%b
	return a

def lcm(a: int, b: int):
	return a * b // gcd(a, b)

def bye(res):
	sT = "No Yes".split()
	print(sT[res])
	#exit(0)

def sol(N,vA,S):
	sZ = set({0,})
	for a,c in zip(vA[::-1],S[::-1]):
		v = a
		for z in reversed(sorted(list(sZ))):
			v = min(v, v^z)
			#if not N: print(z,v)##
		if c=="0":
			sZ |= {v,}
		elif v not in sZ:
			sZ = set({})
			break
		#else:
		#	pass	# sZ = sZ
		#if not N: print(sZ)##
	
	res = 1
	if sZ:
		res = 0
	
	#print(sZ)###
	print(res)


def main():
	T, = linput()
	for _ in "*"*T:
		N, = linput()
		vA = linput()
		S, = linput(str)
		sol(N, vA, S)

def ran():
	N = 200
	#N=6
	vRan = [random.randint(1,10) for _ in "*"*N]
	S = "".join(str(random.randint(0,1)) for _ in "*"*N)
	#print(max(vRan))#
	#vRan = [5, 7, 7, 3, 1, 7]###
	#S = "111000"###
	print(vRan,S)
	sol(N=0, vA=vRan, S=S)
	exit(0)
	
if __name__ == "__main__":
	#ran()
	main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#from collections import deque as dq
input = sys.stdin.readline

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
	#N,A,B = map(int, input().split())
	S = input().rstrip()
	Q = int(input())
	#vA = list(map(int, input().split()))
	#vX = [input().rstrip() for _ in [0,]*N]
	
	rev = 0		# reverse
	
	DF = "" #dq([]) # reversed Head!!
	DR = "" #dq([])
	for q in range(Q):
		tq = input().split()
		if tq[0]=="1":
			rev ^= 1
		else:
			T,F,C = tq
			if F=="1":
				# C to top
				if rev == 0:
					DF += C #DF.appendleft(C) 
				else:
					DR += C #DR.append(C)
			else:
				# C to bottom
				if rev == 0:
					DR += C #DR.append(C)
				else:
					DF += C #DF.appendleft(C)	
	
	
	if rev == False:
		res = DF[::-1] + S + DR
	else:
		res = DR[::-1] + S[::-1] + DF

	print(res)
	
if __name__ == "__main__":
    main()


Fixed submission:
import sys
#from collections import deque as dq
input = sys.stdin.readline

def gcd(a: int, b: int):
    """ https://cocodrips.hateblo.jp/entry/2014/03/05/143623
    """
    while b:
        a, b = b, a%b
    return a

def lcm(a: int, b: int):
    return a * b // gcd(a, b)


def main():
	#N,A,B = map(int, input().split())
	S = input().rstrip()
	Q = int(input())
	#vA = list(map(int, input().split()))
	#vX = [input().rstrip() for _ in [0,]*N]
	
	rev = 0		# reverse
	
	DF = "" #dq([]) # reversed Head!!
	DR = "" #dq([])
	for q in range(Q):
		tq = input().split()
		if tq[0]=="1":
			rev ^= 1
		else:
			T,F,C = tq
			if F=="1":
				# C to top
				if rev == 0:
					DF += C #DF.appendleft(C) 
				else:
					DR += C #DR.append(C)
			else:
				# C to bottom
				if rev == 0:
					DR += C #DR.append(C)
				else:
					DF += C #DF.appendleft(C)	
	
	
	if rev == False:
		res = DF[::-1] + S + DR
	else:
		res = DR[::-1] + S[::-1] + DF

	print(res)
	
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
print("Yes" if sum(a==b,b==c,c==a)==1 else "No")

Fixed submission:
a,b,c=input().split()
print("YNeos"[sum((a==b,b==c,c==a))!=1::2])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
#import bisect
input = sys.stdin.buffer.readline
#lb = bisect.bisect_left

def main():
	H,N=map(int,input().split())
	#vA=list(map(int, input().split()))
	INF = 1001001001
	#H=int(input())
	mAB=[tuple(map(int,input().split())) for _ in [0,]*N]
	
	vN = [INF,]*(H+2)
	vN[0] = 0
	#mD = []
	#apD = mD.append
	#apD(vI)
	
	for h in range(H+2):
		#vN = mD[-1][:]
		for a,b in mAB:
			j = min(h+a,H+1)
			vN[j] = min(vN[h]+b, vN[j])
		#apD(vN)
		
	#res = min(mD[-1][-1],mD[-1][-2])
	res = min(vN[-2:])
	print(res)

main()


Fixed submission:
import sys
#import bisect
input = sys.stdin.buffer.readline
#lb = bisect.bisect_left

def main():
	H,N=map(int,input().split())
	#vA=list(map(int, input().split()))
	INF = 1001001001
	#H=int(input())
	mAB=[tuple(map(int,input().split())) for _ in [0,]*N]
	
	vN = [INF,]*(H+2)
	vN[0] = 0
	#mD = []
	#apD = mD.append
	#apD(vI)
	
	for h in range(H+2):
		#vN = mD[-1][:]
		for a,b in mAB:
			j = min(h+a,H+1)
			vN[j] = min(vN[h]+b, vN[j])
		#apD(vN)
		
	#res = min(mD[-1][-1],mD[-1][-2])
	res = min(vN[-2:])
	print(res)

main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    vA = list(map(int, input().split()))
    MOD = 10**9 + 7
    BMAX = 61

    vC = [0,]*BMAX
    for a in vA:
        d = 0
        while a:
            vC[d] += a&1
            d += 1
            a >>= 1
    res = 0
    for i,c in enumerate(vC):
        x = pow(2,i) * c * (N-c) % MOD
        res = (res + x) % MOD
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    vA = list(map(int, input().split()))
    MOD = 10**9 + 7
    BMAX = 61

    vC = [0,]*BMAX
    for a in vA:
        d = 0
        while a:
            vC[d] += a&1
            d += 1
            a >>= 1
    res = 0
    for i,c in enumerate(vC):
        x = pow(2,i) * c * (N-c) % MOD
        res = (res + x) % MOD
    print(res)


if __name__ == "__main__":
    main()