Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
x = [None for _ in range(N)]
y = [None for _ in range(N)]
h = [None for _ in range(N)]
hh = [0 for _ in range(N)]
flag = False
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())
for cx in range(0, 101):
    for cy in range(0, 101):
        for i in range(N):
            hh[i] = h[i] + abs(x[i] - cx) + abs(y[i] - cy)
            if hh[i] < 1:
                hh[i] = None
        if (min(hh) == max(hh)) and (min(hh) >= 1):
            print(cx, cy, hh[0])
            exit()

Fixed submission:
N = int(input())
x = [None for _ in range(N)]
y = [None for _ in range(N)]
h = [None for _ in range(N)]
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())
    if h[i] > 0:
        a = [x[i], y[i], h[i]]
for cx in range(0, 101):
    for cy in range(0, 101):
        hh = a[2] + abs(a[0] - cx) + abs(a[1] - cy)
        flag = True
        for i in range(N):
            h_i = max(hh - abs(x[i] - cx) - abs(y[i] - cy), 0)
            if h_i != h[i]:
                flag = False
        if flag:
            print(cx, cy, hh)
            exit()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common(2)
b = Counter(v[1::2]).most_common(2)
if a[0][0] == b[0][0]:
    if a[1][1] > b[1][1]:
        print(n - a[1][1] - b[0][1])
    else:
        print(n - a[0][1] - b[1][1])
else:
    print(n- a[0][1] - b[0][1])

Fixed submission:
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
a = Counter(v[::2]).most_common()
b = Counter(v[1::2]).most_common()
if len(a) == 1:
    a.append([0, 0])
if len(b) == 1:
    b.append([0, 0])
if a[0][0] == b[0][0]:
    if a[1][1] > b[1][1]:
        print(n - a[1][1] - b[0][1])
    else:
        print(n - a[0][1] - b[1][1])
else:
    print(n- a[0][1] - b[0][1])
Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
n, x0 = map(int, input().split())
x = np.abs(np.array(list(map(int, input().split()))) - x0)
xx = x[0]
for i in range(1, n):
    xx = math.gcd(xx, x[i])
print(xx)

Fixed submission:
from fractions import gcd
import numpy as np
n, x0 = map(int, input().split())
x = np.abs(np.array(list(map(int, input().split()))) - x0)
xx = x[0]
for i in range(1, n):
    xx = gcd(xx, x[i])
print(xx)

Buggy python submission (verdict: Runtime Error):
import math
import numpy as np
n, x0 = map(int, input().split())
x = np.array(list(map(int, input().split()))) - x0
xx = x[0]
for i in range(1, n):
    xx = math.gcd(xx, x[i])
print(xx)

Fixed submission:
from fractions import gcd
import numpy as np
n, x0 = map(int, input().split())
x = np.abs(np.array(list(map(int, input().split()))) - x0)
xx = x[0]
for i in range(1, n):
    xx = gcd(xx, x[i])
print(xx)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0] + [sum(A[:i+1]) % M for i in range(N)]
B.sort()
ans = 0
k = 1
C = []
for i in range(N):
    if B[i] == B[i + 1]:
        k += 1
    else:
        C.append(k)
        k = 1
C.append(k)
for k in C:
    if k > 1:
        ans += k * (k - 1) // 2
print(ans)

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
b = 0
for i in range(N):
    b += A[i]
    B.append(b % M)
B.sort()
ans = 0
k = 1
C = []
for i in range(N):
    if B[i] == B[i + 1]:
        k += 1
    else:
        C.append(k)
        k = 1
C.append(k)
for k in C:
    if k > 1:
        ans += k * (k - 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
k = 0
if S[0] == 'A' and S[3:-1].count('C') == 1:
    for i in range(len(S)):
        if S[i].isupper()
            if k == 2:
                print('WA')
                break
            k += 1
    print('AC')
else:
    print('WA')

Fixed submission:
S = input()
k = 0
if S[0] == 'A' and S[2:-1].count('C') == 1:
    for i in range(len(S)):
        if S[i].isupper():
            if k == 2:
                print('WA')
                exit()
            k += 1
    print('AC')
else:
    print('WA')
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split())).sort()
print(a[-1] - a[0])

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
a.sort()
print(a[-1] - a[0])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
ans = N
for i in range(N):
    x = S[:i].count('W') + S[i + 1:].count('E')
    if x < ans:
        ans = x
