Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
K = int(input())
A, B = map(int, input())
c = 0

for i in range(A, B+1):
    if i % K == 0:
       c += 1
if c > 0:
    print("OK")
else:
    print("NG")

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

for i in range(A, B+1):
    if i % K == 0:
       c += 1
if c > 0:
    print("OK")
else:
    print("NG")
Buggy python submission (verdict: Time Limit Exceeded):
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019 # mod 2019での結果を入れる箱（0 ~ 2018）
counts[0] = 1 # T_n = 0　のとき

num, d = 0, 1

for char in s:
    num += int(char) * d # 一の位から順に足していく
    d *= 10
    counts[num % 2019] += 1
    
ans = 0
for cnt in counts:
    ans += cnt * (cnt-1) //2 # n_C_2 
    
print(ans)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
cnt = 0

for i in range(N-3):
    for j in range(i+3,N+1):
        if int(S[i:j]) % 2019 == 0:
            cnt += 1

print(cnt)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
cnt = 0

for i in range(N):
    if N - i - 1 >= 3:
        for j in range(i+3,N):
            if int(S[i:j+1]) % 2019 == 0:
                cnt += 1
            
print(cnt)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
cnt = 0

for i in range(N):
    for j in range(i+1,N):
        if len(S[i:j+1]) >= 4:
            if int(S[i:j+1]) % 2019 == 0:
                cnt += 1
            
print(cnt)

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = len(S)
cnt = 0

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

Fixed submission:
s = input()[::-1] # 入力文字列を逆順でsに格納

counts = [0] * 2019
counts[0] = 1

num, d = 0, 1

for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d%= 2019
    counts[num] += 1

ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())
ans = 0 

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += math.gcd(math.gcd(a,b), c)
print(ans)

Fixed submission:
from math import gcd

K = int(input())
ans = 0 

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b), c)
print(ans)

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

s = [i for i in range(1,int(input())+1)]
ans = 0 

for a in s:
    for b in s:
        for c in s:
            ans += math.gcd(math.gcd(a,b), c)
print(ans)

Fixed submission:
from math import gcd

K = int(input())
ans = 0 

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b), c)
print(ans)

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

s = [i for i in range(1,int(input())+1)]
ans = 0 

for a in s:
    for b in s:
        for c in s:
            ans += math.gcd(math.gcd(a,b), math.gcd(b,c))
print(ans)

Fixed submission:
from math import gcd

K = int(input())
ans = 0 

