Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def popcount(n):
    cnt = 0
    for i in range(n):
        if ((n >> i) & 1):
            cnt +=1
    return cnt

def f(n):
    cnt = 1
    while True:
        if n == 0:
            break
        n = n % popcount(n)
        cnt += 1
    return cnt

def pow_r(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return pow_r(x ** 2, n // 2)
    else:
        return x * pow_r(x ** 2, (n - 1) // 2)

if __name__ == "__main__":
    n = int(input())
    x = input()
    xList = list(x)
    k = len(xList) - 1
    xNum = int("".join(xList), 2)
    numcnt = popcount(xNum)
    a = numcnt
    wk = 0
    for i in range(n):
        if xList[i] == '0':
            numcnt += 1
        else:
            numcnt -= 1
        xList[i] = str(int(xList[i]) ^ 1)
        xNum = int("".join(xList), 2)
        wk = xNum % numcnt
        if wk == 0:
            print(1)
        else:
            print(f(wk))
        xList[i] = str(int(xList[i]) ^ 1)
        numcnt = a


Fixed submission:
l, r, d = map(int, input().split())
cnt = 0
a = l
while True:
    if a % d == 0:
        break
    else:
        a += 1
while True:
    if a > r:
        break
    cnt += 1
    a += d
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,x,t=int(input().split())
print(n*x/t)

Fixed submission:
n,x,t=map(int,input().split())
print(-n//x*-t)
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%0==0:
  print("Yes")
else:
  print("No")

Fixed submission:
print("Yes"if int(input())%9==0else"No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
  if a[i-1]>a[i]
    ans+=a[i-1]-a[i]
    a[i]=a[i-1]
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
  if a[i-1]>a[i]:
    ans+=a[i-1]-a[i]
    a[i]=a[i-1]
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input()))
ans=0
for i in range(1,n):
  if a[i-1]>a[i]
    ans+=a[i-1]-a[i]
    a[i]=a[i-1]
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
  if a[i-1]>a[i]:
    ans+=a[i-1]-a[i]
    a[i]=a[i-1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int, input().split())
h=list(map(int, input().split()))
dp=[0]*n
for i in range(1,n):
    dp[i]=min([dpj+abs(h[i]-hj) for dpj,hj in zip(dp[max(0,i-k):i],h[max(0,i-k):i])])
print(dp[-1])

Fixed submission:
n,k=map(int, input().split())
h=list(map(int, input().split()))
dp=[0]*n
for i in range(1,n):
    dp[i]=min([dpj+abs(h[i]-hj) for dpj,hj in zip(dp[max(0,i-k):i],h[max(0,i-k):i])])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab =  [list(map(int,input().split(" "))) for i in range(m)]
for i in range(m):
  if (ab[i][0] == 1):
    c = ab[i][1]
    for i in range(m):
      if (ab[i][0] == c and ab[i][1] == n):
        ans = 'POSSIBLE'
  else:
    ans = 'IMPOSSIBLE'
print(ans)

Fixed submission:
n,m = map(int,input().split())
s=[False]*n
t=[False]*n
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    s[b-1]=True
  if b==n:
    t[a-1]=True
for i in range(n):
  if s[i]==True and t[i]==True:
    print('POSSIBLE')
    exit()
print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
import sys

def f(x,y):
    return x-y.x+y

def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    x = [0]*n
    y = [0]*n
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    f0 = [0]*n
    f1 = [0]*n
    for i in range(n):
        f0[i],fi[i] = f(x[i],y[i])
    print(max(max(f0)-minf(0),max(f1)-minf(1)))

if __name__ = "__main__":
    main()

Fixed submission:
def main():
    n, *xy = map(int, open(0).read().split())
    f = [(i - j, i + j) for i, j in zip(xy[::2], xy[1::2])]
 
    a = max(x[0] for x in f)
    b = min(x[0] for x in f)
 
    c = max(x[1] for x in f)
    d = min(x[1] for x in f)
 
    ans = max(a - b, c - d)
    print(ans)
 
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c = input()
l =list(c)
L = len(l)//2
ans = 0
k = n-1

for i in range(k):
    for j in range(k,i,-1):
        if l[i]== 'W' and l[j] == 'R':
            l[j] = 'W'
            ans += 1
            k = j-1
            break
print(ans)

Fixed submission:
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c = input()
l =list(c)
L = len(l)//2
ans = 0
k = n-1

for i in range(n-1):
    for j in range(k,i,-1):
        if l[i]== 'W' and l[j] == 'R':
            l[j] = 'W'
            ans += 1
            k = j-1
            break
print(ans)

Fixed submission:
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c = input()
l =list(c)
L = len(l)//2
ans = 0
k = n-1

for i in range(n-1):
    for j in range(k,i,-1):
        if l[i]== 'W' and l[j] == 'R':
            l[j] = 'W'
            ans += 1
            k = j-1
            break
print(ans)

Fixed submission:
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c = input()
l =list(c)
L = len(l)//2
ans = 0

for i in range(n-1):
    for j in range(n-1,i,-1):
        if l[i]== 'W' and l[j] == 'R':
            l[j] = 'W'
            ans += 1
            break
print(ans)

Fixed submission:
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c = input()
l =list(c)
L = len(l)//2
ans = 0

for i in range(n-1):
    for j in range(n-1,i,-1):
        if l[i]== 'W' and l[j] == 'R':
            l[i] = 'R'
            l[j] = 'W'
            ans += 1
print(ans)

Fixed submission:
n=int(input())
c=input()
r=c.count("R")
r_1=c[:r].count("R")
ans=r-r_1
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int, input().split())
n=int(input()) 

k = n

if a < b < c:
    print('Yes')
    break

if a < b and b >= c:
    while  b >= c and k >= 1:
        c = 2*c
        k -= 1
        if b >= c and k == 0:
            print('No')
        if b < c and k>=0:
            print('Yes')

if a >= b:
    while a >= b and k >= 1:
        b = 2*b
        k -= 1
        if a >= b and k == 0 :
            print('No')
        if a < b and b >= c and k == 0:
            print('No')
        if a < b < c:
            print('Yes')
            break
        if a < b and b >= c and k >= 1:
            while  b >= c and k >= 1:
                c = 2*c
                k -= 1
                if b >= c and k == 0:
                    print('No')
                if b < c and k>=0:
                    print('Yes')
                    break

Fixed submission:
a,b,c=map(int, input().split())
n=int(input()) 
 
k = n
 
if a < b < c:
    print('Yes')
 
if a < b and b >= c:
    while  b >= c and k >= 1:
        c = 2*c
        k -= 1
        if b >= c and k == 0:
            print('No')
        if b < c and k>=0:
            print('Yes')
 
if a >= b:
    while a >= b and k >= 1:
        b = 2*b
        k -= 1
        if a >= b and k == 0 :
            print('No')
        if a < b and b >= c and k == 0:
            print('No')
        if a < b < c:
            print('Yes')
            break
        if a < b and b >= c and k >= 1:
            while  b >= c and k >= 1:
                c = 2*c
                k -= 1
                if b >= c and k == 0:
                    print('No')
                if b < c and k>=0:
                    print('Yes')
                    break
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int, input().split())
l =sorted([a,b,c])

s = sum(l[:2])
print(s)

Fixed submission:
n = int(input())
a = n%1000

if a == 0 :
  print(0)
if a != 0 :
  print(1000 - a)
Buggy python submission (verdict: Runtime Error):
zn = int(input())
a = 0
b = 0
c = 0
d = 0
 
for i in range(n):
  S = str(input())
  if S == 'AC':
    a += 1
  elif S == 'WA':
    b += 1
  elif S == 'TLE':
    c += 1
  elif S == 'RE':
    d += 1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for _ in range(N):
  s = input()
  if s == 'AC':
    d[s] += 1
  elif s == 'WA':
    d[s] += 1
  elif s == 'TLE':
    d[s] += 1
  else:
    d[s] += 1
    
    
for k in ['AC', 'WA', 'TLE', 'RE']:
  print('{} x {}'.format(k, d[k]))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = 0
b = 0
c = 0
d = 0

for i in range(n):
  S = str(input())
  if S == 'AC':
    a += 1
  if S == 'WA':
    b += 1
  if S == 'TLE':
    c += 1
  if S == 'RE':
    d += 1
print('AC x '+str(a)
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for _ in range(N):
  s = input()
  if s == 'AC':
    d[s] += 1
  elif s == 'WA':
    d[s] += 1
  elif s == 'TLE':
    d[s] += 1
  else:
    d[s] += 1
    
    
for k in ['AC', 'WA', 'TLE', 'RE']:
  print('{} x {}'.format(k, d[k]))

Buggy python submission (verdict: Runtime Error):
taka_h, taka_a, aoki_h, aoki_a = map(int, input().split())

while True:
    aoki_h -=taka_a
    taka_h -= aoki_a
    if(aoki_h <=0):
        print("Yes")
        break
    elif(taka_h <= 0):
        print("No")
        break


Fixed submission:
from collections import defaultdict
N = int(input())
d = defaultdict(int)

for _ in range(N):
  s = input()
  if s == 'AC':
    d[s] += 1
  elif s == 'WA':
    d[s] += 1
  elif s == 'TLE':
    d[s] += 1
  else:
    d[s] += 1
    
    
for k in ['AC', 'WA', 'TLE', 'RE']:
  print('{} x {}'.format(k, d[k]))
Buggy python submission (verdict: Runtime Error):
a=int(input()) 
print(a+a*a+a**3)　

Fixed submission:
a=int(input())
print(a+a*a+a**3)

Buggy python submission (verdict: Runtime Error):
a=int(input()) 
print(a+a*a+a**3)　

Fixed submission:
a=int(input())
print(a+a*a+a**3)

Buggy python submission (verdict: Runtime Error):
a=int(input()) #aを整数aの変数として扱う
print(a+a*a+a**3)　#a+a*a+a**3の値を表示する


Fixed submission:
a=int(input())
print(a+a*a+a**3)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a,b=[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans,j=0,M
for i in range(N + 1):
    if a[i]>K:
        break
    while b[j] > K - a[i]
        j -= 1
    ans = max(ans, i + j)
print(ans)


Fixed submission:
def main():
    from itertools import chain

    N, M, K = map(int, input().split())
    A = map(int, input().split())
    *B, = map(int, input().split())

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a,b=[0],[0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans,j=0,M
for i in range(N + 1):
    if a[i]>K:
        break
    while b[j] > K - a[i]
        j -= 1
    ans = max(ans, i + j)
print(ans)


Fixed submission:
def main():
    from itertools import chain

    N, M, K = map(int, input().split())
    A = map(int, input().split())
    *B, = map(int, input().split())

    t = sum(B)
    ans = 0
    j = M
    for i, x in enumerate(chain([0], A)):
        t += x
        while j > 0 and t > K:
            j -= 1
            t -= B[j]
        if t > K: break
        if ans < i + j:
            ans = i + j
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for j in range(1,N+1):
    for i in range(1,N+1):
        if i % j == 0 :
            ans += i
print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, int(n ** 0.5) + 1):
    k = n // i
    ans += i * k * (k + 1) // 2
    if i != k:
        l = n // (i + 1)
        ans += i * (i + 1) * (k + l + 1) * (k - l) // 4
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = ""
while N > 0:
  x = (N-1) % 26

  ans = chr(ord('a') + x) + ans
  N = (N-1) // 26

print(ans)


Fixed submission:
a = input()
print('A' if a.isupper() else 'a')

Buggy python submission (verdict: Runtime Error):
 a = input()
print('A' if a.isupper() else 'a')

Fixed submission:
a = input()
print('A' if a.isupper() else 'a')

Buggy python submission (verdict: Runtime Error):
 a = input()
print('A' if a.isupper() else 'a')

Fixed submission:
a = input()
print('A' if a.isupper() else 'a')
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.buffer.readline

def main():
    N = int(readline())
    A = [0] *(10**5)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()

Fixed submission:
import sys
readline = sys.stdin.buffer.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
def main():
    N = int(readline())
    A = [0] *(10**5+1)
    total = 0
    for a in map(int, readline().split()):
        total += a
        A[a] += 1
 
 
    Q = int(readline())
    for _ in range(Q):
        b, c = map(int, readline().split())
        total += A[b]*(c-b)
        print(total)
        A[c] += A[b]
        A[b] = 0
 
 
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())
P = list(map(int,input().split()))
 
for i in range(101):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    break

Fixed submission:
x=list(map(int,input().split()))
print(x.index(0)+1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
c=list(map(int, input().split()))
ans = 1
mod = 10**18

for i in c:
    ans = ans*i

if ans <= mod:
    print(ans)
else:
    print('-1')

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

    if 0 in A:
        print(0)
        return

    prod = 1
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1)
            return

    print(prod)


main()
Buggy python submission (verdict: Runtime Error):
from collections import deque
def main():
    N,M,*AB=map(int,open(0).read().split())
    g=[[] for _ in range(N+1)]
    for a,b in zip(*[iter(AB)]*2):
        g[a].append(b)
        g[b].append(a)
    q=deque([1])
    s=[0]*(N+1)
    s[1]=1
    while q:
        u=q.popleft()
        for v in g[u]:
            if not s[v]:
                s[v] = u
                q.append(v)
    print("Yes")
    print("\n".join(map(str, s[2:])))
if __name__ == "__main__":
    main()

Fixed submission:
import math
 
N = int(input())
Prime = []
ans = 0
 
def func(n):
    while n % 2 == 0:
        n = n // 2
        Prime.append(2)
    for i in range(3, int(math.sqrt(n)) + 1, 2):
        while n % i == 0:
            n = n //i
            Prime.append(i)
    if n > 2:
        Prime.append(n)
 
func(N)
 
for i in set(Prime):
    c = i
    while N % c == 0:
        N = N // c
        ans += 1
        c = c * i
 
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Fixed submission:
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')

Buggy python submission (verdict: Runtime Error):
a,b,import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')


Fixed submission:
import numpy as np
import itertools
n, m, x = map(int, input().split())
a = np.dot([i for i in itertools.product([0, 1], repeat = n)],
           [list(map(int, input().split())) for _ in range(n)])
b = np.prod(a[:, 1:(m + 1)] >= x, axis = 1, dtype = bool)
print(min(a[:, 0][b]) if b.sum() else '-1')
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
from math import gcd
from itertools import product

K = int(input())
b = 0

for a in product(range(1,K+1), repeat=3):
    b += reduce(gcd, a)
print(b)

Fixed submission:
from math import gcd
r = range(1, int(input()) + 1)
print(sum(gcd(gcd(i,j),k) for i in r for j in r for k in r))
Buggy python submission (verdict: Runtime Error):
rom collections import Counter
N=int(input())
A=list(map(int, input().split()))
 
count = Counter(A)
vals = count.values()
sum_ = 0
for v in vals:
  if v >= 2: sum_ += v*(v-1)
sum_ //= 2
 
for k in range(N):
  if count[A[k]] < 2: print(sum_)
  else:print(sum_ + 1 - count[A[k]])

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))

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