print(ans)

Fixed submission:
N = int(input())
S = input()
ans = N
x = 0
y = S.count('E')
for i in range(N):
    if S[i-1] == 'W' and i > 0:
        x += 1
    if S[i] == 'E':
        y -= 1
    if x + y < ans:
        ans = x + y
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = [['#' for _ in range(w + 2)]]
s = s + [['#'] + list(input()) + ['#'] for _ in range(h)]
s = s + [['#' for _ in range(w + 2)]]
n_white = 0
for i in range(1, h + 1):
    n_white += s[i].count('.')
q = [[1, 1]]
a = []
d = 1
while(True):
    qq = []
    for i in range(len(q)):
        x = q[i][0]
        y = q[i][1]
        if s[x][y - 1] == '.' and [x, y - 1] not in a:
            qq.append([x, y - 1])
        if s[x - 1][y] == '.' and [x - 1, y] not in a:
            qq.append([x - 1, y])
        if s[x + 1][y] == '.' and [x + 1, y] not in a:
            qq.append([x + 1, y])
        if s[x][y + 1] == '.' and [x, y + 1] not in a:
            qq.append([x, y + 1])
    d += 1
    if [h, w] in qq:
        break
    elif qq == []:
        print(-1)
        exit()
    a = a + qq
    q = qq
print(n_white - d)

Fixed submission:
h, w = map(int, input().split())
s = [['#' for _ in range(w + 2)]]
s = s + [['#'] + list(input()) + ['#'] for _ in range(h)]
s = s + [['#' for _ in range(w + 2)]]
n_white = 0
for i in range(1, h + 1):
    n_white += s[i].count('.')
q = [[1, 1]]
a = []
d = 1
while(True):
    qq = []
    for i in range(len(q)):
        if q[i] in a:
            continue
        x = q[i][0]
        y = q[i][1]
        if s[x][y - 1] == '.' and [x, y - 1] not in qq:
            qq.append([x, y - 1])
        if s[x - 1][y] == '.' and [x - 1, y] not in qq:
            qq.append([x - 1, y])
        if s[x + 1][y] == '.' and [x + 1, y] not in qq:
            qq.append([x + 1, y])
        if s[x][y + 1] == '.' and [x, y + 1] not in qq:
            qq.append([x, y + 1])
    d += 1
    if [h, w] in qq:
        break
    elif qq == []:
        print(-1)
        exit()
    a = a + q
    q = qq
print(n_white - d)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
tt = 0
xx = 0
yy = 0
flag = True
z = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
    t, x, y = z[i]
    s = [[xx, yy]]
    for j in range(t - tt):
        ss = []
        for k in range(len(s)):
            ss.append([s[k][0] + 1, s[k][1]])
            ss.append([s[k][0] - 1, s[k][1]])
            ss.append([s[k][0], s[k][1] + 1])
            ss.append([s[k][0], s[k][1] - 1])
        s = ss
    if [x, y] in s:
        tt = t
        xx = x
        yy = y
    else:
        print('No')
        exit()
print('Yes')

Fixed submission:
N = int(input())
tt = 0
xx = 0
yy = 0
z = [list(map(int, input().split())) for _ in range(N)]
for i in range(N):
    t, x, y = z[i]
    dt = t - tt
    dx = abs(x - xx)
    dy = abs(y - yy)
    if dt < dx + dy or (dt - (dx + dy)) % 2:
        print('No')
        exit()
    tt = t
    xx = x
    yy = y
print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list(set(a))
ans = 0
for i in b:
    c = a.count(i)
    if c < i:
        ans += c
    if c > i:
        ans += c - i