for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            ans += gcd(gcd(a,b), c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

distance = []
for i in range(N-1):
    distance.append(A[i+1] - A[i])
distance.append(K - A[-1] + A[0])

for i in range(N):
    if distance[i] == max(distance):
        start = i

ans = K - max(distance)
print(ans)

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

distance = []
for i in range(N-1):
    distance.append(A[i+1] - A[i])
distance.append(K - A[-1] + A[0])

ans = K - max(distance)
print(ans)

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

distance = []
for i in range(N-1):
    distance.append(A[i+1] - A[i])
distance.append(K - A[-1] + A[0])

for i in range(N):
    if distance[i] == max(distance):
        start = i

ans = K - max(distance)
print(ans)

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

distance = []
for i in range(N-1):
    distance.append(A[i+1] - A[i])
distance.append(K - A[-1] + A[0])

ans = K - max(distance)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

ans = [0] * N
comb = list(itertools.combinations(range(1,N+1),2))


for i in range(len(comb)):
    if comb[i][0] <= X and comb[i][1] >= Y:
        k = comb[i][1] - Y + X - comb[i][0]  + 1
        ans[k] += 1
    elif comb[i][0] <= X:
        k = X - comb[i][0] + min(comb[i][1] - X, Y - comb[i][1]+1)
        ans[k] += 1
    elif comb[i][1] >= Y:
        k = comb[i][1] - Y + min(Y - comb[i][0], comb[i][0] - X + 1)
        ans[k] += 1
    else:
        k = min(comb[i][1] - comb[i][0], comb[i][0] - X + Y - comb[i][1] + 1)
        ans[k] += 1
for i in range(1,N):
    print(ans[i])

Fixed submission:
import itertools

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

ans = [0] * N
comb = list(itertools.combinations(range(1,N+1),2))


for i in range(len(comb)):
    if comb[i][0] <= X and comb[i][1] >= Y:
        k = comb[i][1] - Y + X - comb[i][0]  + 1
        ans[k] += 1
    elif comb[i][0] <= X:
        k = X - comb[i][0] + min(comb[i][1] - X, Y - comb[i][1]+1)
        ans[k] += 1
    elif comb[i][1] >= Y:
        k = comb[i][1] - Y + min(Y - comb[i][0], comb[i][0] - X + 1)
        ans[k] += 1
    else:
        k = min(comb[i][1] - comb[i][0], comb[i][0] - X + Y - comb[i][1] + 1)
        ans[k] += 1
for i in range(1,N):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
ans = 0
c = Counter(A)

for i in A:
    ans = 0
    for key in c:
        if key == i:
            tmp = c[key] - 1
            ans += tmp*(tmp-1) // 2
        else:
            ans += c[key]*(c[key]-1) // 2
    print(ans)

Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
ans = 0
c = Counter(A)

for v in c.values():
    ans += v*(v-1)//2

for i in A:
    print(ans - (c[i] - 1))
Buggy python submission (verdict: Runtime Error):
d = { 'a':input(), 'b':input(), 'c':input() }
pointer = 'a'
while True:
    if 0 < len(d[pointer]):
        tmp = d[pointer][0]
        d[pointer] = s[pointer][1:]
        pointer = tmp
    else:
        print(pointer.upper())
        break

Fixed submission:
SA = input()
SB = input()
SC = input()

pointer = SA[0]
SA = SA[1:]
d = {'a': SA, 'b': SB, 'c': SC}

while True:
    if d[pointer] == '':
        ans = pointer
        break
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp

print(ans.upper())

Buggy python submission (verdict: Runtime Error):
SA = input()
SB = input()
SC = input()

pointer = SA[0]
SA = SA[1:]
d = {'a': SA, 'b': SB, 'c': SC}

while True:
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp
    if d[pointer] == '':
        ans = pointer
        break

print(ans.upper())

Fixed submission:
SA = input()
SB = input()
SC = input()

pointer = SA[0]
SA = SA[1:]
d = {'a': SA, 'b': SB, 'c': SC}

while True:
    if d[pointer] == '':
        ans = pointer
        break
    tmp = d[pointer][0]
    d[pointer] = d[pointer][1:]
    pointer = tmp

print(ans.upper())
Buggy python submission (verdict: Time Limit Exceeded):
X,K,D = [int(x) for x in input().split()]

for i in range(K):
    if abs(X - D) < abs(X + D):
        X -= D
    else:
        X += D

print(abs(X))

Fixed submission:
X,K,D = [int(x) for x in input().split()]

if D * K < abs(X):
    print(abs(X) - D * K)
else:
    if (K - abs(X) // D) % 2 == 0:
        print(abs(X) % D)
    else:
        print(D - abs(X) % D)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
s = input()

ans = N
for i in range(N + 1):
    w = s[0:i].count("W")
    r = s[i:N].count("R")
    ans = min(ans, max(w, r))

print(ans)

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

w = 0
r = s.count('R')
ans = min(N, r)

for i in range(N):
    if s[i] == 'R':
        r -= 1
    else:
        w += 1
    ans = min(ans, max(w, r))

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

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])

L = np.max(A)

