Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0
for i in range(0, 10):
    for j in range(0, 10):
        cij, cji = 0, 0
        for k in range(1, n + 1):
            s = str(k)
            if int(s[0]) == i and int(s[-1]) == j:
                cij += 1
            if int(s[0]) == j and int(s[-1]) == i:
                cji += 1
        cnt += cij * cji
print(cnt)

Fixed submission:
n = int(input())
cnt = 0
c = [[0 for _ in range(10)] for _ in range(10)]
for k in range(1, n + 1):
    a, b = int(str(k)[0]), int(str(k)[-1])
    c[a][b] += 1
for i in range(0, 10):
    for j in range(0, 10):
        cnt += c[i][j] * c[j][i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort()
am = [[] for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if r[i][1] < r[j][0]:
            break
        am[i].append(j)
        am[j].append(i)
while sum(len(mi) for mi in am):
    maxi, maxd = 0, 0
    for i, mi in enumerate(am):
        li = len(mi)
        if li > maxd:
            maxi, maxd = i, li
    for pi in am[maxi]:
        am[pi].remove(maxi)
    am.pop(maxi)
    n -= 1
print(n)

Fixed submission:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l, x + l))
r.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] >= limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
r.sort()
am = [[] for _ in range(n)]
for i in range(n):
    for j in range(i + 1, n):
        if r[i][1] >= r[j][0]:
            am[i].append(j)
            am[j].append(i)
while sum(len(mi) for mi in am):
    maxi, maxd = 0, 0
    for i, mi in enumerate(am):
        li = len(mi)
        if li > maxd:
            maxi, maxd = i, li
    for pi in am[maxi]:
        am[pi].remove(maxi)
    am.pop(maxi)
    n -= 1
print(n)

Fixed submission:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l, x + l))
r.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] >= limit:
        cnt += 1
        limit = ri[1]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())
r = []
dead = defaultdict(int)
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l + 1, x + l - 1))
    for d in range(x - l + 1, x + l):
        dead[d] += 1
while max(dead.values()) > 1:
    maxi, maxd = 0, 0
    for i, ri in enumerate(r):
        dd = sum([dead[d] for d in range(ri[0], ri[1] + 1)])
        if dd > maxd:
            maxi = i
            maxd = dd
    for d in range(r[maxi][0], r[maxi][1] + 1):
        dead[d] -= 1
    n -= 1
print(n)

Fixed submission:
n = int(input())
r = []
for i in range(n):
    x, l = map(int, input().split())
    r.append((x - l, x + l))
r.sort(key=lambda _x: _x[1])
cnt = 1
limit = r[0][1]
for ri in r[1:]:
    if ri[0] >= limit:
        cnt += 1
        limit = ri[1]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache


@lru_cache(maxsize=2**17, typed=int)
def comb(n, r, p):
    r = min(n - r, r)
    if r == 0:
        return 1
    over = 1
    for i in range(n, n - r, -1):
        over = over * i % p
    under = 1
    for i in range(1, r + 1):
        under = under * i % p
    inv = pow(under, p - 2, p)
    return over * inv % p


def main():
    n, k = map(int, input().split())
    a = sorted(int(i) for i in input().split())
    mod = 10**9 + 7
    f = 0
    for i in range(n - k + 1):
        f = (f + a[k + i - 1] * comb(k - 1 + i, k - 1, mod) % mod) % mod
        f = (f - a[i] * comb(n - 1 - i, k - 1, mod) % mod) % mod
    print(f)


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, k = map(int, input().split())
    a = sorted(int(i) for i in input().split())
    mod = 10**9 + 7
    comb = [1] * (n - k + 1)
    for i in range(n - k):
        comb[i + 1] = (comb[i] * (k + i) * pow(i + 1, mod - 2, mod)) % mod
    f = 0
    for i in range(n - k + 1):
        f = (f + a[k + i - 1] * comb[i] % mod) % mod
        f = (f - a[i] * comb[-1 - i] % mod) % mod
    print(f)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
print(s.count("ABC"))

Fixed submission:
k, x = map(int, input().split())
if k * 500 >= x:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
_, s = input(), input()
a = set()
for c in combinations(s, 3):
  a.add(c)
