Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
import numpy as np

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(1, N+1):
  B.append(list(range(math.ceil(i - A[i-1] -0.5), math.ceil(i + A[i-1] + 0.5))))
A = [0] * N
for x in B:
  for n in range(0, N):
    if n + 1 in x:
      A[n] += 1
if K >= 2:
  for i in range(math.ceil(np.log(K))):
    for k in range(1, N+1):
      B[k-1] = list(range(math.ceil(k - A[k-1] -0.5), math.ceil(k + A[k-1] + 0.5)))
    A = [0] * N
    for x in B:
      for n in range(0, N):
        if n + 1 in x:
          A[n] += 1
print(*A) 

Fixed submission:
import sys
 
import numba as nb
import numpy as np
 
input = sys.stdin.readline
 
 
@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A
 
 
def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
 
    ans = solve(N, K, A)
 
    print(" ".join(map(str, ans)))
 
 
if __name__ == "__main__":
    main()

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
for i in range(1, N+1):
  B.append(list(range(math.ceil(i - A[i-1] -0.5), math.ceil(i + A[i-1] + 0.5))))
A = [0] * N
for x in B:
  for n in range(0, N):
    if n + 1 in x:
      A[n] += 1
if K >= 2:
  for i in range(K-1):
    for k in range(1, N+1):
      B[k-1] = list(range(math.ceil(k - A[k-1] -0.5), math.ceil(k + A[k-1] + 0.5)))
    A = [0] * N
    for x in B:
      for n in range(0, N):
        if n + 1 in x:
          A[n] += 1
print(*A)

Fixed submission:
import sys
 
import numba as nb
import numpy as np
 
input = sys.stdin.readline
 
 
@nb.njit("i8[:](i8,i8,i8[:])", cache=True)
def solve(N, K, A):
    for _ in range(min(41, K)):
        A_cumsum = np.zeros(shape=N, dtype=np.int64)
        for i in range(N):
            A_cumsum[max(0, i - A[i])] += 1
            b = i + A[i] + 1
            if N - 1 < b:
                pass
            else:
                A_cumsum[b] -= 1
        A = np.cumsum(A_cumsum)
    return A
 
 
def main():
    N, K = map(int, input().split())
    A = np.array(input().split(), dtype=np.int64)
 
    ans = solve(N, K, A)
 
    print(" ".join(map(str, ans)))
 
 
if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
if s in t and len(t) == len(s)+1:
  print(“Yes”)
else:
  print(“No”)


Fixed submission:
s=input()
t=input()
if s in t[0:len(s)] and len(t) == len(s)+1:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
import math

R = int(input())
ans = R ** 2 math.pi
print(ans)

Fixed submission:
import math
 
R = int(input())
ans = R * 2 * math.pi
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b, c):
  import fractions
  lis = [a, b, c]
  gc = lis[0]
  for i in range(0, 3):
      gc = fractions.gcd(gc, lis[i])
  return gc
def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

Fixed submission:
def gcd(a, b, c):
  x = gcd2(a, b)
  y = gcd2(b, c)
  return gcd2(x, y)

def gcd2(x, y):
    if y == 0:
        return x
    else:
        return gcd2(y,x%y)

def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b, c):
  import fractions
  lis = [a, b, c]
  gc = lis[0]
  for i in range(0, 3):
      gc = fractions.gcd(gc, lis[i])
  return gc
def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()

Fixed submission:
def gcd(a, b, c):
  x = gcd2(a, b)
  y = gcd2(b, c)
  return gcd2(x, y)

def gcd2(x, y):
    if y == 0:
        return x
    else:
        return gcd2(y,x%y)

def main():
  K = int(input())
  ans = 0
  for p in range(1, K+1):
    for s in range(p, K+1):
      for k in range(s, K+1):
        if p == s == k:
          ans += p
        elif p == s or s == k or p == k:
          ans += 3 * gcd(p, s, k)
        else:
          ans += 6 * gcd(p, s, k)
  print(ans)

if __name__=='__main__':
    main()
