Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
m = np.zeros((N + 2, N + 2), dtype='int64')
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    np.add(m[:u + 1, v:], 1, out=m[:u + 1, v:])
ans = 0
for L in range(1, N + 1):
    for R in range(L, N + 1):
        ans += R - L + 1 - m[L, R]
print(ans)


Fixed submission:
N = int(input())
M = 0
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    M += u * (N - v + 1)
V = 0
for r in range(1, N + 1):
    V += r * (N - r + 1)
print(V - M)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
m = np.zeros((N + 1, N + 1), dtype='int64')
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    np.add(m[:u + 1, v:], 1,out=m[:u + 1, v:])
ans = 0
for L in range(1, N + 1):
    for R in range(L, N + 1):
        ans += R - L + 1 - m[L, R]
print(ans)


Fixed submission:
N = int(input())
M = 0
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    M += u * (N - v + 1)
V = 0
for r in range(1, N + 1):
    V += r * (N - r + 1)
print(V - M)

Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
m = np.zeros((N + 1, N + 1), dtype='int32')
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    np.add(m[:u + 1, v:], 1,out=m[:u + 1, v:])
ans = 0
for L in range(1, N + 1):
    for R in range(L, N + 1):
        ans += R - L + 1 - m[L, R]
print(ans)


Fixed submission:
N = int(input())
M = 0
for _ in range(N - 1):
    u, v = sorted(map(int, input().split()))
    M += u * (N - v + 1)
V = 0
for r in range(1, N + 1):
    V += r * (N - r + 1)
print(V - M)
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()))
acc = sum(B)
j = M - 1
if acc + sum(A) <= K:
    print(M + N)
    exit()
ans = 0
for i in range(N):
    acc += A[i]
    if acc <= K:
        ans = max(ans, i + j + 2)
        continue
    else:
        while acc > K:
            acc -= B[j]
            j -= 1
            if (j == -1) & (acc > K):
                print(ans)
                exit()
        ans = max(ans, i + j + 2)
print(ans)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if K >= sum(A) + sum(B):
    print(M + N)
    exit()
acc = 0
ans = 0
for j, b in enumerate(B):
    acc += b
    if K >= acc:
        ans = j + 1
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_acc = [0] * (N + 1)
B_acc = [0] * (M + 1)
acc = 0
for i, a in enumerate(A):
    acc += a
    A_acc[i+1] = acc
acc = 0
for i, b in enumerate(B):
    acc += b
    B_acc[i+1] = acc
ans = 0
for i in range(N + 1):
    if A_acc[i] > K:
        break
    for j in range(M,-1,-1):
        if A_acc[i] + B_acc[j] <= K:
            ans = max(ans, i + j)
            break
print(ans)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if K >= sum(A) + sum(B):
    print(M + N)
    exit()
acc = 0
ans = 0
for j, b in enumerate(B):
    acc += b
    if K >= acc:
        ans = j + 1
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
A_acc = [0]
B_acc = [0]
acc = 0
for a in A:
    acc += a
    A_acc.append(acc)
acc = 0
for b in B:
    acc += b
    B_acc.append(acc)
ans = 0
for i in range(N + 1):
    if A_acc[i] > K:
        break
    for j in range(M,-1,-1):
        if A_acc[i] + B_acc[j] <= K:
            ans = max(ans, i + j)
            break
print(ans)


Fixed submission:
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if K >= sum(A) + sum(B):
    print(M + N)
    exit()
acc = 0
ans = 0
for j, b in enumerate(B):
    acc += b
    if K >= acc:
        ans = j + 1
