Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
nodes = [i for i in range(N)]


def root(x):
    while nodes[x] != x:
        x = nodes[x]
    return x


def same(x, y):
    return root(x) == root(y)


def unite(x, y):
    if not same(x, y):
        nodes[root(y)] = root(x)


for _ in range(M):
    X, Y, Z = map(int, input().split())
    unite(X-1, Y-1)


ans = 0
for i in range(len(nodes)):
    if nodes[i] == i:
        ans += 1

print(ans)


Fixed submission:
N, M = map(int, input().split())
nodes = [i for i in range(N)]


def root(x):
    if nodes[x] == x:
        return x
    else:
        nodes[x] = root(nodes[x])
    return nodes[x]


def same(x, y):
    return root(x) == root(y)


def unite(x, y):
    if not same(x, y):
        nodes[root(x)] = root(y)


for _ in range(M):
    X, Y, Z = map(int, input().split())
    unite(X-1, Y-1)


ans = 0
for i in range(len(nodes)):
    if nodes[i] == i:
        ans += 1

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

N, K = map(int, input().strip().split(' '))
S = input().strip()
prev = ''
l = 0
lst = []
for s in S:
    if s == prev:
        l += 1
    else:
        lst += [l]
        l = 1
    prev = s
lst += [l]
lst = lst[1:]
# print(lst)

res = 0
flip = S[0] == '1'
for i in range(len(lst)):
    # print(lst[i:i+2*K+flip])
    res = max(res, sum(lst[i:i+2*K+flip]))
    flip ^= 1

#print(N, K)
# print(S)
print(res)


Fixed submission:
import sys

N, K = map(int, input().strip().split(' '))
S = input().strip()
prev = ''
l = 0
lst = []
for s in S:
    if s == prev:
        l += 1
    else:
        lst += [l]
        l = 1
    prev = s
lst += [l]
lst = lst[1:]
# print(lst)

flip = S[0] == '1'
res = sum(lst[0:2*K+flip])
cur = res
# print(cur)
flip ^ - 1
for i in range(1, len(lst)):
    cur -= lst[i-1]
    if not flip:
        cur += sum(lst[i+2*K-1:i+2*K+1])
        res = max(cur, res)
        # print(lst[i+2*K:i+2*K+2])
    # res = max(res, sum(lst[i:i+2*K+flip]))
    # print(cur)
    flip ^= 1

# print(N, K)
# print(S)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
import heapq
import copy

def inv(l):
    return list(map(lambda x: x*-1, l))

def solve(A,B,C, K):
    A,B,C = inv(A), inv(B), inv(C)
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)
    ind = set([(0,0,0)])

    h = [(A[0]+ B[0]+ C[0], (0,0,0))]
    res = []

    for _ in range(K):
        h2 = copy.copy(h)
        for (val, (i,j,k)) in h2:
            if i+1 < len(A) and (i+1,j,k) not in ind:
                heapq.heappush(h, (A[i+1]+B[j]+C[k], (i+1, j, k)))
                ind |= set([(i+1,j,k)])
            if j+1 < len(B) and (i,j+1, k) not in ind:
                heapq.heappush(h, (A[i]+B[j+1]+C[k], (i, j+1, k)))
                ind |= set([(i,j+1,k)])
            if k+1 < len(C) and (i,j, k+1) not in ind:
                heapq.heappush(h, (A[i]+B[j]+C[k+1], (i, j, k+1)))
                ind |= set([(i,j,k+1)])
        res += [heapq.heappop(h)]
    for r in res:
        print(r[0]*-1)

la,lb,lc,K = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))

solve(A,B,C,K)

Fixed submission:
import itertools
import heapq
import copy

def inv(l):
    return list(map(lambda x: x*-1, l))