for i in range(N):
    c = a[i]
    del a[i]
    a1 = sorted(a)
    for j in range(N-2):
        for k in range(j+1,N-1):
            if a1[j] == a1[k]:
                ans += 1
    print(ans)
    ans = 0
    a.insert(i,c)

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int,input().split()))
s = np.zeros(n+1)
for i in a:
    s[i]+=1
al = sum((s*(s-1))/2)
for i in range(n):
    ans=al-(s[a[i]]-1)
    print(int(ans))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int, input().split())

al = [1]*a
bl = [0]*b
cl =[]
d = a + b
e = n//d + 2

for i in range(e):
    cl = cl + al + bl

print(sum(cl[:n]))

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

d = a+b
c = n%d
e = n//d

if c <= a:
    print(e*a+c)
if c > a:
    print((e+1)*a)

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

al = [1]*a
bl = [0]*b
cl =[]

for i in range(20):
    cl = cl + al + bl

print(sum(cl[:n]))

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

d = a+b
c = n%d
e = n//d

if c <= a:
    print(e*a+c)
if c > a:
    print((e+1)*a)

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

al = [1]*a
bl = [0]*b
cl =[]

for i in range(n+1):
    cl = cl + al + bl

print(sum(cl[:n]))

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

d = a+b
c = n%d
e = n//d