print(len(a))

Fixed submission:
_, s = input(), input()
cnt = 0
for i in range(1000):
    t = "{:0>3}".format(i)
    ss = s
    if t[0] not in ss:
        continue
    ss = ss[ss.index(t[0]) + 1:]
    if t[1] not in ss:
        continue
    ss = ss[ss.index(t[1]) + 1:]
    if t[2] not in ss:
        continue
    cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
while s >= 10:
  s -= 9
  n += 1
print(n - 1)

Fixed submission:
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print(n + (s - 1) // 9 - 1)

Buggy python submission (verdict: Runtime Error):
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n = ""
cnt = 0
for i in range(m):
  d, c = input().split()
  if d == "0":
    cnt += int(c)
  # elif d == "1":
  #   cnt +=
  else:
    n += d * int(c)
# print(n)
while int(n) >= 10:
  n = n[2:] + str(int(n[0]) + int(n[1]))
  cnt += 1
# print(n)
print(cnt)

Fixed submission:
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print(n + (s - 1) // 9 - 1)

Buggy python submission (verdict: Runtime Error):
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n = "".join(d * int(c) for d, c in [input().split() for i in range(m)])
cnt = 0
while int(n) >= 10:
  n = n[:-2] + str(int(n[-1]) + int(n[-2]))
  cnt += 1
print(cnt)

Fixed submission:
import sys
def input() -> str:
    return sys.stdin.readline()
m = int(input())
n, s = 0, 0
for i in range(m):
  d, c = [int(i) for i in input().split()]
  n += c
  s += d * c
print(n + (s - 1) // 9 - 1)
Buggy python submission (verdict: Runtime Error):
from functools import reduce

def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret

def modinv(a):
    return modpow(a, mod - 2)

def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod

x, y = [int(i) for i in input().split()]
if (x + y) % 3:
    print(0)
else:
    mod = 10**9 + 7
    print(cmb((x + y) // 3, (2 * x - y) // 3))

Fixed submission:
from functools import reduce

def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret

def modinv(a):
    return modpow(a, mod - 2)

def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod

x, y = [int(i) for i in input().split()]
if (x + y) % 3 or x > 2 * y or y > 2 * x:
    print(0)
else:
    mod = 10**9 + 7
    print(cmb((x + y) // 3, (2 * x - y) // 3))

Buggy python submission (verdict: Runtime Error):
# from operator import mul
from functools import reduce


def com_init():
    for i in range(2, n):
        fac[i] = fac[i - 1] * i % mod
        inv[i] = mod - inv[mod % i] * (mod // i) % mod
        finv[i] = finv[i - 1] * inv[i] % mod


def com():
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod


def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret


def modinv(a):
    return modpow(a, mod - 2)


def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod


x, y = [int(i) for i in input().split()]
if (x + y) % 3:
    print(0)
else:
    # n = (x + y) // 3
    # r = min((2 * x - y) // 3, (2 * y - x) // 3)
    mod = 10**9 + 7
    # fac, finv, inv = [1] * (n + 1), [1] * (n + 1), [1] * (n + 1)
    # com_init()
    # print(com())
    # print(factorial(n) // factorial(r) // factorial(n - r))
    print(cmb((x + y) // 3, (2 * x - y) // 3))


Fixed submission:
from functools import reduce

def modpow(a, m):
    ret = 1
    while m > 0:
        if m & 1:
            ret = ret * a % mod
        a = a * a % mod
        m = m >> 1
    return ret

def modinv(a):
    return modpow(a, mod - 2)

def cmb(n, r):
    r = min(r, n - r)
    if r == 0:
        return 1
    over = reduce(lambda a, b: a * b % mod, range(n, n - r, -1))
    under = reduce(lambda a, b: a * b % mod, range(1, r + 1))
    return over * modinv(under) % mod

x, y = [int(i) for i in input().split()]
if (x + y) % 3 or x > 2 * y or y > 2 * x:
    print(0)
else:
    mod = 10**9 + 7
    print(cmb((x + y) // 3, (2 * x - y) // 3))
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
h = []
for i in set(combinations(l, 3)):
  a, b, c = sorted(i)
  if c < (a + b):
    cnt += 1
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for a in key:
    cnt += L[a] * (L[a] - 1) * (L[a] - 2) // 6
    cnt += max(acc[min(2 * a - 1, maxL)] - acc[a], 0) * L[a] * (L[a] - 1) // 2
for i in range(len(key) - 1):
    for j in range(i + 1, len(key)):
        a, b = key[i], key[j]
        cnt += L[a] * L[b] * (L[b] - 1) // 2
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
h = []
for i in set(combinations(l, 3)):
  a, b, c = sorted(i)
  if c < (a + b):
    cnt += 1
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for a in key:
    cnt += L[a] * (L[a] - 1) * (L[a] - 2) // 6
    cnt += max(acc[min(2 * a - 1, maxL)] - acc[a], 0) * L[a] * (L[a] - 1) // 2
for i in range(len(key) - 1):
    for j in range(i + 1, len(key)):
        a, b = key[i], key[j]
        cnt += L[a] * L[b] * (L[b] - 1) // 2
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
h = []
for i in set(combinations(l, 3)):
  a, b, c = i
  if a < (b + c) and b < (c + a) and c < (a + b):
    cnt += 1
print(cnt)

Fixed submission:
from collections import Counter
N = int(input())
L = Counter(int(i) for i in input().split())
maxL = max(L)
key = sorted(L.keys())
val = [L[i] for i in range(1, max(L) + 1)]
acc = [0] * (len(val) + 1)
for i in range(len(val)):
    acc[i + 1] = acc[i] + val[i]
cnt = 0
for a in key:
    cnt += L[a] * (L[a] - 1) * (L[a] - 2) // 6
    cnt += max(acc[min(2 * a - 1, maxL)] - acc[a], 0) * L[a] * (L[a] - 1) // 2
for i in range(len(key) - 1):
    for j in range(i + 1, len(key)):
        a, b = key[i], key[j]
        cnt += L[a] * L[b] * (L[b] - 1) // 2
for i in range(len(key) - 2):
    for j in range(i + 1, len(key) - 1):
        a, b = key[i], key[j]
        cnt += max(acc[min(a + b - 1, maxL)] - acc[b], 0) * L[a] * L[b]
print(cnt)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
for i in range(m):
    a[-1] //= 2
    if a[-1] < a[-2]:
        a.sort()
print(sum(a))


Fixed submission:
import heapq
n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
    mx = -heapq.heappop(a)
    heapq.heappush(a, -(mx // 2))
print(-sum(a))

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[a.index(max(a))] //= 2
print(sum(a))

Fixed submission:
import heapq
n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for _ in range(m):
    mx = -heapq.heappop(a)
    heapq.heappush(a, -(mx // 2))
print(-sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
print(sum(range(int(input()))))

Fixed submission:
n = int(input())
print(n * (n - 1) // 2)

Buggy python submission (verdict: Runtime Error):
n = int(input())
m = 0
p = list(range(2, n + 1)) + [1]
for i, pi in enumerate(p):
  m += (i + 1) % pi
print(m)

Fixed submission:
n = int(input())
print(n * (n - 1) // 2)
Buggy python submission (verdict: Runtime Error):
k, x = [int(i) for i in input().split()]
minimum = 1_000_000 - k + 1 if x + k - 1 > 1_000_000 else max(x - k + 1, -1_000_000)
maximum = -1_000_000 + k - 1 if x - k - 1 < -1_000_000 else min(x + k - 1, 1_000_000)
print(*range(minimum, maximum + 1))

Fixed submission:
k, x = [int(i) for i in input().split()]
minimum = 1000000 - k + 1 if x + k - 1 > 1000000 else max(x - k + 1, -1000000)
maximum = -1000000 + k - 1 if x - k - 1 < -1000000 else min(x + k - 1, 1000000)
print(*range(minimum, maximum + 1))

Buggy python submission (verdict: Runtime Error):
k, x = [int(i) for i in input().split()]
minimum = 1_000_000 - k + 1 if x + k - 1 > 1_000_000 else max(x - k + 1, -1_000_000)
maximum = -1_000_000 + k - 1 if x - k - 1 < -1_000_000 else min(x + k - 1, 1_000_000)
print(*range(minimum, maximum + 1))

Fixed submission:
k, x = [int(i) for i in input().split()]
minimum = 1000000 - k + 1 if x + k - 1 > 1000000 else max(x - k + 1, -1000000)
maximum = -1000000 + k - 1 if x - k - 1 < -1000000 else min(x + k - 1, 1000000)
print(*range(minimum, maximum + 1))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

k, x = [int(i) for i in input().split()]
minimum = 1_000_000 - k + 1 if x + k - 1 > 1_000_000 else max(x - k + 1, -1_000_000)
maximum = -1_000_000 + k - 1 if x - k - 1 < -1_000_000 else min(x + k - 1, 1_000_000)
print(*range(minimum, maximum + 1))

Fixed submission:
k, x = [int(i) for i in input().split()]
minimum = 1000000 - k + 1 if x + k - 1 > 1000000 else max(x - k + 1, -1000000)
maximum = -1000000 + k - 1 if x - k - 1 < -1000000 else min(x + k - 1, 1000000)
print(*range(minimum, maximum + 1))
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline

L, R = map(int, input().split())
min_mod = float('inf')
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        mod = (i * j) % 2019
        if mod < min_mod:
            min_mod = mod
print(min_mod)


Fixed submission:
l, r = [int(i) for i in input().split()]
ans = 2020
for i in range(l, r):
    for j in range(i + 1, r + 1):
        ans = min(ans, (i * j) % 2019)
        if ans == 0:
            print(ans)
            exit()
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
M = [0] * N
for i in range(N):
    op = 1
    for j in range(N):
        jj = (i + j) % N
        M[i] = M[i] + A[jj] if op == 1 else M[i] - A[jj]
        op = 1 - op
print(*M)


Fixed submission:
import math
import sys

input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
X = [sum(A)] * N
for i in range(2, N, 2):
    X[0] -= 2 * A[i - 1]
for i in range(1, N):
    X[i] = 2 * A[i - 1] - X[i - 1]
print(*X)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xy = [0] * n
for i in range(n):
    xy[i] = tuple([int(j) for j in input().split()])
loop = True
cnt = 0
while loop:
    xy_num = len(xy)
    for i in xy:
        a, b = i
        for j in xy:
            if j[0] == a and j[1] != b:
                d = j[1]
                for k in xy:
                    if k[1] == b and k[0] != a:
                        c = k[0]
                        if (c, d) not in xy:
                            xy.append((c, d))
                            cnt += 1
                    if k[1] == d and k[0] != a:
                        c = k[0]
                        if (c, b) not in xy:
                            xy.append((c, b))
                            cnt += 1
            if j[1] == b:
                c = j[0]
                for k in xy:
                    if k[0] == c and k[1] != b:
                        d = k[1]
                        if (a, d) not in xy:
                            xy.append((a, d))
                            cnt += 1
    if len(xy) == xy_num:
        loop = False
print(cnt)


Fixed submission:
s = input()
b = ''
for i in s:
  if i == b:
    print('Bad')
    exit()
  b = i
print('Good')
Buggy python submission (verdict: Runtime Error):
4
1 3 1 1

Fixed submission:
n = int(input())
w = [int(i) for i in input().split()]
s = sum(w)
for t in range(1, n):
  s = min(s, abs(sum(w[:t]) - sum(w[t:])))
print(s)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 0
for a in range(k + 1):
    pa, va = v[:a], v[a:]
    for b in range(k - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(ans, s)
print(ans)


Fixed submission:
n, k = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 0
for a in range(min(n, k) + 1):
    pa, va = v[:a], v[a:]
    for b in range(min(n, k) - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        ans = max(s, ans)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from heapq import heapify, heapreplace

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, read().split())
    a = [int(i) for i in read().split()]
    heapify(a)
    for _ in range(m):
        b, c = map(int, read().split())
        for _ in range(b):
            if a[0] < c:
                heapreplace(a, c)
            else:
                break
    print(sum(a))

if __name__ == '__main__':
    main()

Fixed submission:
import sys
from operator import itemgetter
from heapq import heapify, heapreplace

def read():
    return sys.stdin.readline().rstrip()

def main():
    n, m = map(int, read().split())
    a = [int(i) for i in read().split()]
    bc = sorted([[int(i) for i in read().split()] for _ in range(m)], key=itemgetter(1), reverse=True)
    heapify(a)
    for b, c in bc:
        for _ in range(b):
            if a[0] < c:
                heapreplace(a, c)
            else:
                break
    print(sum(a))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from functools import reduce
from math import gcd

def main():
    n = int(input())
    a = sorted(int(i) for i in input().split())
    a0 = a[0]
    if a0 == 1:
        print(reduce(gcd, a[1:]))
        return
    c = []
    for i in range(2, int(a0**0.5) + 1):
        while a0 % i == 0:
            c.append(i)
            a0 //= i
    if a0 != 1:
        c.append(a0)
    d = [0] * len(c)
    for ai in a[1:]:
        for i, ci in enumerate(c):
            if ai % ci == 0:
                ai //= ci
            else:
                d[i] += 1
    e = []
    g = 1
    for k, v in zip(c, d):
        if v == 0:
            g *= k
        elif v == 1:
            e.append(k)
    f = [1] * (n - 1)
    for i, ai in enumerate(a[1:]):
        for ei in e:
            if ai % ei == 0:
                ai //= ei
            else:
                f[i] *= ei
    print(max(g * max(f), reduce(gcd, a[1:])))

if __name__ == '__main__':
    main()

Fixed submission:
from functools import reduce
from fractions import gcd

def main():
    n = int(input())
    a = sorted(int(i) for i in input().split())
    a0 = a[0]
    if a0 == 1:
        print(reduce(gcd, a[1:]))
        return
    c = []
    for i in range(2, int(a0**0.5) + 1):
        while a0 % i == 0:
            c.append(i)
            a0 //= i
    if a0 != 1:
        c.append(a0)
    d = [0] * len(c)
    for ai in a[1:]:
        for i, ci in enumerate(c):
            if ai % ci == 0:
                ai //= ci
            else:
                d[i] += 1
    e = []
    g = 1
    for k, v in zip(c, d):
        if v == 0:
            g *= k
        elif v == 1:
            e.append(k)
    f = [1] * (n - 1)
    for i, ai in enumerate(a[1:]):
        for ei in e:
            if ai % ei == 0:
                ai //= ei
            else:
                f[i] *= ei
    print(max(g * max(f), reduce(gcd, a[1:])))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())
s = input()
lr = [map(int, input().split()) for _ in range(q)]
sub = [s[i:i + 2] == "AC" for i in range(len(s) - 1)]
acc = [sum(sub[:i]) for i in range(len(sub))] + [sum(sub)]
for l, r in lr:
  print(acc[r - 1] - acc[l - 1])

Fixed submission:
n, q = map(int, input().split())
s = input()
ac = [0] * n
for i in range(n - 1):
  ac[i + 1] = ac[i] + int(s[i:i + 2] == "AC")
for i in range(q):
  l, r = [int(lr) - 1 for lr in input().split()]
  print(ac[r] - ac[l])
Buggy python submission (verdict: Runtime Error):
from math import log2

def main():
    a, b = map(int, input().split())
    x = (b - a + 1) // 2 % 2
    for i in range(1, int(log2(b)) + 1):
        k = 0
        p = 2**i
        q = 2 * p
        pa, qa = a % p, a % q
        pb, qb = b % p, b % q
        if a % q >= p:
            k += q - qa
        if b % q >= p:
            k += qb - p + 1
        x += (k % 2) * p
    print(x)

if __name__ == '__main__':
    main()

Fixed submission:
from math import log2

def main():
    a, b = map(int, input().split())
    if a == b:
        print(a)
        return
    if b == 0:
        print(0)
        return
    d = b - a + 1
    x = (d // 2 + (d % 2) * (a % 2)) % 2
    for i in range(1, int(log2(b)) + 1):
        k = 0
        p = 2**i
        q = 2 * p
        pa, qa = a % p, a % q
        pb, qb = b % p, b % q
        if a % q >= p:
            k += q - qa
        if b % q >= p:
            k += qb - p + 1
        x += (k % 2) * p
    print(x)

if __name__ == '__main__':
    main()