Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import random

n = int(input())
a = [int(i) for i in input().split()]

for j in range(100000):
	chk = 0
	for i in range(n-1): 
		if a[i] == a[i-1] ^ a[i+1]:
			chk += 1
		else:
			break			
	if a[n-1] == a[n-2] ^ a[0]:
		chk += 1
	if chk == n:
		print("Yes")	
		break
	else:
		random.shuffle(a)
if j == 99999:
	print("No")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import random

n = int(input())
a = [int(i) for i in input().split()]

for j in range(100000):
	chk = 0
	for i in range(n-1): 
		if a[i] == a[i-1] ^ a[i+1]:
			chk += 1
	if a[n-1] == a[n-2] ^ a[0]:
		chk += 1
	if chk == n:
		print("Yes")	
		break
	else:
		random.shuffle(a)
if j == 99999:
	print("No")

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a_uni = list(set(a))
if len(a_uni) == 1:
	if a[0] == 0:
		print("Yes")
	else:
		print("No")
elif n%3 != 0:
	print("No")
elif len(a_uni) == 2:
	if a.count(0) == n/3:
		print("Yes")	
	else:
		print("No")	
elif len(a_uni) == 3:
	if a_uni[0]^a_uni[1]!=a_uni[2]:
		print("No")
	elif a.count(a_uni[0])==n/3 and a.count(a_uni[1])==n/3:
		print("Yes")
	else:
		print("No")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
if n*a < b
	print (n*a)
else: 
	print (b)

Fixed submission:
n, a, b = map(int, input().split())
if n*a < b:
	print (n*a)
else: 
	print (b)

Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, input().split())
if n*a < b
	print n*a
else: 
	print b

Fixed submission:
n, a, b = map(int, input().split())
if n*a < b:
	print (n*a)
else: 
	print (b)
Buggy python submission (verdict: Runtime Error):
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-pont[j][k])**2
		if isinstance(a**0.5, int) 
		m += 1
print(m)

Fixed submission:
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-point[j][k])**2
		b = a**(1/2)
		if b.is_integer():
			m += 1
print(m)

Buggy python submission (verdict: Runtime Error):
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for n in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-pont[j][k])**2
		if isinstance(a ** 0.5, int) 
		m += 1
print(m)

Fixed submission:
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-point[j][k])**2
		b = a**(1/2)
		if b.is_integer():
			m += 1
print(m)

Buggy python submission (verdict: Runtime Error):
#入力
n, d = map(int, input().split())
point = [int(input()) for i in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-pont[j][k])**2
		if isinstance(a ** 0.5, int) 
		m += 0
print(m)

Fixed submission:
#入力
n, d = map(int, input().split())
point = [[int(i) for i in input().split()] for j in range(n)]
#点1から計算する
m = 0
for i in range(n):
	for j in range(i+1,n):
		a = 0
		for k in range(d):
			a += (point[i][k]-point[j][k])**2
		b = a**(1/2)
		if b.is_integer():
			m += 1
print(m)
Buggy python submission (verdict: Runtime Error):
today = input()
weather = ["Sunny", "Cloudy", "Rainy"]
i = 0
for v in weather:
  if today == v:
    print(weather[(i+1)%3+1])
  i += 1

Fixed submission:
today = input()
weather = ["Sunny", "Cloudy", "Rainy"]
i = 0
for v in weather:
  if today == v:
    print(weather[(i+1)%3])
  i += 1
Buggy python submission (verdict: Runtime Error):
N = float(input())
EBTC = 380000.0
R = 0
for i in range(N):
    t = [x for x in input().split()]
    R = R + float(t[0]) if t[1]=="JPY" else R + float(t[0])*EBTC
print(int(R))

Fixed submission:
N = int(input())
EBTC = 380000.0
R = 0
for i in range(N):
    t = [x for x in input().split()]
    R = R + float(t[0]) if t[1]=="JPY" else R + float(t[0])*EBTC
print(R)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v & 1 == 0:
        v = v << 2
        d += 1
    DA.append(d)

print(min(DA))


Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

DA = []
for v in A:
    d = 0
    while v%2 == 0:
        v //= 2
        d += 1
    DA.append(d)