Buggy python submission (verdict: Runtime Error):
def check(a):
  for i in range(int(len(a)/2)):
    if a[i]!=a[-(i+1)]:
       return False
  return True

S=input()
if kaibun(S):
  a=S[0:int(len(S)/2)]
  b=S[int(len(S)/2)+1:len(S)]
  if kaibun(a) and kaibun(b):
    print('Yes')
  else:
    print('No')
else:
    print('No')

Fixed submission:
def check(a):
  for i in range(int(len(a)/2)):
    if a[i]!=a[-(i+1)]:
       return False
  return True
 
S=input()
if check(S):
  a=S[0:int(len(S)/2)]
  b=S[int(len(S)/2)+1:len(S)]
  if check(a) and check(b):
    print('Yes')
  else:
    print('No')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
lis = {}
if N == 1:
  s, c = map(int, input().split())
  print(c)
  exit()
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  if s in lis:
    if lis[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    lis[s] = c
if not 1 in lis:
  lis[1] = 1
for i in range(2, N+1):
  if not i in lis:
    lis[i] = 0
ans = ""
for i in range(1, N+1):
  ans += str(lis[i])
print(ans)

Fixed submission:
N, M = map(int, input().split())
lis = {}
if N == 1 and M == 0:
  print(0)
  exit()
if N == 2 and M == 0:
  print(10)
  exit()
if N == 3 and M == 0:
  print(100)
  exit()
if N == 1 and M == 1:
  s, c = map(int, input().split())
  print(c)
  exit()
for i in range(M):
  s, c = map(int, input().split())
  if s == 1 and c == 0:
    print(-1)
    exit()
  if s in lis:
    if lis[s] == c:
      continue
    else:
      print(-1)
      exit()
  else:
    lis[s] = c
if not 1 in lis:
  lis[1] = 1
for i in range(2, N+1):
  if not i in lis:
    lis[i] = 0
ans = ""
for i in range(1, N+1):
  ans += str(lis[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input.split()))
ans = True
for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 or A[i] % 5 != 0:
      ans = False
if ans:
  print("APPROVED")
else:
  print("DENIED")

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
ans = True
for i in range(N):
  if A[i] % 2 == 0:
    if A[i] % 3 != 0 and A[i] % 5 != 0:
      ans = False
if ans:
  print("APPROVED")
else:
  print("DENIED")
Buggy python submission (verdict: Runtime Error):
def check(seq):
    return len(seq) != len(set(seq))

def main():
  N = int(input())
  A = list(map(int, input.split()))
  ans = check(A)
  if ans:
    print("NO")
  else:
    print("Yes")
main()

Fixed submission:
def check(seq):
    return len(seq) != len(set(seq))

def main():
  N = int(input())
  A = list(map(int, input().split()))
  ans = check(A)
  if ans:
    print("NO")
  else:
    print("YES")
main()
Buggy python submission (verdict: Runtime Error):
H, A = map(int, input.split())
ans = H // A
if H % A != 0:
  ans = ans + 1
print(ans)

Fixed submission:
H, A = map(int, input().split())
ans = H // A
if H % A != 0:
  ans = ans + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
alphabet = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
alphabet2 = ["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"]
N = int(input())
S = list(input())
import math
i = 0
max = N-2
roop = True
while roop == True:
  if i+1 > len(S)-1:
    roop = False
  elif S[i] == S[i+1]:
    del S[i]
    max -= 1
  else:
    i += 1
print(len(S))

Fixed submission:
N = int(input())
S = list(input())
A = [0] * N
same = False
import math
for i in range(1, N):
  if S[i] == S[i-1]:
    same = True
  elif same and S[i] != S[i-1]:
    A[i] = 1
    same = False
  else:
    same = False
    A[i] = 1
    
print(sum(A)+1)

Buggy python submission (verdict: Time Limit Exceeded):
alphabet = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
alphabet2 = ["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"]
N = int(input())
S = input()
import math
for k in range(math.ceil(N/2)):
  for i in alphabet:
    if i in S:
      x = alphabet.index(i)
      S = S.replace(i, alphabet2[x])
print(len(S))

Fixed submission:
N = int(input())
S = list(input())
A = [0] * N
same = False
import math
for i in range(1, N):
  if S[i] == S[i-1]:
    same = True
  elif same and S[i] != S[i-1]:
    A[i] = 1
    same = False
  else:
    same = False
    A[i] = 1
    
print(sum(A)+1)

Buggy python submission (verdict: Time Limit Exceeded):
alphabet = ["aa","bb","cc","dd","ee","ff","gg","hh","ii","jj","kk","ll","mm","nn","oo","pp","qq","rr","ss","tt","uu","vv","ww","xx","yy","zz"]
alphabet2 = ["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"]
N = int(input())
S = input()
import math
for k in range(math.ceil(N/2)):
  for i in alphabet:
    if i in S:
      x = alphabet.index(i)
      S = S.replace(i, alphabet2[x])
print(len(S))

Fixed submission:
N = int(input())
S = list(input())
A = [0] * N
same = False
import math
for i in range(1, N):
  if S[i] == S[i-1]:
    same = True
  elif same and S[i] != S[i-1]:
    A[i] = 1
    same = False
  else:
    same = False
    A[i] = 1
    
print(sum(A)+1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
lis = [0] * N
for i in range(1, N+1):
  x = A.index(i)
  lis[i-1] = str(x+1)
ans = " ".join(lis)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
lis = [0] * N
k = 1
for i in A:
  lis[i-1] = k
  k += 1
lis = map(str, lis)
ans = " ".join(lis)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
lis = [0] * N
for i in range(1, N+1):
  x = A.index(i)
  lis[i-1] = x+1
lis = map(str, lis)
ans = " ".join(lis)
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
lis = [0] * N
k = 1
for i in A:
  lis[i-1] = k
  k += 1
lis = map(str, lis)
ans = " ".join(lis)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())
import sys
input = sys.stdin.readline
A = [K] * N
def calc(n):
  return n-1
for i in range(Q):
  M = int(input().rstrip())
  A = list(map(calc, A))
  A[M-1] += 1
for k in A:
  if k <= 0:
    print("No")
  else:
    print("Yes")

Fixed submission:
N, K, Q = map(int, input().split())
import sys
input = sys.stdin.readline
A = [0] * N
for i in range(Q):
  s = int(input().rstrip())
  A[s-1] += 1
for k in A:
  if K - (Q - k) >= 1:
    print("Yes")
  else:
    print("No")
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()
ans = 0
for i in range(N):
  if S[i] == T[i]:
    ans +=1
print(ans)

Fixed submission:
S = input()
T = input()
ans = 0
for i in range(3):
  if S[i] == T[i]:
    ans +=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N == 2:
  print(sum(A)/2)
else:
  temp = (A[0]+A[1])/2
  for i in range(2, N):
    temp = 1/2*(A[i] + temp)
print(temp)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
if N == 2:
  print(sum(A)/2)
  exit()
else:
  temp = (A[0]+A[1])/2
  for i in range(2, N):
    temp = 1/2*(A[i] + temp)
print(temp)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
lis = []
N = int(input().rstrip())
for i in range(N):
  str = input().rstrip()
  counter = {}
  for c in str:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1
  lis.append(counter)
count = 0
for i in range(N):
  for j in range(i+1, N):
    if lis[i] == lis[j]:
      count += 1
print(count)

Fixed submission:
import sys
input = sys.stdin.readline
lis = {}
counter = 0
N = int(input().rstrip())
for i in range(N):
  str = "".join(sorted(list(input().rstrip())))
  if str in lis:
    lis[str] += 1
    counter += lis[str]
  else:
    lis[str] = 0
print(counter)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import sys
input = sys.stdin.readline
lis = []
N = int(input().rstrip())
for i in range(N):
  str = input().rstrip()
  counter = {}
  for c in str:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1
  lis.append(counter)
count = 0
for i in range(N):
  for j in range(i+1, N):
    if lis[i] == lis[j]:
      count += 1
print(count)

Fixed submission:
import sys
input = sys.stdin.readline
lis = {}
counter = 0
N = int(input().rstrip())
for i in range(N):
  str = "".join(sorted(list(input().rstrip())))
  if str in lis:
    lis[str] += 1
    counter += lis[str]
  else:
    lis[str] = 0
print(counter)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int, input().split()))
ans = True
lis = {}
for i in H:
  if i in lis:
    lis[i] += 1
  else:
    lis[i] = 1
