Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
result=0
for i in range(N):
    result+=i

print(result)

Fixed submission:
N=int(input())

result=(N-1)*(N)//2
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

ans=0
result=[]
for i in range(N):
    s= ''.join(sorted(input()))
    ans+=result.count(s)
    result.append(s)
print(ans)

Fixed submission:
import collections as cl
import math
N=int(input())

result_=[]
for i in range(N):
    s= ''.join(sorted(input()))
    result_.append(s)

result=list(cl.Counter(result_).values())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
for j in range(len(result)):
    if result[j]==1:
        continue
    else:
        ans+=combinations_count(result[j],2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s_=[ ''.join(sorted(input())) for i in range(N)]
s_.sort()

ans=0
result=[]
for i in range(N):
    s=s_[i]
    ans+=result.count(s)
    result.append(s)
print(ans)

Fixed submission:
import collections as cl
import math
N=int(input())

result_=[]
for i in range(N):
    s= ''.join(sorted(input()))
    result_.append(s)

result=list(cl.Counter(result_).values())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
for j in range(len(result)):
    if result[j]==1:
        continue
    else:
        ans+=combinations_count(result[j],2)

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
N=int(input())
s_=[sorted(input()) for i in range(N)]
s_.sort()

l=0
r=1
ans=0
while r < N:
    if s_[l]==s_[r]:
        ans+=math.factorial(r-l)
        r+=1
    else:
        l+=r
        r+=1

print(ans)

Fixed submission:
import collections as cl
import math
N=int(input())

result_=[]
for i in range(N):
    s= ''.join(sorted(input()))
    result_.append(s)

result=list(cl.Counter(result_).values())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
for j in range(len(result)):
    if result[j]==1:
        continue
    else:
        ans+=combinations_count(result[j],2)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections as cl
N=int(input())
s_=[sorted(input()) for i in range(N)]

ans=0
result_=[]
for j in range(N):
    cnt=cl.Counter(s_[j]).items()
    for l in range(j):
        if cnt==result_[l]:
            ans+=1
        else:
            ans+=0

    result_.append(cnt)
print(ans)

Fixed submission:
import collections as cl
import math
N=int(input())

result_=[]
for i in range(N):
    s= ''.join(sorted(input()))
    result_.append(s)

result=list(cl.Counter(result_).values())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

ans=0
for j in range(len(result)):
    if result[j]==1:
        continue
    else:
        ans+=combinations_count(result[j],2)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

max_number = max(a)

for i in range(n):
    if a[i] == max_number:
        print(max(a[0:i]+a[i+1:]))
    else:
        print(max_number)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]

for i in range(n):
    result = max(a[0:i:]+a[i+1:])
    print(result)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]

max_number = max(a)
max_number2 = sorted(a)[-2]

for i in range(n):
    if a[i] == max_number:
        print(max_number2)
    else:
        print(max_number)
Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())

ans = []

ans += [1] * a
ans += [0] * b
ans += [-1] * c

print(sum(ans[:min(k, a+b+c)]))

Fixed submission:
a, b, c, k = map(int, input().split())

# ans = []

# ans += [1] * a
# ans += [0] * b
# ans += [-1] * c

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(a - (k - a - b))

#print(sum(ans[:k]))

Buggy python submission (verdict: Runtime Error):
a, b, c, k = map(int, input().split())

ans = []

ans += [1] * a
ans += [0] * a
ans += [-1] * a

print(sum(ans[:min(k, a+b+c)]))

Fixed submission:
a, b, c, k = map(int, input().split())

# ans = []

# ans += [1] * a
# ans += [0] * b
# ans += [-1] * c

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(a - (k - a - b))

#print(sum(ans[:k]))
Buggy python submission (verdict: Runtime Error):
 -*- coding: utf-8 -*-
import math
import sys

X = int(input())

for A in range(-118, 190):
  for B in range(-119, 119):
    val = math.pow(A, 5) - math.pow(B, 5)
    if(val == X):
      print(A, B)
      sys.exit()