if c <= a:
    print(e*a+c)
if c > a:
    print((e+1)*a)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans = 0
 
for i in range(q):
    c = list(map(str, input().split()))
    if c[0] == '1':
        ans +=1
        ans = ans%2
    if c[0] == '2':
        if (int(c[1])+ans)%2== 1 :
          s = c[2] + s
        if (int(c[1])+ans)%2== 0 :
          s = s + c[2]
 
if ans == 1:
  s = s[::-1]
 
print(s)

Fixed submission:
s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
  query=input().split()
  if int(query[0])==1:
    r=1-r
  else:
    if (r^(int(query[1])-1))==0:
      f+=query[2]
    else:
      b+=query[2]
ret=f[::-1]+s+b
if r:
  ret=ret[::-1]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans = 0

for i in range(q):
    c = list(map(str, input().split()))
    if c[0] == '1':
        ans +=1
    if c[0] == '2':
        if (int(c[1])+ans%2)%2== 1 :
          s = c[2] + s
        if (int(c[1])+ans%2)%2== 0 :
          s = s + c[2]

if ans%2 == 1:
  s = s[::-1]

print(s)

Fixed submission:
s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
  query=input().split()
  if int(query[0])==1:
    r=1-r
  else:
    if (r^(int(query[1])-1))==0:
      f+=query[2]
    else:
      b+=query[2]