print(min(DA))
Buggy python submission (verdict: Runtime Error):
r = input()
print(3 * r * r)


Fixed submission:
r = int(input())
print(3 * r * r)

Buggy python submission (verdict: Runtime Error):
r = input()
print(2 * r * r)


Fixed submission:
r = int(input())
print(3 * r * r)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
S = input()
S[K-1] = S[K-1].lower()
print(S)

Fixed submission:
N, K = map(int, input().split())
S = input()
S = S[0:K-1] + S[K-1].lower() + S[K:]
print(S)
Buggy python submission (verdict: Runtime Error):
N, K = int(input())

print(N-K+1)

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

print(N-K+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))


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


gcds = []
for i in range(N):
    m = A[0] if i != 0 else A[1]
    for j in range(N):
        if i == j:
            continue
        m = gcd(m, A[j])
    gcds.append(m)

max_gcd = 1
for i in range(N):
    max_gcd = max(max_gcd, max(gcd(A[i], gcds[i]), gcds[i]))

print(max_gcd)


Fixed submission:
from itertools import *
import fractions

N = int(input())
A = list(map(int, input().split()))

L = list(accumulate([0]+A, fractions.gcd))
R = list(accumulate([0]+A[::-1], fractions.gcd))

print(max(fractions.gcd(s, t) for s, t in zip(L, R[::-1][1:])))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

MAX_A = 10**9

num = 1

for i in range(max(A), 1, -1):
    c = 0
    for j in range(N):
        if A[j] % i == 0:
            c += 1
    if c == N:
        num = i
        break
    elif c == N-1:
        num = i
        break


print(num)


Fixed submission:
from itertools import *
import fractions

N = int(input())
A = list(map(int, input().split()))

L = list(accumulate([0]+A, fractions.gcd))
R = list(accumulate([0]+A[::-1], fractions.gcd))

print(max(fractions.gcd(s, t) for s, t in zip(L, R[::-1][1:])))
Buggy python submission (verdict: Runtime Error):
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC = []
for i in range(X):
    for j in range(Y):
        if i + 1 + j + 1 > K:
            break
        for k in range(Z):
            if i + 1 + j + 1 + k + 1 > K:
                break
            ABC.append(A[i] + B[j] + C[k])

ABC.sort(reverse=True)
for i in range(K):
    print(ABC[i])


Fixed submission:

list = []
for i in range(6):
    a = int(input())
    list.append(a)

flag = False
for i in range(5):
    for j in range(i+1, 5):
        if list[j] - list[i] > list[5]:
            flag = True

if flag:
    print(':(')
else:
    print('Yay!')
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

result = A
for i in range(A+1, B+1):
    result = result ^ i

print(result)


Fixed submission:
A, B = map(int, input().split())