print(ans)

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

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list(set(a))
ans = 0
for i in b:
    c = a.count(i)
    if i > n or c < i:
        ans += c
    if c > i:
        ans += c - i
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
ans = 0
for i in d:
    if d[i] < i:
        ans += d[i]
    if d[i] > i:
        ans += d[i] - i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
bi = [n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if b[i] <= a[j]:
            bi[i] = j
            break
ans = 0
for i in range(n):
    for j in range(n):
        if c[i] <= b[j]:
            break
        else:
            ans += bi[j]
print(ans)

Fixed submission:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0;
for bj in b:
    ai = bisect.bisect_left(a, bj);
    ck = n - bisect.bisect_right(c, bj);
    ans += ai * ck;
print(ans)
Buggy python submission (verdict: Runtime Error):
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += ss[j]
        print(s)
        exit()
print('UNRESTORABLE')


Fixed submission:
sp = list(input())
t = list(input())
n = len(sp)
s = []
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s.append('')
        ss = sp
        ss[n - i:n - i + len(t)] = t
        for j in range(n):
            if ss[j] == '?':
                s[-1] += 'a'
            else:
                s[-1] += ss[j]
if s == []:
    print('UNRESTORABLE')
else:
    s.sort()
    print(s[0])
Buggy python submission (verdict: Runtime Error):
a, b, c, d, e, f = map(int, input().split())
x = []
y = []
t = 100 * e / (100 + e)
for i in range(f // (100 * a) + 1):
    bb = f - 100 * a * i
    for j in range(bb // (100 * b) + 1):
        if 100 * (a * i + b * j) in x:
            continue
        else:
            x.append(100 * (a * i + b * j))
for i in range(f // c + 1):
    dd = f - c * i
    for j in range(dd // d + 1):
        if c * i + d * j in y:
            continue
        else:
            y.append(c * i + d * j)
y.sort()
rr = 0
ans = []
for i, xi in enumerate(x):
    for j, yi in enumerate(y):
        if xi + yi == 0:
            continue
        r = 100 * yi / (xi + yi)
        if r > t:
            break
        elif xi + yi <= f and rr < r:
            ans = [xi + yi, yi]
            rr = r
print(ans[0], ans[1])

Fixed submission:
a, b, c, d, e, f = map(int, input().split())
x = []
y = []
t = 100 * e / (100 + e)
for i in range(f // (100 * a) + 1):
    bb = f - 100 * a * i
    for j in range(bb // (100 * b) + 1):
        if 100 * (a * i + b * j) in x:
            continue
        else:
            x.append(100 * (a * i + b * j))
for i in range(f // c + 1):
    dd = f - c * i
    for j in range(dd // d + 1):
        if c * i + d * j in y:
            continue
        else:
            y.append(c * i + d * j)
y.sort()
rr = 0
ans = []
for i, xi in enumerate(x):
    for j, yi in enumerate(y):
        if xi + yi == 0:
            continue
        r = 100 * yi / (xi + yi)
        if r > t:
            break
        elif xi + yi <= f and rr <= r:
            ans = [xi + yi, yi]
            rr = r
print(ans[0], ans[1])
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
X = [[0 for j in range(w)] for i in range(h)]

xi = -1
hi = 0
for i, ai in enumerate(a):
    for j in range(xi + 1, min(xi + ai + 1, w)):
        X[hi][j] = i + 1
    if j == w - 1:
        hi += 1
        j = -1
        for j in range(max(0, xi + ai + 1 - w)):
            X[hi][j] = i + 1
    xi = j

for i in range(h):
    if i % 2 == 0:
        print(*X[i])
    else:
        print(*X[i][::-1])

Fixed submission:
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
m = h * w
X = []

for i, ai in enumerate(a):
    X += [i + 1 for _ in range(ai)]

for hi in range(h):
    if hi % 2 == 0:
        print(*X[hi * w:(hi + 1) * w])
    else:
        print(*X[hi * w:(hi + 1) * w][::-1])

Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
X = [[0 for j in range(w)] for i in range(h)]

xi = -1
hi = 0
for i, ai in enumerate(a):
    for j in range(xi + 1, min(xi + ai + 1, w)):
        X[hi][j] = i + 1
    if j == w - 1:
        hi += 1
        j = -1
        for j in range(max(0, xi + ai + 1 - w)):
            X[hi][j] = i + 1
    xi = j

for i in range(h):
    if i % 2 == 0:
        print(*X[i])
    else:
        print(*X[i][::-1])

Fixed submission:
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
m = h * w
X = []

for i, ai in enumerate(a):
    X += [i + 1 for _ in range(ai)]

for hi in range(h):
    if hi % 2 == 0:
        print(*X[hi * w:(hi + 1) * w])
    else:
        print(*X[hi * w:(hi + 1) * w][::-1])
Buggy python submission (verdict: Runtime Error):
def value_and_count(x):
    d = {}
    for xi in x:
        if xi in d.keys():
            d[xi] += 1
        else:
            d[xi] = 1
    return d

def comb(n, k):
    k = min(n - k, k)
    denominator = 1 # 分母
    numerator = 1 # 分子
    for i in range(k):
        denominator *= i + 1
        numerator *= n - i
    return numerator // denominator

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
d_v = value_and_count(v)
v.sort(reverse=True)
sum_v = sum(v[:a])
print(sum_v / a)

ans = 0
d_vk = None
for k in range(a, b + 1):
    vk = v[:k]
    sum_vk = sum(vk)
    if sum_vk < sum_v:
        break

    if d_vk is None:
        d_vk = value_and_count(vk)
    else:
        d_vk[vk[-1]] += 1

    ans_k = 1
    for vi, ci in d_vk.items():
        ans_k *= comb(d_v[vi], ci)
    ans += ans_k

print(ans)


Fixed submission:
def value_and_count(x):
    d = {}
    for xi in x:
        if xi in d.keys():
            d[xi] += 1
        else:
            d[xi] = 1
    return d

def comb(n, k):
    k = min(n - k, k)
    denominator = 1 # 分母
    numerator = 1 # 分子
    for i in range(k):
        denominator *= i + 1
        numerator *= n - i
    return numerator // denominator

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
d_v = value_and_count(v)
v.sort(reverse=True)
sum_v = sum(v[:a])
mean_v = sum_v / a
print(mean_v)

ans = 0
d_vk = None
for k in range(a, b + 1):
    vk = v[:k]
    sum_vk = sum(vk)
    if sum_vk / k < mean_v:
        break

    if d_vk is None:
        d_vk = value_and_count(vk)
    else:
        d_vk[vk[-1]] += 1

    ans_k = 1
    for vi, ci in d_vk.items():
        ans_k *= comb(d_v[vi], ci)
    ans += ans_k

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
d = {0: None}
i = 0
while(True):
    flag = False
    i += 1
    d_keys = list(d.keys())
    for di in d_keys:
        xx = [di - i, di + i]
        if x in xx:
            flag = True
            break
        else:
            d[xx[0]] = None
            d[xx[1]] = None
    if flag:
        break
print(i)


Fixed submission:
x = int(input())
xx = 0
i = 1
while(True):
    xx += i
    if xx >= x:
        print(i)
        break
    else:
        i += 1
Buggy python submission (verdict: Runtime Error):
import copy

def warshall_floyd(V, E):
    INF = 10 ** 9
    d = [[[INF, []] for j in range(V + 1)] for i in range(V + 1)]
    for i, j, c in E:
        d[i][j] = [c, []]
        d[j][i] = [c, []]
    for k in range(1, V + 1):
        for i in range(1, V):
            for j in range(i, V + 1):
                dk = d[i][k][0] + d[k][j][0]
                if d[i][j][0] > dk:
                    root = copy.copy(d[i][k][1]) + [k] + copy.copy(d[k][j][1])
                    d[i][j] = [dk, root]
                    d[j][i] = [dk, root]
    return d

n, m = map(int, input().split())
E = [[None for j in range(n + 1)] for i in range(n + 1)]
E_list = []
for i in range(m):
    a, b, c = map(int, input().split())
    E_list.append([a, b, c])
    E[a][b] = 0
    E[b][a] = 0
d = warshall_floyd(n, E_list)
ans = m
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        k = i
        for r in d[i][j][1]:
            if E[r][k] == 0:
                ans -= 1
            E[r][k] += 1
            E[k][r] += 1
            k = r
        if E[j][k] == 0:
            ans -= 1
        E[j][k] += 1
        E[k][j] += 1
print(ans)

Fixed submission:
import copy

def warshall_floyd(V, E):
    INF = 10 ** 9
    d = [[[INF, 0] for j in range(V + 1)] for i in range(V + 1)]
    for i, j, c in E:
        d[i][j] = [c, 0]
        d[j][i] = [c, 0]
    for k in range(1, V + 1):
        for i in range(1, V):
            for j in range(i, V + 1):
                dk = d[i][k][0] + d[k][j][0]
                if d[i][j][0] > dk:
                    d[i][j] = [dk, k]
                    d[j][i] = [dk, k]
    return d

def find_path(i, j, d, E):
    k = d[i][j][1]
    if k == 0:
        E[i][j] += 1
        E[j][i] += 1
        return E
    E = find_path(i, k, d, E)
    E = find_path(k, j, d, E)
    return E

n, m = map(int, input().split())
E = [[None for j in range(n + 1)] for i in range(n + 1)]
E_list = []
for i in range(m):
    a, b, c = map(int, input().split())
    E_list.append([a, b, c])
    E[a][b] = 0
    E[b][a] = 0
d = warshall_floyd(n, E_list)
ans = 0
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        E = find_path(i, j, d, E)
for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        if E[i][j] == 0:
            ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, X, M = map(int,input().split())
A = [X]
Lstart = 0
for i in range(N):
    An = A[-1]**2 % M
    if An in A:
        Lstart = A.index(An)
        break
    else:
        A.append(An)
LenBefL = Lstart
LenLoop = len(A) - Lstart
if LenLoop > 0:
    ans = sum(A[:Lstart])+sum(A[Lstart:])*((N-LenBefL)//LenLoop) + sum(A[Lstart:Lstart + (N-LenBefL)%LenLoop])
else:
    ans = sum(A)
print(ans)

Fixed submission:
N, X, M = map(int,input().split())
A = [X]
As = set(A)
Lstart = 0
for i in range(N):
    An = A[-1]**2 % M
    if An in As:
        Lstart = A.index(An)
        break
    else:
        A.append(An)
        As.add(An)
LenBefL = Lstart
LenLoop = len(A) - Lstart
if LenLoop > 0:
    ans = sum(A[:Lstart])+sum(A[Lstart:])*((N-LenBefL)//LenLoop) + sum(A[Lstart:Lstart + (N-LenBefL)%LenLoop])
else:
    ans = sum(A)
print(ans)

Buggy python submission (verdict: Runtime Error):
N, X, M = map(int,input().split())
A = [X]
for i in range(N):
    An = A[-1]**2 % M
    if An in A:
        Lstart = A.index(An)
        break
    else:
        A.append(An)
LenBefL = Lstart
LenLoop = len(A) - Lstart
if LenLoop > 0:
    ans = sum(A[:Lstart])+sum(A[Lstart:])*((N-LenBefL)//LenLoop) + sum(A[Lstart:Lstart + (N-LenBefL)%LenLoop])
else:
    ans = sum(A)
print(ans)

Fixed submission:
N, X, M = map(int,input().split())
A = [X]
As = set(A)
Lstart = 0
for i in range(N):
    An = A[-1]**2 % M
    if An in As:
        Lstart = A.index(An)
        break
    else:
        A.append(An)
        As.add(An)
LenBefL = Lstart
LenLoop = len(A) - Lstart
if LenLoop > 0:
    ans = sum(A[:Lstart])+sum(A[Lstart:])*((N-LenBefL)//LenLoop) + sum(A[Lstart:Lstart + (N-LenBefL)%LenLoop])
else:
    ans = sum(A)
print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, H, M = map(int,input().split())
Ha = H*math.pi/6 + M*math.pi/360
Ma = M*math.pi/30
if Ha == Ma:
    print(abs(A-B))
else:
    print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(Ha-Ma)))

Fixed submission:
import math
A, B, H, M = map(int,input().split())
Ha = H*math.pi/6 + M*math.pi/360
Ma = M*math.pi/30
if Ha == Ma:
    print(abs(A-B))
else:
    print(math.sqrt(A**2 + B**2 - 2*A*B*math.cos(Ha-Ma)))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
Qr = [list(input().split()) for i in range(Q)]
isForward = True
for i in range(Q):
    if Qr[i][0] == "1":
        isForward = not(isForward)
    elif (isForward and  Qr[i][1] == "1") or (not(isForward) and Qr[i][1] == "2"):
        S = Qr[i][2] + S
    else:
        S = S + Qr[i][2]
if not(isForward):
    S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
Qr = [list(input().split()) for i in range(Q)]
isForward = True
for i in range(Q):
    if Qr[i][0] == "1":
        isForward = not(isForward)
    elif (isForward and  Qr[i][1] == "1") or (not(isForward) and Qr[i][1] == "2"):
        S.appendleft(Qr[i][2])
    else:
        S.append(Qr[i][2])
S = list(S)
if not(isForward):
    S.reverse()
print("".join(S))

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
if Q != 1:
    Qr = [list(input().split()) for i in range(Q)]
isForward = True
for i in range(Q):
    if Qr[i][0] == "1":
        isForward = not(isForward)
    elif (isForward and  Qr[i][1] == "1") or (not(isForward) and Qr[i][1] == "2"):
        S = Qr[i][2] + S
    else:
        S = S + Qr[i][2]
if not(isForward):
    S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
Qr = [list(input().split()) for i in range(Q)]
isForward = True
for i in range(Q):
    if Qr[i][0] == "1":
        isForward = not(isForward)
    elif (isForward and  Qr[i][1] == "1") or (not(isForward) and Qr[i][1] == "2"):
        S.appendleft(Qr[i][2])
    else:
        S.append(Qr[i][2])
S = list(S)
if not(isForward):
    S.reverse()
print("".join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int,input().split())
p = list(map(int,input().split()))
mx = 0
for i in range(N - K + 1):
    mx = max(mx, sum(p[i:i+K]))
print((K + mx)/2)

Fixed submission:
N, K = map(int,input().split())
p = list(map(int,input().split()))
mx,it = sum(p[:K]), sum(p[:K])
for i in range(N - K):
    it = it - p[i] + p[i + K]
    mx = max(mx, it)
print((K + mx)/2)
Buggy python submission (verdict: Runtime Error):
import math
a,b,x = list(map(int,input().split()))
h = x/(a**2)
if h<=b/2:
    ans =  math.degrees(math.atan(b**2/(2*a*h)))
else:
    ans = 90-math.degrees(math.atan(a/(2*(b-h))))
print(ans)

Fixed submission:
import math
a,b,x = list(map(int,input().split()))
h = x/(a**2)
if b == h:
    ans = 0
elif h<=b/2:
    ans = math.degrees(math.atan(b**2/(2*a*h)))
else:
    ans = 90-math.degrees(math.atan(a/(2*(b-h))))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int,input().split())
A = [int(input()) for i in range(Q)]

for i in range(N):
    if K + A.count(i+1) - Q > 0:
        print("Yes")
    else: print("No")

Fixed submission:
N, K, Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
ans = [K-Q]*N
for i in range(Q):
    ans[A[i]-1]+=1
for i in range(N):
    if ans[i]>0:
        print("Yes")
    else: print("No")