def solve(A,B,C, K):
    A,B,C = inv(A), inv(B), inv(C)
    A = sorted(A)
    B = sorted(B)
    C = sorted(C)
    ind = set([(0,0,0)])

    h = [(A[0]+ B[0]+ C[0], (0,0,0))]
    res = []

    for _ in range(K):
        h2 = copy.copy(h)
        val, (i,j,k) = heapq.heappop(h)
        res += [-val]
        if i+1 < len(A) and (i+1,j,k) not in ind:
            heapq.heappush(h, (A[i+1]+B[j]+C[k], (i+1, j, k)))
            ind |= set([(i+1,j,k)])
        if j+1 < len(B) and (i,j+1, k) not in ind:
            heapq.heappush(h, (A[i]+B[j+1]+C[k], (i, j+1, k)))
            ind |= set([(i,j+1,k)])
        if k+1 < len(C) and (i,j, k+1) not in ind:
            heapq.heappush(h, (A[i]+B[j]+C[k+1], (i, j, k+1)))
            ind |= set([(i,j,k+1)])
    for r in res:
        print(r)

la,lb,lc,K = list(map(int, input().split(' ')))
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
C = list(map(int, input().split(' ')))

solve(A,B,C,K)
Buggy python submission (verdict: Runtime Error):
S = input()
T = input()

if S == T[::-1]
    print('Yes')
else:
    print('No')

Fixed submission:
S = input()
T = input()

lens = len(S)
lent = len(T)

ans = True
if lens + 1 != lent:
    ans = False

for i in range(lens):
    if S[i] != T[i]:
        ans = False

if ans:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

# from fractions import gcd
from math import gcd

def f(x, y, z):
    r = gcd(gcd(x, y), z)
    return r



ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += f(i, j, k)

print(ans)

Fixed submission:
K = int(input())

from fractions import gcd
# return gcd(x, y)

d = {}

def f(x, y, z):
    # print(d)
    if d.get((x,y)):
        s = d[(x,y)]
    else:
        s = gcd(x, y)
        d[(x,y)] = s

    if d.get((s,z)):
        t = d[(s,z)]
    else:
        t = gcd(s,z)
        d[(s,z)] = t

    return t

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j == k:
                ans += f(i, j, k)
            elif i == j or j == k:
                ans += 3 * f(i, j, k)
            else:
                ans += 6 * f(i, j, k)

print(ans)

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

from fractions import gcd
# return gcd(x, y)

d = {}
d2 = {}

def f(x, y, z):
    s = gcd(x, y)
    t = gcd(s, z)
    return t

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j == k:
                ans += f(i, j, k)
            elif i == j or j == k:
                ans += 3 * f(i, j, k)
            else:
                ans += 6 * f(i, j, k)

print(ans)

Fixed submission:
K = int(input())

from fractions import gcd
# return gcd(x, y)

d = {}

def f(x, y, z):
    # print(d)
    if d.get((x,y)):
        s = d[(x,y)]
    else:
        s = gcd(x, y)
        d[(x,y)] = s

    if d.get((s,z)):
        t = d[(s,z)]
    else:
        t = gcd(s,z)
        d[(s,z)] = t

    return t

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j == k:
                ans += f(i, j, k)
            elif i == j or j == k:
                ans += 3 * f(i, j, k)
            else:
                ans += 6 * f(i, j, k)

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

rc = 0
gc = 0
bc = 0

for si in S:
    if si == 'R':
        rc += 1
    elif si == 'G':
        gc += 1
    else:
        bc += 1


bad = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + (j-i)
        if k > N-1:
            continue
        
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            # print('bad', i,j,k,S[i],S[j],S[k])
            bad += 1

ans = rc * gc * bc
# print(ans)
ans -= bad
print(ans)


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

rc = 0
gc = 0
bc = 0

for si in S:
    if si == 'R':
        rc += 1
    elif si == 'G':
        gc += 1
    else:
        bc += 1


bad = 0
for i in range(N):
    for j in range(i+1, N):
        k = j + (j-i)
        if k > N-1:
            continue
        
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            # print('bad', i,j,k,S[i],S[j],S[k])
            bad += 1

ans = rc * gc * bc
# print(ans)
ans -= bad
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
QUERY = []
for i in range(Q):
    # q = list(map(int, input().split()))
    q = input().split()
    if q[0] == '1':
        QUERY.append([int(q[0])])
    else:
        QUERY.append([int(q[0]), int(q[1]), q[2]])

for q in QUERY:
    if q[0] == 1:
        S = S[::-1]
    else:
        if q[1] == 1:
            S = q[2] + S
        else:
            S = S + q[2]