mine = min(H)
times = lis[mine]
for i in range(N):
  if mine < H[i]-1:
    ans = False
    break
  else:
    if H[i] == mine:
      times -= 1
    if times == 0 and i != N-1:
      del lis[mine]
      lis = sorted(lis)
      mine = next(iter(lis))
      times = lis[next(iter(lis))]
if ans:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.reverse()
ans = "Yes"
for i in range(N-1):
  if A[i] >= A[i+1]:
    continue
  elif A[i] == A[i+1] - 1:
    A[i+1] = A[i]
  else:
    ans = "No"
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
H = list(map(int, input().split()))
ans = True
for i in range(N):
  if min(H) < H[i]-1:
    ans = False
    break
  else:
    H[i] = 10**10
if ans:
  print("Yes")
else:
  print("No")

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.reverse()
ans = "Yes"
for i in range(N-1):
  if A[i] >= A[i+1]:
    continue
  elif A[i] == A[i+1] - 1:
    A[i+1] = A[i]
  else:
    ans = "No"
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
B = sorted(set(A), key = A.index)
B = sorted(B, reverse = True)
max_A = B[0]
try:
  second_max = B[1]
except:
  second_max = B[0]
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)

Fixed submission:
N = int(input())
A = []
import sys
input = sys.stdin.readline
for i in range(N):
  A.append(int(input().rstrip()))