ret=f[::-1]+s+b
if r:
  ret=ret[::-1]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
ans = 0

for i in range(q):
    c = list(map(str, input().split()))
    if c[0] == '1':
        ans +=1
    if c[0] == '2':
        if c[1] == '1' and ans%2 == 0 :
          s = c[2] + s
        if c[1] == '1' and ans%2 == 1 :
          s = s + c[2]
        if c[1] == '2' and ans%2 == 0:
          s = s + c[2]
        if c[1] == '2' and ans%2 == 1:
          s = c[2] + s

if ans%2 == 1:
  s = s[::-1]

print(s)

Fixed submission:
s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
  query=input().split()
  if int(query[0])==1:
    r=1-r
  else:
    if (r^(int(query[1])-1))==0:
      f+=query[2]
    else:
      b+=query[2]
ret=f[::-1]+s+b
if r:
  ret=ret[::-1]
print(ret)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

for i in range(q):
    c = list(map(str, input().split()))
    if c[0] == '1':
        s = s[::-1]
    if c[0] == '2':
        if c[1] == '1':
            s = c[2] + s
        if c[1] == '2':
            s = s + c[2]

print(s)

Fixed submission:
s=input()
q=int(input())
f=""
b=""
r=0
for i in range(q):
  query=input().split()
  if int(query[0])==1:
    r=1-r
  else:
    if (r^(int(query[1])-1))==0:
      f+=query[2]
    else:
      b+=query[2]
ret=f[::-1]+s+b
if r:
  ret=ret[::-1]
print(ret)