print(S)

Fixed submission:
S = input()
Q = int(input())
QUERY = []
for i in range(Q):
    # q = list(map(int, input().split()))
    q = input().split()
    if q[0] == '1':
        QUERY.append([int(q[0])])
    else:
        QUERY.append([int(q[0]), int(q[1]), q[2]])

st = []
en = []
rev = False
rev_c = 0
for q in QUERY:
    if q[0] == 1:
        if rev:
            rev = False
        else:
            rev = True
        rev_c += 1
    else:
        if q[1] == 1:
            if not rev:
                st.append(q[2])
            else:
                en.append(q[2])
        else:
            if not rev:
                en.append(q[2])
            else:
                st.append(q[2])

# print(st)
# print(en)

st_s = "".join(st)
st_s = st_s[::-1]
en_s = "".join(en)

ans = st_s + S + en_s
if rev_c % 2 == 0:
    pass
else:
    ans = ans[::-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

# A = list(set(A))

def lcm(x, y):
    return (x * y) // gcd(x, y)

p = lcm(A[0]//2, A[1]//2)
q = lcm(A[0], A[1])
for i in range(1, N-1):
    print(i)
    p = lcm(p, A[i]//2)
    q = lcm(q, A[i])
# print(p, q)

n = ((M - p) / q) + 1
print(int(n))

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

half = [i//2 for i in A]

def f(v):
    r = 0
    while v % 2 == 0:
        v /= 2
        r += 1
    return r

from fractions import gcd
def f2(x, y):
    return (x * y) // gcd(x, y)

d = f(A[0])
for ai in A:
    if d != f(ai):
        print(0)
        break
else:
    lcm = 1
    for ai in half:
        lcm = f2(lcm, ai)

    r = M // lcm
    ans = (r + 1) // 2
    print(ans)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

A = set(A)
half = [i/2 for i in A]
# print(half)

# def lcm(x, y):
#     return (x * y) // gcd(x, y)


a = 1
for hi in half:
    a *= hi

b = 1
for ai in A:
    b *= ai
b //= 2
# print(a, b)

n = ((M - a) / b) + 1
print(int(n))

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

half = [i//2 for i in A]

def f(v):
    r = 0
    while v % 2 == 0:
        v /= 2
        r += 1
    return r

from fractions import gcd
def f2(x, y):
    return (x * y) // gcd(x, y)

d = f(A[0])
for ai in A:
    if d != f(ai):
        print(0)
        break
else:
    lcm = 1
    for ai in half:
        lcm = f2(lcm, ai)

    r = M // lcm
    ans = (r + 1) // 2
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

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

    A.sort()

    for i in range(M):
        a = A.pop()
        a = a // 2
        bisect.insort_right(A, a)

    # print(A)
    x = sum(A)
    print(x)


if __name__ == "__main__":
    main()

Fixed submission:
import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A = [-1 * i for i in A]

    heapq.heapify(A)

    for i in range(M):
        a = heapq.heappop(A)
        a = -1 * (-1 * a // 2)
        heapq.heappush(A, a)


    x = -1 * sum(A)
    print(x)


if __name__ == "__main__":
    main()

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

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

A.sort()

for i in range(M):
    a = A.pop()
    a = a // 2
    bisect.insort_right(A, a)

# print(A)
x = sum(A)
print(x)

Fixed submission:
import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A = [-1 * i for i in A]

    heapq.heapify(A)

    for i in range(M):
        a = heapq.heappop(A)
        a = -1 * (-1 * a // 2)
        heapq.heappush(A, a)


    x = -1 * sum(A)
    print(x)


if __name__ == "__main__":
    main()

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

for i in range(M):
    A.sort(reverse=True)
    A[0] = A[0] // 2

x = sum(A)
print(x)

Fixed submission:
import heapq

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A = [-1 * i for i in A]

    heapq.heapify(A)

    for i in range(M):
        a = heapq.heappop(A)
        a = -1 * (-1 * a // 2)
        heapq.heappush(A, a)


    x = -1 * sum(A)
    print(x)


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    x = factorial(v) / factorial(2) / factorial(v - 2)
    ans += x

print(round(ans))


Fixed submission:
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial

N = int(input())
st = set()
d = defaultdict(int)
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if s_sorted in st:
        d[s_sorted] += 1
    else:
        st.add(s_sorted)

ans = 0
for _, v in d.items():
    tmp = v + 1
    x = factorial(tmp) / factorial(2) / factorial(tmp - 2)
    ans += x

print(round(ans))


Fixed submission:
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial

N = int(input())
st = set()
d = defaultdict(int)
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if s_sorted in st:
        d[s_sorted] += 1
    else:
        st.add(s_sorted)

ans = 0
for _, v in d.items():
    x = factorial(v + 1) / factorial(2)
    ans += x

print(round(ans))


Fixed submission:
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial

N = int(input())
# S = []
st = set()
d = defaultdict(int)
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if s_sorted in st:
        d[s_sorted] += 1
    else:
        st.add(s_sorted)

ans = 0
for _, v in d.items():
    x = factorial(v + 1) / factorial(2)
    ans += x

print(round(ans))


Fixed submission:
from math import factorial

N = int(input())
d = {}
for _ in range(N):
    s = input()
    s_sorted = "".join(sorted(s))
    if not d.get(s_sorted):
        d[s_sorted] = 1
    else:
        d[s_sorted] += 1

ans = 0
for _, v in d.items():
    if v == 1:
        continue
    ans += v * (v - 1) // 2

print(round(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
for i in range(N):
    a = int(input())
    A.append(a)

for i in range(N):
    AC = A.copy()
    del AC[i]
    print(max(AC))

Fixed submission:
N = int(input())
A = []

for i in range(N):
    a = int(input())
    A.append(a)

SA = sorted(A)
mx = max(A)

for i in range(N):
    if A[i] == mx:
        print(SA[-2])
    else:
        print(mx)
Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

# max_loop = 2019 * 2 + 1
max_loop = 2019 ** 2
count = 0
ans = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        x = (i * j) % 2019
        ans = min(ans, x)
    if ans == 0:
        break
print(ans)


Fixed submission:
L, R = map(int, input().split())

# max_loop = 2019 * 2 + 1
max_loop = 2019 ** 2
count = 0
ans = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        x = (i * j) % 2019
        ans = min(ans, x)
        if ans == 0:
            print(0)
            exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
L, R = map(int, input().split())

# max_loop = 2019 * 2 + 1
max_loop = 2019 ** 2
count = 0
ans = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        x = (i * j) % 2019
        ans = min(ans, x)
print(ans)

Fixed submission:
L, R = map(int, input().split())

# max_loop = 2019 * 2 + 1
max_loop = 2019 ** 2
count = 0
ans = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        x = (i * j) % 2019
        ans = min(ans, x)
        if ans == 0:
            print(0)
            exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N, M = map(int, input().split())
cnt = Counter()

for i in range(M):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        cnt[i] += 1

ans = 0
for v in cnt.values():
    if v == M:
        ans += 1
print(ans)

Fixed submission:
from collections import Counter

N, M = map(int, input().split())
L = []
R = []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxL = max(L)
minR = min(R)

ans = max(0, minR - maxL + 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [0] * (N+1)
for i in range(M):
    l, r = map(int, input().split())
    for i in range(l, r + 1):
        A[i] += 1

print(A.count(M))

Fixed submission:
from collections import Counter

N, M = map(int, input().split())
L = []
R = []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxL = max(L)
minR = min(R)

ans = max(0, minR - maxL + 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])

A = [0] * (N+1)

for l, r in LR:
    for i in range(l, r + 1):
        A[i] += 1

print(A.count(M))

Fixed submission:
from collections import Counter

N, M = map(int, input().split())
L = []
R = []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxL = max(L)
minR = min(R)

ans = max(0, minR - maxL + 1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LR = []
for i in range(M):
    l, r = map(int, input().split())
    LR.append([l, r])

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

for l, r in LR:
    for i in range(l, r + 1):
        A[i] += 1

print(A.count(M))

Fixed submission:
from collections import Counter

N, M = map(int, input().split())
L = []
R = []

for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

maxL = max(L)
minR = min(R)

ans = max(0, minR - maxL + 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())

G = []
for i in range(N):
    G.append([])

color = [None] * N

for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])

# for i in range(N):
#     print(G[i])

def dfs(v, c):
    color[v] = c

    # vと隣接する点
    for p, d in G[v]:
        # 訪問済み
        if color[p] is not None:
            continue
        if d % 2 == 0:
            dfs(p, c)
        else:
            dfs(p, c ^ 1)  # 排他的論理和で0, 1をひっくり返す

# 0の頂点を0で塗る
dfs(0, 0)

# print(color)
for col in color:
    print(col)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())

G = []
for i in range(N):
    G.append([])

color = [None] * N

for i in range(N-1):
    u, v, w = list(map(int, input().split()))
    G[u-1].append([v-1, w])
    G[v-1].append([u-1, w])

# for i in range(N):
#     print(G[i])

def dfs(v, c):
    color[v] = c

    # vと隣接する点
    for p, d in G[v]:
        # 訪問済み
        if color[p] is not None:
            continue
        if d % 2 == 0:
            dfs(p, c)
        else:
            dfs(p, c ^ 1)  # 排他的論理和で0, 1をひっくり返す

# 0の頂点を0で塗る
dfs(0, 0)

# print(color)
for col in color:
    print(col)
Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())

cnt = 0
for i in range(3001):
    for j in range(3001):
        x = n - (r * i + g * j)
        if x < 0:
            continue
        if x % b == 0:
            cnt += 1

print(cnt)


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

cnt = 0
for i in range(int(n//r)+1):
    r_num = r * i
    for j in range(int((n - r_num)//g)+1):
        g_num = g * j
        b_num = (n - r_num - g_num)
        if b_num >= 0 and b_num % b == 0:
            cnt += 1

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

from fractions import gcd

if N == 2:
    print(max(A))
    exit()

ans = []
for n in range(N):
    if n == 0:
        x = A[1]
    else:
        x = A[0]

    for i, ai in enumerate(A):
        if i == n:
            continue
        x = gcd(x, ai)
    ans.append(x)

print(max(ans))

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

from fractions import gcd

H = [A[0]]
x = A[0]
for i in range(1, N):
    x = gcd(x, A[i])
    H.append(x)


T = [A[-1]]
x = A[-1]
for i in range(2, N+1):
    x = gcd(x, A[-1 * i])
    T.append(x)

# print('H', H)
# print('T', T)

r = []
for i in range(N):
    if i == 0:
        ans = T[-2]
        r.append(ans)
    elif i == N - 1:
        ans = H[-2]
        r.append(ans)
    else:
        ans = gcd(H[i-1], T[N-i-2])
        r.append(ans)
print(max(r))
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()

r = 0
b = 0
for si in S:
    if s == 'R':
        r += 1
    else:
        b += 1

if r > b:
    print('Yes')
else:
    print('No')

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

r = 0
b = 0
for si in S:
    if si == 'R':
        r += 1
    else:
        b += 1

if r > b:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;

  if (s <= "2019/04/30") {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}


Fixed submission:
def main():
    s = input()
    
    m = int(s[5]+s[6])
    d = int(s[8]+s[9])

    if m < 4:
        print("Heisei")
    elif m == 4 and d <= 30:
        print("Heisei")
    else:
        print("TBD")




if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
H = list(map(int, input().split()))

INF = float('inf')

DP = [INF] * N
DP[0] = 0

for i in range(N):
    for j in range(1, K+1):
        if i + j < N:
            DP[i+j] = min(DP[i+j], DP[i] + abs(H[i+j] - H[i]))
    # print(DP)

print(DP[N-1])

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

INF = 10**5

# DP = [INF] * ((10**5)+10)
DP = [None] * ((10**5)+10)
# DP = [None] * (N+1)
DP[0] = 0

for i in range(1, N):
    a = []
    for j in range(1, K+1):
        if 0 <= i-j < N:
            v = DP[i-j] + abs(H[i-j] - H[i])
            a.append(v)
    DP[i] = min(a)


# print(DP)
print(DP[N-1])