Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
d = dict()
wa = ac = 0
N, M= map(int,input().split())
for i in range(M):
  a, b = input().split()
    if a not in d:
        d[a] = 0
    if d[a] >= 0 and b == "AC":
        ac += 1
        wa += d[a]
        d[a] = -1
    elif d[a] >= 0:
        d[a] += 1
print(ac,wa)

Fixed submission:
d = dict()
wa = ac = 0
N, M= map(int,input().split())
for i in range(M):
  a, b = input().split()
  if a not in d:
    d[a] = 0
  if d[a] >= 0 and b == "AC":
    ac += 1
    wa += d[a]
    d[a] = -1
  elif d[a] >= 0:
    d[a] += 1
print(ac,wa)

Buggy python submission (verdict: Runtime Error):
d = dict()
wa = ac = 0
N, M= map(int,input().split())
for i in range(M):
  a, b = input().split()
  if a not in d:
    d[a] = 0
if d[a] >= 0 and b == "AC":
    ac += 1
    wa += d[a]
    d[a] = -1
elif d[a] >= 0:
    d[a] += 1
print(ac,wa)

Fixed submission:
d = dict()
wa = ac = 0
N, M= map(int,input().split())
for i in range(M):
  a, b = input().split()
  if a not in d:
    d[a] = 0
  if d[a] >= 0 and b == "AC":
    ac += 1
    wa += d[a]
    d[a] = -1
  elif d[a] >= 0:
    d[a] += 1
print(ac,wa)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
x = 0
while x == 0:
    num = 2
    while N % 2 != 0:
        num += 1
    if num == N:
        x = 1
    else:
        N += 1
print(N)

Fixed submission:
N = int(input())
x = True
while x:
    num = 2
    while N % num != 0:
        num += 1
    if num == N:
        x = False
    else:
        N += 1
print(N)
Buggy python submission (verdict: Runtime Error):
N = int(input())
X = input()