from collections import Counter
counter = Counter(A)
max_A = max(A)
#B = sorted(set(A), key = A.index)
#B = sorted(B, reverse = True)
#max_A = B[0]
try:
  second_max = sorted(set(A))[-2]
except:
  second_max = max_A
j = False
if counter[max_A] >= 2:
  j = True
for i in range(N):
  if A[i] == max_A and j == False:
    print(second_max)
  else:
    print(max_A)
Buggy python submission (verdict: Runtime Error):
N, L = map(int, input().split())
A = []
for i in range(N):
  A.append(L+i)
i = 0
for k in A:
  if i == 0:
    x = 0
  else:
    x, y = abs(i), -abs(i)
  i += 1
  for 
  

Fixed submission:
N, L = map(int, input().split())
A = []
for i in range(N):
  A.append(L+i)
i = 0
ans = False
while ans == False:
    x, y = abs(i), -abs(i)
    for k in A:
      if k == x or k == y:
        ans = True
        A.remove(k)
    i += 1
print(sum(A))
Buggy python submission (verdict: Runtime Error):
W, H, x, y = map(int, input().split())
ans1 = W * H / 2
cen_x, cen_y = W/2, H/2
if cen_x == x and cen_y == y:
  ans2 = 1
else:
  ans2 = 0
print(ans1 + " " + ans2)


Fixed submission:
W, H, x, y = map(int, input().split())
ans1 = W * H / 2
cen_x, cen_y = W/2, H/2
if cen_x == x and cen_y == y:
  ans2 = 1
else:
  ans2 = 0
print(str(ans1) + " " + str(ans2))
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
l, r = map(int, input().split())
s = set(list(range(l, r+1)))
for i in range(1, M):
  l, r = map(int, input().split())
  s1 = set(list(range(l, r+1)))
  s = s & s1
print(len(s))

Fixed submission:
N, M = map(int, input().split())
L_lis = []
R_lis = []
for i in range(M):
  L, R = map(int, input().split())
  L_lis.append(L)
  R_lis.append(R)