Fixed submission:
# -*- coding: utf-8 -*-
import math
import sys

X = int(input())

for A in range(-118, 120):
  for B in range(-119, 119):
    val = math.pow(A, 5) - math.pow(B, 5)
    if(val == X):
      print(A, B)
      sys.exit()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math
import sys

X = int(input())

for A in range(-118, 190):
  for B in range(-119, 119):
    val = math.pow(A, 5) - math.pow(B, 5)
    if(val == X):
      print(A, B)
      sys.exit(0)
~                        

Fixed submission:
# -*- coding: utf-8 -*-
import math
import sys

X = int(input())

for A in range(-118, 120):
  for B in range(-119, 119):
    val = math.pow(A, 5) - math.pow(B, 5)
    if(val == X):
      print(A, B)
      sys.exit()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math
X = int(input())

B = 1
e = 1.0e-10
while True:
  B5 = pow(B, 5)
  A = math.pow(X + B5, 0.2)
  if(abs(A - int(A)) < e):
    print(int(A), B)
    break

  A = math.pow(X - B5, 0.2)
  if(abs(A-int(A)) < e):
    print(int(A), -B)
    break

  B += 1


Fixed submission:
# -*- coding: utf-8 -*-
import math
import sys

X = int(input())

for A in range(-118, 120):
  for B in range(-119, 119):
    val = math.pow(A, 5) - math.pow(B, 5)
    if(val == X):
      print(A, B)
      sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

flip = 0
for i in range(Q):
  st = input()
  if(st[0] == '1'):
    flip += 1
  else:
    if((st[2] == '1' and flip % 2 == 0) or (st[2] == '2' and flip % 2 == 1)):
      nS = st[4] + S
    else:
      nS = S + st[4]
    S = nS

if(flip % 2 != 0):
  S = S[::-1]
print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

flip = 0
ad1 = []
ad2 = []
for i in range(Q):
  st = input()
  if(st[0] == '1'):
    flip += 1
  else:
    if((st[2] == '1' and flip % 2 == 0) or (st[2] == '2' and flip % 2 == 1)):
      #nS = st[4] + S
      ad1.append(st[4])
    else:
      #nS = S + st[4]
      ad2.append(st[4])

ft = ''.join(ad1)
ft = ft[::-1]
ed = ''.join(ad2)

S = ft + S + ed

if(flip % 2 != 0):
  S = S[::-1]
print(S)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

for i in range(Q):
  st = input()
  if(st[0] == '1'):
    S = S[::-1]
  else:
    if(st[2] == '1'):
      nS = st[4] + S
    else:
      nS = S + st[4]
    S = nS

print(S)


Fixed submission:
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

flip = 0
ad1 = []
ad2 = []
for i in range(Q):
  st = input()
  if(st[0] == '1'):
    flip += 1
  else:
    if((st[2] == '1' and flip % 2 == 0) or (st[2] == '2' and flip % 2 == 1)):
      #nS = st[4] + S
      ad1.append(st[4])
    else:
      #nS = S + st[4]
      ad2.append(st[4])

ft = ''.join(ad1)
ft = ft[::-1]
ed = ''.join(ad2)

S = ft + S + ed

if(flip % 2 != 0):
  S = S[::-1]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
A, B = map(int, input().split())
pn = [2]
C = max(A, B)
for i in range(3, C+1):
  flag = 0
  for k in pn:
    if(i%k == 0):
      flag = 1
      break
  if(flag == 0):
    pn.append(i)
#print(pn)

N = len(pn)
aa = np.zeros(N)
bb = np.zeros(N)
As = A
Bs = B
for k in range(N):
  flag = 1
  count = 0
  while(flag == 1):
    if(As % pn[k] == 0):
      As = As // pn[k]
      count += 1
    else:
      flag = 0
  aa[k] = count

  flag = 1
  count = 0
  while(flag == 1):
    if(Bs % pn[k] == 0):
      Bs = Bs // pn[k]
      count += 1
    else:
      flag = 0
  bb[k] = count