def f(a):
    if a % 2 == 0:
        return 0^a if (a // 2) % 2 == 0 else 1^a
    else:
        return 0 if ((a+1) // 2) % 2 == 0 else 1

print(f(B)^f(A-1))
Buggy python submission (verdict: Runtime Error):
import copy
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)


class UnionFind:
    def __init__(self, n):
        self.Parent = [-1 for i in range(N)]

    def root(self, x):
        if self.Parent[x] < 0:
            return x
        self.Parent[x] = self.root(self.Parent[x])
        return copy.deepcopy(self.Parent[x])

    def size(self, x):
        return -copy.deepcopy(self.Parent[self.root(x)])

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size(x) < self.size(y):
            x, y = y, x
        self.Parent[x] += self.deepcopy(self.Parent[y])
        self.Parent[y] = x
        return True


ans = [0 for i in range(M)]
ans[M - 1] = N * (N - 1) / 2
unif = UnionFind(N)

for i in range(M-1, 1, -1):
    ans[i - 1] = ans[i]
    if unif.root(A[i]) != unif.root(B[i]):
        ans[i - 1] -= unif.size(A[i]) * unif.size(B[i])
        unif.connect(A[i], B[i])

for i in range(M):
    print(int(ans[i]))


Fixed submission:
import copy
N, M = map(int, input().split())
A = []
B = []
for i in range(M):
    a, b = map(int, input().split())
    A.append(a - 1)
    B.append(b - 1)


class UnionFind:
    def __init__(self, n):
        self.Parent = [-1 for i in range(N)]

    def root(self, x):
        if self.Parent[x] < 0:
            return x
        self.Parent[x] = self.root(self.Parent[x])
        return copy.deepcopy(self.Parent[x])

    def size(self, x):
        return -copy.deepcopy(self.Parent[self.root(x)])

    def connect(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.size(x) < self.size(y):
            x, y = y, x
        self.Parent[x] += copy.deepcopy(self.Parent[y])
        self.Parent[y] = x
        return True


ans = [0 for i in range(M)]
ans[M - 1] = N * (N - 1) / 2
unif = UnionFind(N)

for i in range(M-1, 0, -1):
    ans[i - 1] = ans[i]
    if unif.root(A[i]) != unif.root(B[i]):
        ans[i - 1] -= unif.size(A[i]) * unif.size(B[i])
        unif.connect(A[i], B[i])

for i in range(M):
    print(int(ans[i]))
Buggy python submission (verdict: Runtime Error):
import numpy as np

N = int(input())
a = []
for i in range(N):
    a.append(int(input()))

mean = np.mean(a)

idx = np.abs(np.asarray(a) - mean).argmin()

print(idx)



Fixed submission:
import numpy as np

N = int(input())
a = [int(i) for i in input().split()]

mean = np.mean(a)

idx = np.abs(np.asarray(a) - mean).argmin()

print(idx)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
t = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != c and t[s] != -1:
        print(-1)
        exit()
    t[s] = c

if n != 1:
    if t[0] == 0:
        print(-1)
        exit()
    for i in range(m):
        if t[i] == -1:
            t[i] = 0
    else:
        if t[0] == -1:
            t[0] = 0

print(''.join(map(str, t)))

Fixed submission:
n, m = map(int, input().split())
t = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c

if n != 1:
    if t[0] == 0:
        print(-1)
        exit()
    if t[0] == -1:
        t[0] = 1
    for i in range(n):
        if t[i] == -1:
            t[i] = 0
else:
    if t[0] == -1:
        t[0] = 0
    
print(''.join(map(str, t)))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
t = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != c and t[s] != -1:
        print(-1)
        exit()
    t[s] = c

if n != 1:
    if t[0] == 0:
        print(-1)
        exit()
    for i in range(m):
        if t[i] == -1:
            t[i] = 0
    else:
        if t[0] == -1:
            t[0] = 0

print(''.join(map(str, t)))

Fixed submission:
n, m = map(int, input().split())
t = [-1] * n
for _ in range(m):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c

if n != 1:
    if t[0] == 0:
        print(-1)
        exit()
    if t[0] == -1:
        t[0] = 1
    for i in range(n):
        if t[i] == -1:
            t[i] = 0
else:
    if t[0] == -1:
        t[0] = 0
    
print(''.join(map(str, t)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
j = 1
count = 0

for i in range(0,n):
    if p[j] >= p[i]:
        print(p[j-1])
        count += 1

print(count)

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
count = 0
min = p[0]

for i in range(n):
    if min >= p[i]:
        count += 1
        min = p[i]

print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0


for i in range(n-2):
    if s[i:i+3] == "ABC":
        res += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

print(s.count('ABC'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0


for i in range(n-2):
    if s[i:i+3] == "ABC":
        res += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

print(s.count('ABC'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
 s = input()
 ans = 0
 for i in range(n - 2):
     if s[i:i+3] == 'ABC':
         ans += 1 
 print(ans) 

Fixed submission:
n = int(input())
s = input()

print(s.count('ABC'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0


for i in range(n):
    if s[i:i+3] == 'ABC':
        res += 1

print(ans)

Fixed submission:
n = int(input())
s = input()

print(s.count('ABC'))

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
i = 0
count = 0

while i < n:
    if s[i] == 'A':
        if s[i+1] == 'B':
            if s[i+2] == 'C':
                count += 1
                i += 2
    i += 1

print(count)

Fixed submission:
n = int(input())
s = input()

print(s.count('ABC'))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np;
count = 0;
maxnum=0;
n,m = input().split();
mark=np.zeros(int(n));
s = input();

for j in range(len(s)):
    for i in range(int(n)-1):
        if(s[i]=='A' and s[i+1] == 'C'):
            mark[i] = 1;
for j in range(int(m)): 
    x,y = input().split();
    print(int(np.sum(mark[(int(x)-1):int(y)-1])))

Fixed submission:
import numpy as np;
count = 0;
maxnum=0;
n,m = input().split();
mark=np.zeros(int(n));
s = input();

for i in range(1,int(n)):
    if(s[i]=='C' and s[i-1] == 'A'):
        count= count +1;
    mark[i] = count;
for j in range(int(m)): 
    x,y = input().split();
    print(int(mark[int(y)-1])-int(mark[int(x)-1]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 20:23:42 2019

@author: SCREAM
"""

count = 0;
maxnum=0;
n,m = input().split();

s = input();




for j in range(int(m)):
    x,y = input().split();
    i =int(x)-1
    while(i<int(y)-1):
        if(s[i]=='A' and s[i+1] == 'C'):
            count = count +1;
            i = i+2;
        else:
            i = i+1;
    print(count);  
    count = 0;
   
        

    


Fixed submission:
import numpy as np;
count = 0;
maxnum=0;
n,m = input().split();
mark=np.zeros(int(n));
s = input();

for i in range(1,int(n)):
    if(s[i]=='C' and s[i-1] == 'A'):
        count= count +1;
    mark[i] = count;
for j in range(int(m)): 
    x,y = input().split();
    print(int(mark[int(y)-1])-int(mark[int(x)-1]))

Buggy python submission (verdict: Time Limit Exceeded):

count = 0;
maxnum=0;
n,m = input().split();

s = input();




for j in range(int(m)):
    x,y = input().split();
    for i in range(int(x)-1,int(y)-1):
        if(s[i]=='A' and s[i+1] == 'C'):
            count = count +1;
    print(count);  
    count = 0;
   

Fixed submission:
import numpy as np;
count = 0;
maxnum=0;
n,m = input().split();
mark=np.zeros(int(n));
s = input();

for i in range(1,int(n)):
    if(s[i]=='C' and s[i-1] == 'A'):
        count= count +1;
    mark[i] = count;
for j in range(int(m)): 
    x,y = input().split();
    print(int(mark[int(y)-1])-int(mark[int(x)-1]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
t = input()

if s == t:
    print(n)
    return

r = 0
for i in range(0, n):
    if s[-(i + 1)] != t[i]:
        break
    r += 1

print((n * 2) - r)


Fixed submission:
n = int(input())
s = input()
t = input()

r = n
for i in range(0, n):
    if s[i:] == t[:(n-i)]:
            break
    r += 1

print(r)
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

L = int(input())
#print(L)

a0 = math.floor(L/2)
#print(a0)

cand = []

if a0==1:
  b0 = -2*a0 + L
  cand.append(a0*b0*a0)
else:
  x = np.arange(0.1, a0, 0.001)
  for i in x:
    b0 = -2*i + L
    cand.append(i*b0*i)

cand_np = np.array(cand)
print(cand_np.max())


Fixed submission:
import math
import numpy as np

L = int(input())
a0 = L/3

print(a0*a0*a0)

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

L = int(input())
#print(L)

a0 = math.floor(L/2)
#print(a0)

cand = []

if a0==1:
  b0 = -2*a0 + L
  cand.append(a0*b0*a0)
else:
  x = np.arange(0.1, a0, 0.1)
  for i in x:
    b0 = -2*i + L
    cand.append(i*b0*i)

cand_np = np.array(cand)
print(cand_np.max())


Fixed submission:
import math
import numpy as np

L = int(input())
a0 = L/3

print(a0*a0*a0)

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np

L = int(input())
#print(L)

a0 = math.floor(L/2)
#print(a0)

cand = []

if a0==1:
  b0 = -2*a0 + L
  cand.append(a0*b0*a0)
else:
  for i in range(1,a0):
    b0 = -2*i + L
    cand.append(i*b0*i)

cand_np = np.array(cand)
print(cand_np.max())


Fixed submission:
import math
import numpy as np

L = int(input())
a0 = L/3

print(a0*a0*a0)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
s = input()
s1 = int(s[0])
s2 = int(s[1])
s3 = int(s[2])

if s1==s2:
	if s1==s3:
		print("No")
	else:
		print("Yes")
else:
	print("Yes")


Fixed submission:
# -*- coding: utf-8 -*-
s = input()
s1 = s[0]
s2 = s[1]
s3 = s[2]

if s1==s2:
	if s1==s3:
		print("No")
	else:
		print("Yes")
else:
	print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

S = input()
Q = int(input())
rev_flg = False

for i in range(Q):
  q = input().split(" ")
  if len(q)==1:
    # T=1のときは文字列を反転する
    rev_flg = not(rev_flg)
  if len(q)==3:
    # print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      if rev_flg==False:
      	S = q[2] + S
      else:
        S = S + q[2]
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      if rev_flg==False:
        S = S + q[2]
      else:
        S = q[2] + S
  
if rev_flg==True:
  print(S[::-1])
else:
  print(S)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque

S = input()
Q = int(input())
rev_flg = False

output = deque()
output.append(S)

for i in range(Q):
  q = input().split(" ")
  if len(q)==1:
    # T=1のときは文字列を反転する
    rev_flg = not(rev_flg)
    # print(rev_flg)
  if len(q)==3:
    # print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      if rev_flg==False:
        output.appendleft(q[2])
      else:
        output.append(q[2])
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      if rev_flg==False:
        # S = S + q[2]
        output.append(q[2])
      else:
        # S = q[2] + S
        output.appendleft(q[2])
  
output_s = "".join(list(output))

if rev_flg==True:
  print(output_s[::-1])
  #print(S[::-1])
else:
  #print(S)
  print(output_s)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import sys

S = input()
Q = int(input())

input_val = []
for i in range(Q):
  q = input().split(" ")
  input_val.append(q)
  
#print(input_val)
output = ""
for q in input_val:
  if len(q)==1:
    #print("T=1, S=",S)
    # T=1のときは文字列を反転する
    S = S[::-1]
    #print(S)
  if len(q)==3:
    #print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      #print("F=1, S:",S,"q[2]:",q[2])
      S = q[2] + S 
      #print(S)
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      #print("F=2, S:",S,"q[2]:",q[2])
      S = S + q[2]
      #print(S)
  #print(q)
  
print(S)

Fixed submission:
# -*- coding: utf-8 -*-
import sys
from collections import deque

S = input()
Q = int(input())
rev_flg = False

output = deque()
output.append(S)

for i in range(Q):
  q = input().split(" ")
  if len(q)==1:
    # T=1のときは文字列を反転する
    rev_flg = not(rev_flg)
    # print(rev_flg)
  if len(q)==3:
    # print("T=2, S=",S)
    # T=2のときは
    # F=1なら先頭に文字列Cを追加
    if int(q[1])==1:
      if rev_flg==False:
        output.appendleft(q[2])
      else:
        output.append(q[2])
    # F=2なら最後に文字列を追加
    if int(q[1])==2:
      if rev_flg==False:
        # S = S + q[2]
        output.append(q[2])
      else:
        # S = q[2] + S
        output.appendleft(q[2])
  
output_s = "".join(list(output))

if rev_flg==True:
  print(output_s[::-1])
  #print(S[::-1])
else:
  #print(S)
  print(output_s)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())
tmp = max(A, B)
flag = True
for i in range(tmp):
    if abs(i - A) == abs(i - B):
        print(i)
        flag = False

if flag == True:
    print("IMPOSSIBLE")

Fixed submission:
A, B = map(int, input().split())
K = int((A + B) / 2)
if abs(K - A) == abs(K - B):
    print(K)
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in range(0,n):
    dist.append(int(d[i]))

ex = dist[0] + k - dist[n-1]
res = k - ex

for i in range(1, n):
 	diff = dist[i] - dist[i-1]
    aux = res + ex - diff
    
    if aux < res:
        res = aux
        
	ex = diff

print(str(res))

Fixed submission:
s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in d:
    dist.append(int(i))

res = dist[n-1] - dist[0]

for i in range(1, n):
    diff = dist[i] - dist[i-1]
    aux = k - diff
    if aux < res:
        res = aux

print(str(res))