def calc(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    r_1 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % cnt
        a_1 = (a_1 * 2) % cnt

    return r_1[0]

def calc_first(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    a_2 = 1
    r_1 = [0] * (L+1)
    r_2 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % (cnt+1)
        r_2[i] = (r_2[i+1] + int(S[i]) * a_2) % (cnt-1)

        a_1 = (a_1 * 2) % (cnt + 1)
        a_2 = (a_2 * 2) % (cnt - 1)

    for i in range(L):
        if S[i] == "0":
            ans = (r_1[0] - r_1[i] + r_1[i+1] + pow(2, N-i-1, (cnt+1))) % (cnt+1)
        else:
            ans = (r_2[0] - r_2[i] + r_2[i+1]) % (cnt-1)

        cnt_ans = 1
        while ans > 0:
            ans = calc(str(bin(ans))[2:], len(str(bin(ans))[2:]))
            cnt_ans += 1
        print(cnt_ans)

calc_first(X, N)



Fixed submission:
N = int(input())
X = input()

def calc(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    r_1 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % cnt
        a_1 = (a_1 * 2) % cnt

    return r_1[0]

def calc_first(S, L):
    cnt = 0
    for i in range(L):
        if S[i] == "1":
            cnt += 1

    a_1 = 1
    a_2 = 1
    r_1 = [0] * (L+1)
    r_2 = [0] * (L+1)
    for i in reversed(range(L)):
        r_1[i] = (r_1[i+1] + int(S[i]) * a_1) % (cnt+1)
        if cnt-1 > 0:
            r_2[i] = (r_2[i+1] + int(S[i]) * a_2) % (cnt-1)

        a_1 = (a_1 * 2) % (cnt + 1)
        if cnt-1 > 0:
            a_2 = (a_2 * 2) % (cnt - 1)

    for i in range(L):
        if S[i] == "0":
            ans = (r_1[0] - r_1[i] + r_1[i+1] + pow(2, N-i-1, (cnt+1))) % (cnt+1)
        else:
            if cnt == 1:
                print(0)
                continue
            else:
                ans = (r_2[0] - r_2[i] + r_2[i+1]) % (cnt-1)

        cnt_ans = 1
        while ans > 0:
            ans = calc(str(bin(ans))[2:], len(str(bin(ans))[2:]))
            cnt_ans += 1
        print(cnt_ans)

calc_first(X, N)
Buggy python submission (verdict: Runtime Error):
N = int(input())

s = []
a = 26
tmp = 1
for i in range(20):
    s.append(tmp)
    tmp += a
    a *= 26
    if tmp > 1000000000000001:
        break

for i in range(len(s)):
    if N >= s[i]:
        continue
    else:
        size = i 
        break

b = N - s[size-1]

n2a = lambda c: chr(c+64)
a = 26 ** (size-1)

ans = []
while(a >= 1):
    ans.append(n2a(b // a + 1).lower())
    b %= a
    a //= 26

print(*ans, sep="")

Fixed submission:
N = int(input())

s = []
a = 26
tmp = 1
for i in range(20):
    s.append(tmp)
    tmp += a
    a *= 26
    if tmp > 100000000000000000:
        break

for i in range(len(s)):
    if N >= s[i]:
        continue
    else:
        size = i 
        break

b = N - s[size-1]

n2a = lambda c: chr(c+64)
a = 26 ** (size-1)

ans = []
while(a >= 1):
    ans.append(n2a(b // a + 1).lower())
    b %= a
    a //= 26

print(*ans, sep="")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
S = input()

mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]

        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
        self.invs[n] = pow(self.facts[n], mod-2, mod)
        for i in range(1, n+1):
            self.invs[n-i] = self.invs[n-i+1] * (n-i+1) % mod

    def ncr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.ncr(n+r-1, n-1)

N = K+len(S)
pow25 = [1] * (N+1)
pow26 = [1] * (N+1)
for i in range(1, N+1):
    pow25[i] = (pow25[i-1] * 25) % mod
    pow26[i] = (pow26[i-1] * 26) % mod

comb = Combination(K+len(S))

ans = 0
for i in range(K+1):
    ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow25[N-i-len(S)] * pow26[i]) % mod

print(ans)

Fixed submission:
K = int(input())
S = input()

mod = 10**9 + 7

class Combination:
    def __init__(self, n):
        self.facts = [1 for i in range(n+1)]
        self.invs = [1 for i in range(n+1)]
        
        for i in range(1, n+1):
            self.facts[i] = self.facts[i-1] * i % mod
            self.invs[i] = pow(self.facts[i], mod-2, mod)

    def ncr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.facts[n] * self.invs[r] * self.invs[n-r] % mod

    def nhr(self, n, r):
        if n < r:
            return 0
        if n < 0 or r < 0:
            return 0
        else:
            return self.ncr(n+r-1, n-1)

N = K+len(S)
comb = Combination(K+len(S))

ans = 0
for i in range(K+1):
    ans = (ans + comb.ncr(N-i-1, len(S)-1) * pow(25, N-i-len(S), mod) * pow(26, i, mod)) % mod

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

exist = [False] * 101
p = list(map(int, input().split()))

for i in range(N):
    exist[p[i]] = True

for i in range(200):
    if X - i <= 0:
        print(X-i)
        exit()

    if not exist[X-i]:
        print(X-i)
        exit()

    if not exist[X+i]:
        print(X+i)
        exit()

    if X + i > 100:
        print(X+i)
        exit()


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

exist = [False] * 101
p = list(map(int, input().split()))

for i in range(N):
    exist[p[i]] = True

for i in range(200):
    if X - i <= 0:
        print(X-i)
        exit()

    if not exist[X-i]:
        print(X-i)
        exit()

    if X + i > 100:
        print(X+i)
        exit()

    if not exist[X+i]:
        print(X+i)
        exit()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A.sort()
ok = [False] * N

for i in range(N):
    for j in range(i+1, N):
        if ok[j]:
            continue

        if A[i] == A[j]:
            ok[i] = True
            ok[j] = True

        if A[j] % A[i] == 0:
            ok[j] = True

print(N-sum(ok))

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

amax = max(A)
sieve = [False] * (amax+1)
exist = [0] * (amax+1)

for a in A:
    if exist[a] > 0:
        exist[a] += 1
        continue
    exist[a] += 1
    for i in range(a*2, amax+1, a):
        sieve[i] = True

ans = 0
for a in A:
    if not sieve[a] and exist[a] == 1:
        ans += 1

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        break

print(*A)

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        break

print(*A)

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        print(break)

print(*A)

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        break

print(*A)

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

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

if K > math.sqrt(N):
    A = [N] * N
    print(*A)
    exit()

for i in range(K):
    tmp_A = np.array([0] * N)
    for j in range(N):
        tmp_A[max(0,j-A[j]):min(j+A[j], N-1)+1] += 1
    A = tmp_A

print(*A)

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

for i in range(K):
    B = [0] * N
    for j in range(N):
        l = max(0,j-A[j])
        r = j+A[j]+1
        B[l] += 1
        if r < N:
            B[r] -= 1
    for j in range(1, N):
        B[j] += B[j-1]

    A = B

    if sum(A) == N**2:
        break

print(*A)
Buggy python submission (verdict: Runtime Error):
T = input()
if T[0] == "?" and len(T) > 1:
    ans = "P"
elif T[0] == "?" and len(T) == 1:
    ans = "D"
else:
    ans = T[0]

for i in range(1, len(T)):
    if T[i] == "?":
        if ans[i-1] == "P":
            ans = ans + "D"
        elif i == len(T) - 1:
            ans = ans + "D"
        elif ans[i+1] == "D":
            ans = ans + "P"
        else:
            ans = ans + "P"
    else:
        ans = ans + T[i]

print(ans)

Fixed submission:
T = input()
ans = ""

for i in range(len(T)):
    if T[i] == "?":
        ans = ans + "D"
    else:
        ans = ans + T[i]

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

N, K = map(int, input().split())

mat = np.array([[False] * N for i in range(N)])

for i in range(K):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        mat[i][a[j]-1] = True

mat = mat.T


ans = 0
for i in range(N):
    flg = False
    for j in range(N):
        if mat[i][j]:
            flg = True

    if not flg:
        ans += 1

print(ans)

Fixed submission:
import numpy as np

N, K = map(int, input().split())

mat = np.array([[False] * N for i in range(K)])

for i in range(K):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        mat[i][a[j]-1] = True

mat = mat.T

ans = 0
for i in range(N):
    flg = False
    for j in range(K):
        if mat[i][j]:
            flg = True

    if not flg:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import Counter

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.arange(N) + 1

s = A + B
m = B - A

s_ct = Counter(s)
m_ct = Counter(m)

ans = 0
for i in s_ct:
    for j in m_ct:
        if i == j:
            ans += m_ct[j] * s_ct[i] 

print(ans)




Fixed submission:
import numpy as np
from collections import Counter

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.arange(N) + 1

s = A + B
m = B - A

s_ct = Counter(s)
m_ct = Counter(m)

ans = 0
for i in s_ct:
    ans += s_ct[i] * m_ct[i]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

ans = 0
for i in range(N):
    tmp_A = A + A[i]
    tmp_B = np.concatenate([np.zeros(i),np.arange(N-i)])
    C = tmp_B - tmp_A
    ans += np.count_nonzero(C == 0)

print(ans)

Fixed submission:
import numpy as np
from collections import Counter

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.arange(N) + 1

s = A + B
m = B - A

s_ct = Counter(s)
m_ct = Counter(m)

ans = 0
for i in s_ct:
    ans += s_ct[i] * m_ct[i]

print(ans)

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

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

ans = 0
for i in range(N):
    tmp_A = A + A[i]
    tmp_B = np.concatenate([np.zeros(i),np.arange(N-i)])
    C = tmp_B - tmp_A
    ans += np.count_nonzero(C == 0)

print(ans)





Fixed submission:
import numpy as np
from collections import Counter

N = int(input())
A = np.array(list(map(int, input().split())))
B = np.arange(N) + 1

s = A + B
m = B - A

s_ct = Counter(s)
m_ct = Counter(m)

ans = 0
for i in s_ct:
    ans += s_ct[i] * m_ct[i]

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
N = len(S)

dp = [0] * 2019
for i in reversed(range(N)):
    mod = int(S[i:]) % 2019
    dp[mod] += 1

ret = [i*(i-1)//2 for i in dp if i > 1]
print(sum(ret) + dp[0])

Fixed submission:
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ans = 0
for i in range(len(S)):
    Sum = int(S[i]) % 3
    for j in range(i+1, len(S)):
        Sum = (int(S[j]) + Sum) % 3
        if Sum != 0:
            continue
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ans = 0
for i in range(len(S)):
    Sum = int(S[i])
    for j in range(i+1, len(S)):
        Sum += int(S[j])
        if Sum % 3 != 0:
            continue
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()

ans = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        if int(S[i:j+1]) % 2019 == 0:
            ans += 1

print(ans)

Fixed submission:
from collections import Counter

S = input()
N = len(S)

dp = [0] * N
dp[N-1] = int(S[N-1])
times = 10
for i in reversed(range(1, N)):
    dp[i-1] = (dp[i] + times * int(S[i-1])) % 2019
    times *= 10
    times %= 2019

T = Counter(dp)
ans = T[0]
for t in T.values():
    ans += t*(t-1)//2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import math
# 1行だけ読むやつ

N = int(stdin.readline().rstrip().split()[0])
Sum = 0

for i in range(1, N+1):
    for j in range(1, N+1):
        for k in range(1, N+1):
            temp_gcd = math.gcd(i, j)
            Sum += math.gcd(temp_gcd, k)

print(Sum)

Fixed submission:
from sys import stdin
import math
# 1行だけ読むやつ

N = int(stdin.readline().rstrip().split()[0])
Sum = 0

for i in range(1, N+1):
    for j in range(i, N+1):
        for k in range(j, N+1):
            if i == j and j == k:
                Sum += i
            elif i == j or j == k or k == i:
                temp_gcd = math.gcd(i, j)
                Sum += (math.gcd(temp_gcd, k) * 3)
            else:
                Sum += (math.gcd(temp_gcd, k) * 6) 

print(Sum)
Buggy python submission (verdict: Time Limit Exceeded):
import queue

N, X, Y = map(int, input().split())

to = [[] * N for i in range(N)]

for i in range(N-1):
    to[i].append(i+1)
    to[i+1].append(i)

to[X-1].append(Y-1)
to[Y-1].append(X-1)

ans = [0] * N

for i in range(N):
    dis = [0] * N
    dis[i] = 0
    visited = [False] * N
    q = queue.Queue()
    q.put(i)
    visited[i] = True

    while not q.empty():
        tmp_v = q.get()
        for j in to[tmp_v]:
            if not visited[j]:
                dis[j] = dis[tmp_v] + 1
                visited[j] = True
                q.put(j)

    for j in range(N):
        ans[dis[j]] += 1

for i in range(1,N):
    print(ans[i]//2)

Fixed submission:
from collections import deque

N, X, Y = map(int, input().split())

to = [[] * N for i in range(N)]

for i in range(N-1):
    to[i].append(i+1)
    to[i+1].append(i)

to[X-1].append(Y-1)
to[Y-1].append(X-1)

ans = [0] * N

for i in range(N):
    dis = [0] * N
    dis[i] = 0
    visited = [False] * N
    q = deque([])
    q.append(i)
    visited[i] = True

    while len(q) != 0:
        tmp_v = q.popleft()
        for j in to[tmp_v]:
            if not visited[j]:
                dis[j] = dis[tmp_v] + 1
                visited[j] = True
                q.append(j)

    for j in range(N):
        ans[dis[j]] += 1

for i in range(1,N):
    print(ans[i]//2)

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

N, X, Y = map(int, input().split())

to = [[] * N for i in range(N)]

for i in range(N-1):
    to[i].append(i+1)
    to[i+1].append(i)

to[X-1].append(Y-1)
to[Y-1].append(X-1)

ans = [0] * N

for i in range(N):
    dis = [0] * N
    dis[i] = 0
    visited = [False] * N
    q = queue.Queue()
    q.put(i)
    visited[i] = True

    while not q.empty():
        tmp_v = q.get()
        for j in to[tmp_v]:
            if not visited[j]:
                dis[j] = dis[tmp_v] + 1
                visited[j] = True
                q.put(j)

    for j in range(N):
        ans[dis[j]] += 1

for i in range(1,N):
    print(ans[i]//2)

Fixed submission:
from collections import deque

N, X, Y = map(int, input().split())

to = [[] * N for i in range(N)]

for i in range(N-1):
    to[i].append(i+1)
    to[i+1].append(i)

to[X-1].append(Y-1)
to[Y-1].append(X-1)

ans = [0] * N

for i in range(N):
    dis = [0] * N
    dis[i] = 0
    visited = [False] * N
    q = deque([])
    q.append(i)
    visited[i] = True

    while len(q) != 0:
        tmp_v = q.popleft()
        for j in to[tmp_v]:
            if not visited[j]:
                dis[j] = dis[tmp_v] + 1
                visited[j] = True
                q.append(j)

    for j in range(N):
        ans[dis[j]] += 1

for i in range(1,N):
    print(ans[i]//2)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

is_frontR = True
for i in range(Q):
    tmp_Q = input().split()

    if len(tmp_Q) == 1:
        is_frontR = not is_frontR
        
    else:
        if tmp_Q[1] == "1":
            if is_frontR:
                S = tmp_Q[2] + S
            else:
                S = S + tmp_Q[2]
        else:
            if is_frontR:
                S = S + tmp_Q[2]
            else:
                S = tmp_Q[2] + S

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

Fixed submission:
S = input()
Q = int(input())

is_reversed = False
head = ""

for i in range(Q):
    tmp_Q = input().split()

    if len(tmp_Q) == 1:
        is_reversed = not is_reversed
        
    else:
        if tmp_Q[1] == "1":
            if is_reversed:
                S = S + tmp_Q[2]
            else:
                head = head + tmp_Q[2]
        else:
            if is_reversed:
                head = head + tmp_Q[2]
            else:
                S = S + tmp_Q[2]

if is_reversed:
    print(S[::-1] + head)
else:
    print(head[::-1] + S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

for i in range(Q):
    tmp_Q = input().split()

    if len(tmp_Q) == 1:
        S = S[::-1]
    else:
        if tmp_Q[1] == "1":
            S = tmp_Q[2] + S
        else:
            S = S + tmp_Q[2]

print(S)

Fixed submission:
S = input()
Q = int(input())

is_reversed = False
head = ""

for i in range(Q):
    tmp_Q = input().split()

    if len(tmp_Q) == 1:
        is_reversed = not is_reversed
        
    else:
        if tmp_Q[1] == "1":
            if is_reversed:
                S = S + tmp_Q[2]
            else:
                head = head + tmp_Q[2]
        else:
            if is_reversed:
                head = head + tmp_Q[2]
            else:
                S = S + tmp_Q[2]

if is_reversed:
    print(S[::-1] + head)
else:
    print(head[::-1] + S)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Q_list = [input().split() for i in range(Q)]

for tmp_Q in Q_list:
    if len(tmp_Q) == 1:
        S = S[::-1]
    else:
        if tmp_Q[1] == "1":
            S = tmp_Q[2] + S
        else:
            S = S + tmp_Q[2]

print(S)

Fixed submission:
S = input()
Q = int(input())

is_reversed = False
head = ""

for i in range(Q):
    tmp_Q = input().split()

    if len(tmp_Q) == 1:
        is_reversed = not is_reversed
        
    else:
        if tmp_Q[1] == "1":
            if is_reversed:
                S = S + tmp_Q[2]
            else:
                head = head + tmp_Q[2]
        else:
            if is_reversed:
                head = head + tmp_Q[2]
            else:
                S = S + tmp_Q[2]

if is_reversed:
    print(S[::-1] + head)
else:
    print(head[::-1] + S)
Buggy python submission (verdict: Runtime Error):
N = input()

print(N//2 + N % 2)

Fixed submission:
N = int(input())
 
print(N//2 + N % 2)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(4100000)

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

to = [[] for i in range(N)]
block = [[] for i in range(N)]
sets = []

is_visited = [False] * N
graph_g = [None] * N
graph_cnt = -1

def dfs(s, g):
    global graph_cnt
    if is_visited[s]:
        return graph_g[s]

    is_visited[s] = True
    if g == None:
        graph_cnt += 1
        graph_g[s] = graph_cnt
    else:
        graph_g[s] = g

    for edge in to[s]:
        dfs(edge, graph_cnt)


for i in range(M):
    A, B = map(int, input().split())
    to[A-1].append(B-1)
    to[B-1].append(A-1)

for i in range(K):
    C, D = map(int, input().split())
    block[C-1].append(D-1)
    block[D-1].append(C-1)

for i in range(N):
    dfs(i, None)

group_to_idx = [set() for i in range(graph_cnt+1)]
if len(group_to_idx) != 0:
    for i in range(N):
        group_to_idx[graph_g[i]].add(i)

ret = []
for i in range(N):
    cand = len(group_to_idx[graph_g[i]])
    fri = len(to[i])
    tmp_block = len(group_to_idx[graph_g[i]] & set(block[i]))

    tmp_ret = cand - fri - tmp_block - 1
    ret.append(tmp_ret)

print(*ret)

Fixed submission:
N = int(input())
 
print(N//2 + N % 2)