ans = 1
for k in range(N):
  ans *= pn[k] ** max(aa[k], bb[k])

print(int(ans))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
A, B = map(int, input().split())

L = max(A, B)
S = min(A, B)
flag = 1
while(flag == 1):
  #print(L, S)
  if(L % S == 0):
    flag = 0
    lval = S
  else:
    tmp = L % S
    L = S
    S = tmp

Ar = A // lval
Br = B // lval

print(int(lval*Ar*Br))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
T = np.zeros(5, dtype=int)
T[0] = int(input())
T[1] = int(input())
T[2] = int(input())
T[3] = int(input())
T[4] = int(input())
res = np.argsort(T%10)
for i in range(5):
  if(T[res[i]]%10 > 0):
    selected_index = res[i]
    break
tim = (T//10 + (T%10 != 0))*10
tim[selected_index] = T[selected_index]
print(sum(tim))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
T = np.zeros(5, dtype=int)
T[0] = int(input())
T[1] = int(input())
T[2] = int(input())
T[3] = int(input())
T[4] = int(input())
res = np.argsort(T%10)
selected_index = 0
for i in range(5):
  if(T[res[i]]%10 > 0):
    selected_index = res[i]
    break
tim = (T//10 + (T%10 != 0))*10
tim[selected_index] = T[selected_index]
print(sum(tim))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
import numpy as np
S = input()
n = len(S)
l = np.zeros(n, dtype=int)
DNA = ['A', 'G', 'C', 'T']

i = 0
while(i < n):
  if(S[i] in DNA):
    if(i == n-1):
      l[i] = 1
      i+=1
    else:
      for j in range(i+1, n):
        if(S[j] not in DNA):
          l[i] = j-i
          i = j+1
          break;
  else:
    i += 1
print(max(l))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
S = input()
n = len(S)
l = np.zeros(n, dtype=int)
DNA = ['A', 'G', 'C', 'T']

if S[0] in DNA:
  ll = [1]
else:
  ll = [0]

for i in range(1, n):
  if S[i] in DNA:
    ll.append(ll[i-1]+1)
  else:
    ll.append(0)

print(max(ll))
Buggy python submission (verdict: Runtime Error):
 -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if(N <= K):
  sum = N*X
else:
  sum = K*X + (N-K)*Y

print(sum)


Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())
K = int(input())
X = int(input())
Y = int(input())

if(N <= K):
  sum = N*X
else:
  sum = K*X + (N-K)*Y

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

for i in range(1,N+1):
    if i in A:
        print(A.count(i))        
    else:
        print(0)




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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])

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

from collections import Counter
from functools import lru_cache

ans = [0]*(N+1)

@lru_cache(maxsize=1000)
def main(i):
    ans[i] = A.count(i)
    print(ans[i])

for i in range(1,N+1):
    main(i)


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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])

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

from functools import lru_cache

ans = [0]*(N+1)

@lru_cache(maxsize=1000)
def main():
    for i in range(1,N+1):
        ans[i] = A.count(i)
        print(ans[i])

main()


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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])

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

ans = [0]*(N+1)

for i in range(1,N+1):
    ans[i] = A.count(i)
    print(ans[i])


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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])

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

ans = [0]*(N+1)

for i in range(1,N+1):
    ans[i] = A.count(i)

for j in range(1,N+1):
    print(ans[j])


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

import collections
c = collections.Counter(A)