ans = L
for l in range(1, L):
    counter = np.sum(A // l)
    if counter <= K:
        ans = l
        break

print(ans)

Fixed submission:
import numpy as np

N, K = [int(x) for x in input().split()]
A = np.array([int(x) for x in input().split()])
I = np.array([1] * N)

L = np.max(A)

ans = L
low = 1
high = L
while 1:
    if low == high:
        ans = low
        break
    
    mid = (low + high) // 2
    if np.sum((A - I) // mid) <= K:
        high = mid
    else:
        low = mid + 1

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

alph = ['z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',\
     'k', 'l', 'm', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',\
         'x', 'y']

seq = []

while N > 0:
    s = N % 26
    N //= 26
    seq.append(s)
L = len(seq)

name = ''

for i in range(L):
    name = alph[seq[i]] + name

print(name)

Fixed submission:
N = int(input())

alph = ['z', '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']

seq = []

while N > 0:
    s = N % 26
    N  = (N - 1) // 26
    seq.append(s)
L = len(seq)

name = ''

for i in range(L):
    name = alph[seq[i]] + name

print(name)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

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

def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] <= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

while len(A) > 1:
    B = []
    for i in range(len(A) // 2):
        B.append(merge(A[2 * i], A[2 * i + 1]))
    if len(A) % 2 == 1:
        B.append(A[len(A) - 1])
    A = B

A = A[0]
check = [True for _ in range(N)]

for i in range(N):
    if check[i] == True:
        a = A[i]
        for j in range(i + 1, N):
            if check[j] == True:
                if A[j] % a == 0:
                    check[j] = False
                    if j == i + 1:
                        if A[j] <= a:
                            check[i] = False

ans = check.count(True)
                            
print(ans)

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

count = [0] * (M + 1)
for i in range(N):
    count[A[i]] += 1

check = [True] * (M + 1)
for a in range(1, M + 1):
    if count[a] > 0 and check[a] == True:
        for k in range(2, M // a + 1):
            check[a * k] = False      

ans = 0
for i in range(N):
    if count[A[i]] == 1 and check[A[i]] == True:
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(N):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)

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

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(x) for x in input().split()]

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False

if ok == True or ans == 0:
    print(ans)
else:
    print(-1)

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

ans = 1

ok = True
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        ok = False
        break

for i in range(n):
    if a[i] == 0:
        ok = True
        ans = 0

if ok == True:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
import math

N = int(input())

ans = 0
check = [True for _ in range(10 ** 6)]

for p in range(2, 10 ** 6):
    if check[p] == True:
        for j in range(2, (10 ** 6) // p + 1):
            check[p * j] = False

        e = 1
        while N % (p ** e) == 0:
            N = N // (p ** e)
            e += 1
            ans += 1

if ans == 0:
    if N == 1:
        print(0)
    else:
        print(1)
else:
    print(ans)

Fixed submission:
import math
 
N = int(input())
 
M = int(math.sqrt(N))

ans = 0 
check = [True for _ in range(M + 1)]
e = [0 for _ in range(M + 1)]

for p in range(2, M + 1):
    if check[p] == True:
        for j in range(2, M // p + 1):
            check[p * j] = False

        while N % p == 0:
            N = N // p
            e[p] += 1
        
        ans += int((math.sqrt(1 + 8 * e[p]) - 1)/2)

if N > 1:
    ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):

def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] <= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

def merge_sort(A):
    while len(A) > 1:
        B = []
        for i in range(len(A) // 2):
            B.append(merge(A[2 * i], A[2 * i + 1]))
        if len(A) % 2 == 1:
            B.append(A[len(A) - 1])
        A = B

    return(A[0])

N = int(input())
A = []
B = []

for i in range(N):
    a, b = [[int(x)] for x in input().split()]
    A.append(a)
    B.append(b)

C = merge_sort(A)
D = merge_sort(B)

if N % 2 == 0:
    ans = D[N//2 - 1] + D[N//2] - C[N//2 - 1] - C[N//2] + 1
else: # N % 2 == 1
    ans = D[N//2] - C[N//2] + 1

print(ans)

Fixed submission:
import numpy as np

N = int(input())
A = []
B = []

for i in range(N):
    a, b = [int(x) for x in input().split()]
    A.append(a)
    B.append(b)

C = np.array(A)
D = np.array(B)

m_inf = np.median(C)
m_sup = np.median(D)

if N % 2 == 0:
    ans = 2 * m_sup - 2 * m_inf + 1
else:
    ans = m_sup - m_inf + 1

print(int(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

M = max(A) + N

counter = [0] * (M + 1)

ans = 0
for i in range(N):
    if i > A[i]:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)

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

counter = {}

for i in range(N):
    counter[i + A[i]] = 0

ans = 0
for i in range(N):
    if i - A[i] in counter:
        ans += counter[i - A[i]]
    counter[i + A[i]] += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
    T = (T + R * int(S[n - i - 1])) % 2019
    R = 10 * R % 2019
    counter[T] += 1

ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2

print(ans)

Fixed submission:
S = input()
N = len(S)
 
counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
    T = (T + R * int(S[N - i - 1])) % 2019
    R = 10 * R % 2019
    counter[T] += 1
 
ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2
 
print(ans)

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

counter = [0] * 2019
counter[0] = 1
T = 0
for i in range(N):
    T = ((10 ** i) * int(S[N - i - 1]) + T) % 2019
    counter[T] += 1

ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2

print(ans)

Fixed submission:
S = input()
N = len(S)
 
counter = [0] * 2019
counter[0] = 1
T = 0
R = 1
for i in range(N):
    T = (T + R * int(S[N - i - 1])) % 2019
    R = 10 * R % 2019
    counter[T] += 1
 
ans = 0
for i in range(2019):
    m = counter[i]
    ans += m * (m - 1) // 2
 
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(a, d, n):

    if n == 0:
        fans = ''
        for i in range(d):
            fans = fans + str(max(0, int(a) - i))

    else:
        s = f(a, d, n - 1)
        k = 0
        for j in range(d - 1):
            if s[d - 2 - j] >= s[d - 1 - j]:
                k = d - 1 - j
                break

        t = f(str(int(s[d - 1 - j]) + 1), j + 1, 0)
        fans = s[:k] + t
    
    return fans

lnln = [[0] * 10 for _ in range(10 + 1)]
lnln[1] = [1] * 10

for i in range(2, 10 + 1):
    for j in range(10):
        if j == 0:
            lnln[i][0] = lnln[i - 1][0] + lnln[i - 1][1]
        elif j == 9:
            lnln[i][9] = lnln[i - 1][8] + lnln[i - 1][9]
        else:
            lnln[i][j] = lnln[i - 1][j - 1] + lnln[i - 1][j] + lnln[i - 1][j + 1]

N = int(input())
S = 0
ok = False
for i in range(1, 10 + 1):
    for j in range(1, 10):
        if S + lnln[i][j] >= N:
            d, a, n = i, j, N - S - 1
            ok = True
            break
        else:
            S += lnln[i][j]
    if ok == True:
        break

ans = int(f(str(a), d, n))

print(ans)

Fixed submission:
from collections import deque

N = int(input())

Q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(N - 1):
    x = Q.popleft()
    if x % 10 != 0:
        y = 10 * x + x % 10 - 1
        Q.append(y)
    
    y = 10 * x + x % 10
    Q.append(y)

    if x % 10 != 9:
        y = 10 * x + x % 10 + 1
        Q.append(y)

ans = Q.popleft()

print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque

X, Y, A, B, C = [int(x) for x in input().split()]
p = deque(sorted([int(x) for x in input().split()]))
q = deque(sorted([int(x) for x in input().split()]))
r = deque(sorted([int(x) for x in input().split()]))

ans = 0
for i in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()

for i in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)

Fixed submission:
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]

s = sorted(p + q + r, reverse=True)

ans = sum(s[:X + Y])

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque

def merge(s, t):
    u = []

    while s + t:
        
        if s == [] or t == []:
            return u + s + t

        if s[0] >= t[0]:
            u.append(s[0])
            s = s[1:]
        else: # s0 > t0
            u.append(t[0])
            t = t[1:]

    return u

def merge_sort(A):
    while len(A) > 1:
        B = []
        for _ in range(len(A) // 2):
            B.append(merge(A[0], A[1]))
            A = A[2:]
        B += A
        A = B

    return(A[0])

X, Y, A, B, C = [int(x) for x in input().split()]
p = deque(merge_sort([[int(x)] for x in input().split()]))
q = deque(merge_sort([[int(x)] for x in input().split()]))
r = deque(merge_sort([[int(x)] for x in input().split()]))

ans = 0
for i in range(X):
    if p[0] >= r[0]:
        ans += p.popleft()
    else:
        ans += r.popleft()

for i in range(Y):
    if q[0] >= r[0]:
        ans += q.popleft()
    else:
        ans += r.popleft()

print(ans)

Fixed submission:
X, Y, A, B, C = [int(x) for x in input().split()]
p = sorted([int(x) for x in input().split()], reverse=True)[:X]
q = sorted([int(x) for x in input().split()], reverse=True)[:Y]
r = sorted([int(x) for x in input().split()], reverse=True)[:X + Y]

s = sorted(p + q + r, reverse=True)

ans = sum(s[:X + Y])

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())

c2 = 0
query = []
for i in range(Q):
    q = [x for x in input().split()]
    T = int(q[0])
    if T == 1:
        query.append([T])
    else: # T == 2
        F, C = int(q[1]), q[2]
        query.append([T, F, C])
        c2 += 1

while len(query) > c2 + 1:
    print(query)
    T1 = query[i][0]
    if T1 == 1:
        T2 = query[i + 1][0]
        if T2 == 1:
            query = query[:i] + query[i + 2:]
        if T2 == 2:
            F, C = query[i + 1][1], query[i + 1][2]
            if F == 1:
                query[i] = [2, 2, C]
                query[i + 1] = [1]
            else: # F == 2
                query[i] = [2, 1, C]
                query[i + 1] = [1]

M = c2 + 1
for i in range(M):
    T = query[i][0]
    if T == 1:
        L = len(S)
        S = S[L - 1::-1]
    else: # T == 2
        F, C = query[i][1], query[i][2]
        if F == 1:
            S = C + S
        else: # F == 2
            S = S + C

print(S)

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

cond = [None for _ in range(N + 1)]
ok = True
for i in range(M):
    s, c = [int(x) for x in input().split()]
    if cond[s] == None:
        cond[s] = c
    else:
        if cond[s] != c:
            ok = False
            break

if cond[1] == None:
    if N == 1:
        cond[1] = 0
    else:
        cond[1] = 1
else:
    if cond[1] == 0:
        if N != 1:
            ok = False

for i in range(2, N + 1):
    if cond[i] == None:
        cond[i] = 0

if ok == True:
    for i in range(1, N + 1):
        print(cond[i], end='')
    print('')
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
N, M = [int(x) for x in input().split()]

P = [0] * (N + 1)
correct = 0
ok = [False] * (N + 1)
for i in range(M):
    query = input().split()
    p = int(query[0])
    S = query[1]
    if ok[p] == False:
        if S == 'AC':
            ok[p] = True
            correct += 1
        else: # S = 'WA'
            P[p] += 1

penalty = 0
for i in range(N):
    if ok[p] == True:
        penalty += P[p]

print(correct, end=' ')
print(penalty)

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

P = [0] * (N + 1)           #各問題のペナルティの回数を記録
ok = [False] * (N + 1)      #その問題でACが出たかどうか記録

correct = 0                 #正答数を記録
penalty = 0                 #ペナルティ数を記録
for i in range(M):
    query = input().split()
    p = int(query[0])
    S = query[1]
    if ok[p] == False:
        if S == 'AC':
            ok[p] = True
            correct += 1
            penalty += P[p]
        else: # S = 'WA'
            P[p] += 1

print(correct, end=' ')
print(penalty)