new_L, new_R = max(L_lis), min(R_lis)
if new_L <= new_R:
  print(new_R - new_L + 1)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
# author:  Taichicchi
# created: 15.09.2020 21:11:53

import sys

N = int(input())
ans = ''
while N > 0:
N -= 1
ans += chr(ord('a') + N % 26)
N //= 26
print(ans[::-1])


Fixed submission:
# author:  Taichicchi
# created: 15.09.2020 21:11:53

import sys

N = int(input())
ans = ''
while N > 0:
    N -= 1
    ans += chr(ord('a') + N % 26)
    N //= 26
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

res = 1

for a in A:
    res *= a

if res > 10 ** 18:
    res = -1

print(res)

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

A.sort()


res = 1
for a in A:
    res *= a
    if res > 10 ** 18:
        res = -1
        break

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

H = list(map(int, input().split()))

ls = []

res = []

for m in range(M):
    ls.append(list(map(int, input().split())))

for n in range(N):
    tmp_res = 1
    for l in ls:
        if n + 1 in l:
            if n + 1 == l[0]:
                if H[n] <= H[l[1] - 1]:
                    tmp_res = 0
            else:
                if H[n] <= H[l[0] - 1]:
                    tmp_res = 0
    res.append(tmp_res)


print(sum(res))

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

H = list(map(int, input().split()))

ls = [1 for _ in range(N)]

for m in range(M):
    A, B = map(int, input().split())

    if ls[A - 1]: 
        ls[A - 1] = 0
        if H[A - 1] > H[B - 1]:
            ls[A - 1] = 1

    if ls[B - 1]: 
        ls[B - 1] = 0
        if H[B - 1] > H[A - 1]:
            ls[B - 1] = 1


print(sum(ls))
Buggy python submission (verdict: Time Limit Exceeded):
# author:  Taichicchi
# created: 19.09.2020 00:14:21

import sys

N = int(input())

S = input()

ans = S.count("R") * S.count("G") * S.count("B")


for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if j - i == k - j:
                if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]):
                    ans -= 1

print(ans)


Fixed submission:
# author:  Taichicchi
# created: 19.09.2020 00:14:21

import sys

N = int(input())

S = input()

ans = S.count("R") * S.count("G") * S.count("B")


for i in range(N - 2):
    for j in range(i + 1, N - 1):
        try:
            k = 2 * j - i
            if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]):
                ans -= 1
        except:
            continue

print(ans)

Buggy python submission (verdict: Runtime Error):
# author:  Taichicchi
# created: 19.09.2020 00:14:21

from collections import Counter
import sys
from math import prod

N = int(input())

S = input()


c = Counter(S)

ans = prod(list(c.values()))

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if j - i == k - j:
                if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]):
                    ans -= 1

print(ans)


Fixed submission:
# author:  Taichicchi
# created: 19.09.2020 00:14:21

import sys

N = int(input())

S = input()

ans = S.count("R") * S.count("G") * S.count("B")


for i in range(N - 2):
    for j in range(i + 1, N - 1):
        try:
            k = 2 * j - i
            if (S[i] != S[j]) & (S[j] != S[k]) & (S[k] != S[i]):
                ans -= 1
        except:
            continue

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            S = query[2] + S
        else:
            S = S + query[2]

if rev:
    print(S[::-1])
else:
    print(S)


Fixed submission:
# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

front = []
end = []

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            front.append(query[2])
        else:
            end.append(query[2])

front = "".join(front)
end = "".join(end)


if rev:
    print(end[::-1] + S[::-1] + front)
else:
    print(front[::-1] + S + end)

Buggy python submission (verdict: Time Limit Exceeded):
# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            S = query[2] + S
        else:
            S = S + query[2]

if rev:
    print(S[::-1])
else:
    print(S)


Fixed submission:
# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

front = []
end = []

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            front.append(query[2])
        else:
            end.append(query[2])

front = "".join(front)
end = "".join(end)


if rev:
    print(end[::-1] + S[::-1] + front)
else:
    print(front[::-1] + S + end)