for i in range(1,N+1):
    print(c[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())
ans = 0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      temp = math.gcd(i, j)
      temp2 = math.gcd(temp, k)
      ans = temp2 + ans

print(ans)


Fixed submission:
import math
from functools import reduce

K = int(input())
ans = 0

def main(K):
    g=0
    for i in range(1,K+1):
        for j in range(1,K+1):
            for k in range(1,K+1):
                g += math.gcd(math.gcd(i, j), k)
    return (g)
 
print(main(K))
Buggy python submission (verdict: Time Limit Exceeded):
N,K = list(map(int, input().split()))
H = list(map(int, input().split()))

H = sorted(H, reverse=True)

for i in range(K):
    if(len(H) == 0):
        print(0)
        end = 0
        break
    H.pop(0)

if(len(H) > 0):
    print(sum(H))

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

H = sorted(H, reverse=True)

if K > N:
    print(0)
else:
    print(sum(H[K:]))
Buggy python submission (verdict: Runtime Error):
import math

A,B = map(int, input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(A, B))



Fixed submission:
import math

A,B = map(int, input().split())

def computeGCD(x, y): 
    if x > y: 
        small = y 
    else: 
        small = x 
    for i in range(1, small+1): 
        if((x % i == 0) and (y % i == 0)): 
            gcd = i 
              
    return gcd

def lcm(x, y):
    return (x * y) // computeGCD(x, y)

print(lcm(A, B))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input()) 
A = []

for j in range(N):
    A += [input()]

for i in range(N):
    S = A.copy()
    del S[i]
    print(max(S))
    

Fixed submission:
N = int(input()) 
A = []
 
for j in range(N):
    A += [int(input())]

maxnumber = max(A)
secondmax = sorted(A)[-2]

for i in range(N):
    if(maxnumber != A[i]):
       print(maxnumber)
    else:
       print(secondmax)
Buggy python submission (verdict: Runtime Error):
N,K=map(int, input().split())

if K=1:
   print(0)
else:
   print(N-K)


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

if K == 1:
  out =0
else:
  # 1以外
  nokori = N - K
  mx = nokori + 1
  mn = 1
  out = mx-mn

print(out)
Buggy python submission (verdict: Runtime Error):
import numpy as np
 
n=int(input())
w=list(map(int, input().split()))
s=[0]*n
 
for i in range(n):
  a = np.sum(w[:i])
  b = np.sum(w)
  c = b - a
  s[i] = abs(a-c)
  
print(int(np.min(s)))

Fixed submission:
import numpy as np
 
n=int(input())
w=list(map(int, input().split()))
s=[0]*n
 
for i in range(n):
  a = np.sum(w[:i])
  b = np.sum(w)
  c = b - a
  s[i] = abs(a-c)
  
print(int(np.min(s)))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())

if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")



Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if( (a * b) % 2 == 0):
  print "Even"
else:
  print "Odd"

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(raw_input())
b = int(raw_input())

if( (a * b) % 2 == 0):
  print "Even"
else:
  print "Odd"

Fixed submission:
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
s1,s2,s3 = map(int, input().split())
print(s1+s2+s3)


Fixed submission:
s=input()
print(s.count("1"))

Buggy python submission (verdict: Runtime Error):
s1,s2,s3 = map(int, input().split())
print(s1+s2+s3)

Fixed submission:
s=input()
print(s.count("1"))
Buggy python submission (verdict: Runtime Error):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

def find_min_cycle(a):
    memo = {1: 0}
    idx = 0
    cnt = 1

    while a[idx] not in memo:
        memo[a[idx]] = cnt
        cnt += 1
        idx = a[idx]-1

    return memo[a[idx]], cnt-memo[a[idx]], memo

offset, cycle_len, memo = find_min_cycle(a)
rmemo = {v: k for k, v in memo.items()}

if k <= offset:
    print(memo[k])
else:
    i = (k-offset)%cycle_len
    print(rmemo[offset+i])


Fixed submission:
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

def find_min_cycle(a):
    memo = {1: 0}
    idx = 0
    cnt = 1

    while a[idx] not in memo:
        memo[a[idx]] = cnt
        cnt += 1
        idx = a[idx]-1

    return memo[a[idx]], cnt-memo[a[idx]], memo

offset, cycle_len, memo = find_min_cycle(a)
rmemo = {v: k for k, v in memo.items()}

if k <= offset:
    print(rmemo[k])