for i in range(N):
    acc += A[i]
    if K >= acc:
        ans = max(ans, i + j + 2)
        continue
    else:
        while (K < acc) & (j > -1):
            acc -= B[j]
            j -= 1
        if K >= acc:
            ans = max(ans, i + j + 2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
A = list(map(int, input().split()))

dp = np.ones(max(A)+1, dtype=bool)

for a in A:
    ind = [a * i for i in range(2, max(A)//a + 1)]
    dp[ind] = False
dub = [x for x in set(A) if A.count(x) > 1]
dp[dub] = False
print(sum(dp[A]))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MAX = max(A)
dp = [True for _ in range(MAX+1)]

for a in set(A):
    for k in range(2*a,MAX+1,a):
        dp[k] = False
B = sorted(A)
for i in range(len(B)-1):
    if B[i] == B[i+1]:
        dp[B[i]] = False

print(sum(dp[a] for a in set(A)))

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

B = sorted([x for x in set(A) if A.count(x) == 1])
C = [x for x in set(A) if A.count(x) > 1]
ans = 0
#自身よりも小さい数で試し割　あとに重複した要素で試し割
for i in range(len(B)):
    for b in B[:i]:
        if B[i] % b == 0:
            break
    else:
        for c in C:
            if B[i] % c == 0:
                break
        else:
            ans += 1
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
MAX = max(A)
dp = [True for _ in range(MAX+1)]

for a in set(A):
    for k in range(2*a,MAX+1,a):
        dp[k] = False
B = sorted(A)
for i in range(len(B)-1):
    if B[i] == B[i+1]:
        dp[B[i]] = False

print(sum(dp[a] for a in set(A)))
Buggy python submission (verdict: Runtime Error):
from math import cos
A, B, H, M = map(int, input().split())
t = 30 * A - 6 * B
print((A**2 + B**2 - 2*a*b*cos(t) ** .5)


Fixed submission:
from math import cos, radians
A, B, H, M = map(int, input().split())
t = 30 * (H + M / 60) - 6 * M
t = radians(t)
print((A**2 + B**2 - 2*A*B*cos(t)) ** .5)
Buggy python submission (verdict: Runtime Error):
import numpy as np
N, M, X = map(int, input().split())
A = []
C = []
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)
A = np.array(A,dtype=int)
ans = 10 ** 7
for bit in range(2 ** N):
    B = np.zeros(M, dtype=int)
    cost = 0
    for i in range(N):
        if bit & (1<<i):
            B += A[i]
            cost += C[i]
    if np.all(B >= X):
        ans = min(ans, cost)
print(ans if ans < 10**7 else -1)


Fixed submission:
N, K = map(int, input().split())
G = [[] for _ in range(N)]
for i, a in enumerate(map(int, input().split())):
    G[i] = a - 1
now = 0
seen = set()
#ループが始まる町とそれまでの移動回数iを求める
for i in range(1, K+1):
    seen.add(now)
    now = G[now]
    if now in seen:
        break
K -= i
if K > 0:
    #ループの移動回数jを求める。
    seen = set()
    for j in range(1,K+1):
        seen.add(now)
        now = G[now]
        if now in seen:
            break
    #ループの長さで割った余りｒを求める。
    r = K % j
    for _ in range(r):
        now = G[now]
print(now + 1)
Buggy python submission (verdict: Runtime Error):
K = int(input())
A, B = map(int, input().split())
XK = list(x * K for x in range(1, 1000//K + 1))
for i in XK:
    if (A <= i) & (i <= B):
        print('OK')
        break
else:
    print('NG')


Fixed submission:
X = int(input())
i = 0
money = 100
r = 101
while money < X:
    money *= r
    money //= 100
    i += 1
print(i)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
G = np.zeros((N, N), dtype=int)
for i in range(N):
    for j in range(i+1, N):
        G[i][j] = min(j - i, abs(X - i) + 1 + abs(Y - j))
for cnt in range(1, N):
    print(np.sum(G == cnt))


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[ min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
for i in range(1, N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path
N, X, Y = map(int, input().split())

G = np.full((N, N), np.inf, dtype=float)
for i in range(N - 1):
    G[i][i + 1] = 1
    G[i + 1][i] = 1
G[X - 1][Y - 1] = 1
G[Y - 1][X - 1] = 1

G = shortest_path(G)
for cnt in range(1, N):
    print(np.sum(G == cnt) // 2)


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[ min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
for i in range(1, N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path
N, X, Y = map(int, input().split())

G = np.full((N, N), np.inf, dtype=float)
for i in range(N - 1):
    G[i][i + 1] = 1
    G[i + 1][i] = 1
G[X - 1][Y - 1] = 1
G[Y - 1][X - 1] = 1

G = shortest_path(G)
for cnt in range(1, N):
    print(np.sum(G == cnt) // 2)


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[ min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
for i in range(1, N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path
N, X, Y = map(int, input().split())

G = np.full((N, N), np.inf, dtype=float)
for i in range(N - 1):
    G[i][i + 1] = 1
    G[i + 1][i] = 1
G[X - 1][Y - 1] = 1
G[Y - 1][X - 1] = 1

G = shortest_path(G, method='D')
for cnt in range(1, N):
    print(np.sum(G == cnt) // 2)


Fixed submission:
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
ans = [0] * N
for i in range(N):
    for j in range(i+1, N):
        ans[ min(j - i, abs(X - i) + 1 + abs(Y - j))] += 1
for i in range(1, N):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
direction = True
for _ in range(Q):
    line = input()
    if line[0] == '1':
        direction = not direction
    else:
        if (direction and line[2] == '1') or (not direction and line[2] == '2'):
            S = line[4] + S
        else:
            S = S + line[4]
print(S if direction else S[::-1])


Fixed submission:
from collections import deque
S = input()
q = deque()
for s in list(S):
    q.append(s)
Q = int(input())
direction = True
for _ in range(Q):
    line = input()
    if line[0] == '1':
        direction = not direction
    else:
        if (direction and line[2] == '1') or (not direction and line[2] == '2'):
            q.appendleft(line[4])
        else:
            q.append(line[4])
print("".join(q) if direction else "".join(reversed(q)))
Buggy python submission (verdict: Time Limit Exceeded):
H = int(input())
q, r = divmod(H, 2)
i = 1
while q != 1:
    q //= 2
    i += 1
ans = 0
for j in range(i + 1):
    ans += 2 ** j
print(ans)


Fixed submission:
H = int(input())
L = len(bin(H)) - 2
ans = 0
for j in range(L):
    ans += 2 ** j
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9] * (H + 1)
dp[0] = 0
for i in range(H + 1):
    for a, b in ab:
        if i - a < 0:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i - a] + b)
print(dp[H])


Fixed submission:
import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9] * (H + 1)
dp[0] = 0
for i in range(H + 1):
    for a, b in ab:
        if i - a < 0:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i - a] + b)
print(dp[H])

Buggy python submission (verdict: Time Limit Exceeded):
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [0] * (H + 1 + 10**4)
for i in range(1, H + 1):
    dp[i] = 10 ** 9
for i in range(H + 1):
    for a, b in ab:
        dp[i] = min(dp[i], dp[i - a] + b)
print(dp[H])


Fixed submission:
import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
dp = [10**9] * (H + 1)
dp[0] = 0
for i in range(H + 1):
    for a, b in ab:
        if i - a < 0:
            dp[i] = min(dp[i], b)
        else:
            dp[i] = min(dp[i], dp[i - a] + b)
print(dp[H])
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
a = max(0, A - K)
if K - A > 0:
    b = max(0, B - K + A)
print(a, b)


Fixed submission:
A, B, K = map(int, input().split())
a = max(0, A - K)
b = B
if K - A > 0:
    b = max(0, B - K + A)
print(a, b)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
aaa = list(map(int, input().split()))
zero = [0] * 61
one = [0] * 61
for a in aaa:
    for i in range(61):
        if a & (1<<i):
            one[i] += 1
        else:
            zero[i] += 1
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)


Fixed submission:
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
aaa = np.array(list(map(int, input().split())), dtype='int64')
MOD = 1_000_000_007
ans = 0
for j in range(1, N):
    ans += sum((aaa[:j] ^ aaa[j]) % MOD)
    ans %= MOD
print(ans)


Fixed submission:
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
aaa = list(map(int, input().split()))
ans = 0
MOD = 1_000_000_007
for i in range(N-1):
    for j in range(i + 1, N):
        ans += aaa[i] ^ aaa[j]
        ans %= MOD
print(ans)


Fixed submission:
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
aaa = map(int, input().split())
ans = 0
MOD = 1_000_000_007
for i in range(N-1):
    for j in range(i + 1, N):
        ans += aaa[i] ^ aaa[j]
        ans %= MOD
print(ans)


Fixed submission:
N = int(input())
aaa = list(map(int, input().split()))
bbb = [format(a, '061b') for a in aaa]

zero = [0] * 61
one = [0] * 61
for i in range(61):
    s = ''.join(list(b[-(i+1)] for b in bbb))
    zero[i] = s.count('0')
    one[i] = s.count('1')
ans = 0
MOD = 1_000_000_007
for i, o, l in zip(range(61), zero, one):
    ans += 2**i * o * l
    ans %= MOD
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i, a in enumerate(L):
    for j, b in enumerate(L[i+1:]):
        l = abs(a - b)
        r = a + b
        top = bisect_left(L[i+j+2:], r)
        bot = bisect_right(L[i+j+2:], l)
        ans += top - bot
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i - 1, 0, -1):
        x = L[i] - L[j]
        bottom = bisect_right(L, x)
        if j > bottom:
            ans += j - bottom
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
c = np.zeros(10 ** 3 + 1, dtype=int)
for l in L:
    c[l] += 1
ans = 0
for i, a in enumerate(L):
    for b in L[i+1:]:
        ans += c[a - b + 1:b].sum()
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i - 1, 0, -1):
        x = L[i] - L[j]
        bottom = bisect_right(L, x)
        if j > bottom:
            ans += j - bottom
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
ans = 0
for a in range(N):
    for b in range(a + 1, N):
        for c in range(b + 1, N):
            if L[c] < L[b] + L[a]:
                if L[a] < L[b] + L[c] and L[b] < L[c] + L[a]:
                    ans += 1
            else:
                break
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i - 1, 0, -1):
        x = L[i] - L[j]
        bottom = bisect_right(L, x)
        if j > bottom:
            ans += j - bottom
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int, input().split()))
ans = 0
for a in range(N):
    for b in range(a + 1, N):
        for c in range(b + 1, N):
            if L[a] < L[b] + L[c] and L[b] < L[a] + L[c] and L[c] < L[b] + L[a]:
                ans += 1
print(ans)


Fixed submission:
from bisect import bisect_left, bisect_right
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N-1, 1, -1):
    for j in range(i - 1, 0, -1):
        x = L[i] - L[j]
        bottom = bisect_right(L, x)
        if j > bottom:
            ans += j - bottom
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
id = set(i for i in range(1, n + 1))
for i in range(m):
    l, r = map(int, input().split())
    check = set(i for i in range(l, r + 1))
    id = id & check
print(len(id))

Fixed submission:
n, m = map(int, input().split())
id = set(i for i in range(1, n + 1))
L = []
R = []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
print( min(R) - max(L) + 1 if min(R) - max(L) + 1 > 0 else 0)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
id = [x for x in range(1, n + 1)]
for i in range(m):
    l, r = map(int, input().split())
    id = [x for x in id if l <= x <= r]
print(len(id))

Fixed submission:
n, m = map(int, input().split())
id = set(i for i in range(1, n + 1))
L = []
R = []
for i in range(m):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
print( min(R) - max(L) + 1 if min(R) - max(L) + 1 > 0 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as C
n, k = map(int, input().split())
c = list(C(range(n), k))
ans = 0
for comb in c:
    for i in range(k - 1):
        if comb[i] + 1 == comb[i + 1]:
            continue
        break
    else:
        ans += 1
print(ans)


Fixed submission:
n, k = map(int, input().split())
print(n - k + 1)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations as C
n, k = map(int, input().split())
c = list(C(range(n), k))
ans = 0
for comb in c:
    for i in range(k - 1):
        if comb[i] + 1 == comb[i + 1]:
            continue
        break
    else:
        ans += 1
print(ans)


Fixed submission:
n, k = map(int, input().split())
print(n - k + 1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
L = [0]
R = [0]
for i in range(n-1):
    l = gcd(L[-1], A[i])
    L.append(l)
    r = gcd(R[-1], A[::-1][i])
    R.append(r)
for l, r in zip(L,R[::-1]):
    ans = max(ans, gcd(l, r))
print(ans)

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
    ans = max(ans, gcd(l, r))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

def gcd_list(list):
    a = list.pop()
    for b in list:
        a = gcd(a,b)
    return a

ans = []
for i in range(n):
    B = A.copy()
    B.pop(i)
    ans.append(gcd_list(B))
print(max(ans))

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
    ans = max(ans, gcd(l, r))
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

if len(A) == 2:
    print(gcd(A[0], A[1]))
    exit()
b = set()
for i in range(2):
    a = 0
    for j in range(n):
        a = gcd(A[i],A[j])
        b.add(a)
b = sorted(b)
print(b[1])

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

ans = 0
L = [0]*(n)
R = [0]*(n+1)
for i in range(n-1):
    L[i+1] = gcd(L[i], A[i])
    R[i+1] = gcd(R[i], A[-i-1])
for l, r in zip(L[::-1],R):
    ans = max(ans, gcd(l, r))
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
S = input()
start =[]
end = []
if S[0] == "0":
    start.appned(0)
else:
    end.append(0)
for i in range(n):
    if S[i:i+2] == "10":
        start.append(i+1)
    elif S[i:i+2] == "01":
        end.append(i+1)
if len(start) <= k:
    print(len(S))
else:
    start.append(len(S))
    ans = []
    for i in range(len(start) - k):
        ans.append(start[i + k] - end[i])
    print(max(ans))

Fixed submission:
n, k = map(int, input().split())
S = input()
start =[]
end = [0]
if S[0] == "0":
    start.append(0)
for i in range(n):
    if S[i:i+2] == "10":
        start.append(i+1)
    elif S[i:i+2] == "01":
        end.append(i+1)

if len(start) <= k:
    print(len(S))
else:
    start.append(len(S))
    ans = []
    for i in range(len(start) - k):
        ans.append(start[i + k] - end[i])
    print(max(ans))