else:
    i = (k-offset)%cycle_len
    print(rmemo[offset+i])
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()
    d = {'R': [], 'G': [], 'B': []}

    for i, c in enumerate(s):
        d[c].append(i)

    ans = 0

    perms = (('R', 'G', 'B'), ('R', 'B', 'G'), ('B', 'R', 'G'), ('B', 'G', 'R'), ('G', 'R', 'B'), ('G', 'B', 'R'))

    for p1, p2, p3 in perms:
        for i in d[p1]:
            for j in d[p2]:
                for k in d[p3]:
                    if j > i and k > j and k-j != j-i:
                        ans +=1

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter
def main():
    n = int(input())
    s = input()
    d = Counter(s)
    ans = d['R'] * d['G'] * d['B']

    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j-i
            if s[i]!=s[j] and k < n and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    s = input()

    ans = 0

    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if s[i] != s[j] and s[i] != s[k] and s[j] != s[k] and j-i != k-j:
                    ans += 1

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
from collections import Counter
def main():
    n = int(input())
    s = input()
    d = Counter(s)
    ans = d['R'] * d['G'] * d['B']

    for i in range(n-2):
        for j in range(i+1, n-1):
            k = 2*j-i
            if s[i]!=s[j] and k < n and s[i] != s[k] and s[j] != s[k]:
                ans -= 1

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

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

way = [[0 for j in range(n)] for i in range(n)]




for i in range(m):
    a,b  = map(int, input().split())
    way[a-1][b-1] += 1
    way[b-1][a-1] += 1
    
#print(way)
goodcount = 0

for i in range(n): #i本目を調べてる
    good = 1
    for j in range(n): #j本目と比べてる
        #print("!", i,j)
        if i != j and way[i][j] != 0:
            #print(height[i], height[j])
            if height[i] <= height[j]:
                good = 0
                
    if good == 1:
        goodcount += 1
        #print(i)
        
print(goodcount)


Fixed submission:
n, m = map(int, input().split())

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

good = [1 for j in range(n)] 


for i in range(m):
    a,b  = map(int, input().split())
    
    if height[a-1] >= height[b-1]:
        good[b-1] = 0
    if height[a-1] <= height[b-1]:
        good[a-1] = 0

ans = good.count(1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = n * 2 * math.pi
print(a)

Fixed submission:
import math
n = int(input())
a = n * 2 * math.pi
print(a)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = n * 2 * math.pi
print(a)


Fixed submission:
import math
n = int(input())
a = n * 2 * math.pi
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
letters = list(input())
n = int(input())
for i in range(0,n):
    command = list(input().split())
    if command[0] == "1":
        letters.reverse()
    
    else:
        if command[1] == "2":
            letters.append(command[2])
        else:
            letters.insert(0, command[2])


ans = "".join(letters)
print(ans)

Fixed submission:
from collections import deque

letters = deque(input())
n = int(input())

top = "head"

for i in range(0,n):
    command = list(input().split())
    if command[0] == "1":
        if top == "head":
            top = "tail"
        else:
            top = "head"
        
    
    else:
        if (command[1] == "2" and top == "head") or (command[1] == "1" and top == "tail"):
            letters.append(command[2])
        else:
            letters.appendleft(command[2])

if top == "tail":
    letters.reverse()
    
 
ans = "".join(letters)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [""] * n
t = []
for i in range(n):
    s[i] = input()
for i in range(n):
    if s[i] not in t:
        t.append(s[i])
print(len(t))


Fixed submission:
n = int(input())
s = [""] * n
for i in range(n):
    s[i] = input()
s = set(s)
print(len(s))
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
a = list(range(1,k+1))
b = list(range(1,k+1))
c = list(range(1,k+1))

for i in a:
    for j in b:
        for k in c:
            ans += gcd(i,j,k)
print(ans)

Fixed submission:
import math
from functools import reduce

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

k = int(input())
ans = 0
a = list(range(1,k+1))
b = list(range(1,k+1))
c = list(range(1,k+1))

for i in a:
    for j in b:
        for k in c:
            ans += gcd(i,j,k)
print(ans)