Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n, q = map(int, input().split())
c = []
r = [(n - 1, -1)]
t = 0
for i in range(q):
    k, x = map(int, input().split())
    if k == 1:
        c.append((x - 1, t))
    else:
        r.append((x - 1, t))
        t += 1
c.sort()
r.sort()
idx = 0
ans = (len(c)) * (r[0][0])
for i in range(len(r) - 1):
    x, t = r[i]
    tmp = idx
    while idx < len(c) and c[idx][1] > t:
        idx += 1
    ans += c[idx][0]
    ans += (len(c) - idx) * (r[i + 1][0] - x)
print((n - 2) * (n - 2) - ans + len(c) + len(r) - 1)


Fixed submission:
n, q = map(int, input().split())
c = [(n - 1, -1)]
r = [(n - 1, -1)]
t = 0
for i in range(q):
    k, x = map(int, input().split())
    if k == 1:
        c.append((x - 1, t))
    else:
        r.append((x - 1, t))
        t += 1
c.sort()
r.sort()
idx = 0
ans = (len(c) - 1) * (r[0][0])
for i in range(len(r) - 1):
    x, t = r[i]
    tmp = idx
    while idx < len(c) and c[idx][1] > t:
        idx += 1
    ans += c[idx][0]
    ans += (len(c) - idx - 1) * (r[i + 1][0] - x)
print((n - 2) * (n - 2) - ans + len(c) + len(r) - 2)
Buggy python submission (verdict: Runtime Error):
def construct_table(n, s):
    table = [-1] * (n + 1)
    j = -1
    for i in range(n):
        while j >= 0 and s[i] != s[j]:
            j = table[j]
        j += 1
        table[i + 1] = j
    return table


n = int(input())
m = n
a = list(map(int, input().split()))
t = list(map(int, input().split()))
s2 = a + a
tb = construct_table(m, t)
l = [False] * n
i = 0
j = 0
while i < n:
    if t[j] == s2[i + j]:
        i += j - tb[j]
        if j > 0:
            j = tb[j]
    else:
        j += 1
        if j == m:
            l[i] = True
            i += j - tb[j]
            j = tb[j]
if True in l:
    print('Yes')
    idx = l.index(True)
    print(*(t[n-idx:]+t[:n-idx]))
else:
    print('No')
    exit(1)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
be = [-1] * n
la = [-1] * n
be2 = [-1] * n
la2 = [-1] * n
for i in range(n):
    if be[a[i] - 1] == -1:
        be[a[i] - 1] = i
    la[a[i] - 1] = i + 1
    if be2[b[i] - 1] == -1:
        be2[b[i] - 1] = i
    la2[b[i] - 1] = i + 1
l, r = 0, 2 * n
for i in range(n):
    if la[i] != -1 and la2[i] != -1:
        l = max(la[i] - be2[i], l)
        r = min(r, be[i] + n - la2[i])
if l > r:
    print('No')
else:
    print('Yes')
    print(*(b[n-l:] + b[:n-l]))
Buggy python submission (verdict: Time Limit Exceeded):
from functools import cmp_to_key
import heapq


def func(a, b):
    if a[0] * b[1] == a[1] * b[0]:
        return 0
    elif a[0] * b[1] > a[1] * b[0]:
        return - 1
    else:
        return 1


n, k = map(int, input().split())
c = cmp_to_key(func)
hq = list(map(lambda x: c((int(x), 1)), input().split()))
heapq.heapify(hq)
for _ in range(k):
    t = heapq.heappop(hq).obj
    heapq.heappush(hq, c((t[0], t[1] + 1)))
t = heapq.heappop(hq).obj
print((t[0] - 1) // t[1] + 1)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 10 ** 9 + 10
while r - l > 1:
    res = 0
    m = (l + r) // 2
    for x in a:
        res += (x - 1) // m
    if res <= k:
        r = m
    else:
        l = m
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import cmp_to_key
import heapq


def func(a, b):
    if a[0] * b[1] == a[1] * b[0]:
        return 0
    elif a[0] * b[1] > a[1] * b[0]:
        return - 1
    else:
        return 1


n, k = map(int, input().split())
c = cmp_to_key(func)
hq = list(map(lambda x: c((int(x), 1)), input().split()))
heapq.heapify(hq)
for _ in range(k):
    t = heapq.heappop(hq).obj
    heapq.heappush(hq, c((t[0], t[1] + 1)))
t = heapq.heappop(hq).obj
print((t[0] - 1) // t[1] + 1)


Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
l, r = 0, 10 ** 9 + 10
while r - l > 1:
    res = 0
    m = (l + r) // 2
    for x in a:
        res += (x - 1) // m
    if res <= k:
        r = m
    else:
        l = m
print(r)
Buggy python submission (verdict: Runtime Error):
INF = 10 ** 10
n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]
l = []
for i in range(n):
    if len(l) % 2 == 0:
        if a[i] > a[i + 1] <= a[i + 2]:
            l.append(a[i + 1])
    else:
        if a[i] < a[i + 1] >= a[i + 2]:
            l.append(a[i + 1])
t = 1000
for i in range(0, len(l), 2):
    t = t // l[i] * l[i + 1] + t % l[i]
print(t)


Fixed submission:
INF = 10 ** 10
n = int(input())
a = [INF] + list(map(int, input().split())) + [-INF]
l = []
for i in range(n):
    if len(l) % 2 == 0:
        if a[i + 1] < a[i + 2]:
            l.append(a[i + 1])
    else:
        if a[i + 1] > a[i + 2]:
            l.append(a[i + 1])
t = 1000
for i in range(1, len(l), 2):
    t = t // l[i - 1] * l[i] + t % l[i - 1]
print(t)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = input()
d = [0] * n
t = x.count('1')
a = 0
b = 0
for i in range(n):
    a *= 2
    b *= 2
    if x[i] == '1':
        a += 1
        b += 1
    a %= t + 1
    b %= t - 1
for i in range(n):
    if x[i] == '1':
        d[i] = (b - pow(2, n - i - 1, t - 1)) % (t - 1)
    else:
        d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
if t == 1:
    for i in range(n):
        if x[i] == '1':
            print(0)
        else:
            p = d[i]
            for p in d:
                ans = 1
                while p > 0:
                    p %= bin(p).count('1')
                    ans += 1
                print(ans)
else:
    for p in d:
        ans = 1
        while p > 0:
            p %= bin(p).count('1')
            ans += 1
        print(ans)


Fixed submission:
n = int(input())
x = input()
d = [0] * n
t = x.count('1')
a = 0
b = 0


if t == 1:
    for i in range(n):
        d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
    for i in range(n):
        a *= 2
        if x[i] == '1':
            a += 1
        a %= t + 1
    for i in range(n):
        if x[i] == '1':
            print(0)
        else:
            p = d[i]
            ans = 1
            while p > 0:
                p %= bin(p).count('1')
                ans += 1
            print(ans)
else:
    for i in range(n):
        a *= 2
        b *= 2
        if x[i] == '1':
            a += 1
            b += 1
        a %= t + 1
        b %= t - 1
    for i in range(n):
        if x[i] == '1':
            d[i] = (b - pow(2, n - i - 1, t - 1)) % (t - 1)
        else:
            d[i] = (a + pow(2, n - i - 1, t + 1)) % (t + 1)
    for i in range(n):
        a *= 2
        b *= 2
        if x[i] == '1':
            a += 1
            b += 1
        a %= t + 1
        b %= t - 1
    for p in d:
        ans = 1
        while p > 0:
            p %= bin(p).count('1')
            ans += 1
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = 1
for i in range(n):
    ans *= a[i]
if ans > 10 ** 18:
    print(-1)
else:
    print(ans)


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
    print(0)
    exit(0)
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10 ** 18:
        print(-1)
        exit(0)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for i in range(n):
    for j in range(s, a[i] - 1, -1):
        f[j] += f[j - a[i]] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])


Fixed submission:
MOD = 998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
f = [0] * (s + 1)
f[0] = pow(2, n, MOD)
v = pow(2, MOD - 2, MOD)
for x in a:
    for j in range(s, x - 1, -1):
        f[j] += f[j - x] * v
    for j in range(s + 1):
        f[j] %= MOD
print(f[s])
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
for a in range(-1000000, 1000001):
    p = a ** 5
    l, r = -100000000, 100000001
    while r - l > 1:
        m = (l + r) // 2
        if m ** 5 <= p - x:
            l = m
        else:
            r = m
    if l ** 5 == p - x:
        print(p, l)
        exit(0)


Fixed submission:
x = int(input())
for a in range(-10000, 10001):
    p = a ** 5
    l, r = -10000, 10001
    while r - l > 1:
        m = (l + r) // 2
        if m ** 5 <= p - x:
            l = m
        else:
            r = m
    if l ** 5 == p - x:
        print(a, l)
        exit(0)
Buggy python submission (verdict: Runtime Error):
n-int(input())
print((n+1)//2)

Fixed submission:
n = int(input())
print((n - 1) // 2 + 1)
Buggy python submission (verdict: Runtime Error):
"""
じょえちゃんねる
高評価・チャンネル登録よろしくお願いします！
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
"""
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - k))


Fixed submission:
"""
じょえちゃんねる
高評価・チャンネル登録よろしくお願いします！
https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
"""
n, r = map(int, input().split())
if n >= 10:
    print(r)
else:
    print(r + 100 * (10 - n))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ng, pz = [], []
z = 0
for x in a:
    if x > 0:
        pz.append(x)
    elif x < 0:
        ng.append(-x)
    else:
        z += 1
ra = list(reversed(list(map(lambda x: -x, a))))
l, r = -10 ** 19, 10 ** 19
while r - l > 1:
    if r - l < 100:
        r
    m = (l + r) // 2
    res = 0
    if m >= 0:
        res += z * (n - 1)
    for x in ng:
        idx = bisect_right(ra, m // x)
        if idx > 0 and ra[idx - 1] >= x:
            idx -= 1
        res += idx
    for x in pz:
        idx = bisect_right(a, m // x)
        if idx > 0 and a[idx - 1] >= x:
            idx -= 1
        res += idx
    if k <= res // 2:
        r = m
    else:
        l = m
print(r)


Fixed submission:
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
pz = a[a > 0]
ng = a[a < 0]
z = np.count_nonzero(a == 0)


def count(x):
    res = 0
    if x >= 0:
        res += z * n
    res += np.searchsorted(a, x // pz, side="right").sum()
    res += n * len(ng) - np.searchsorted(a, -(-x // ng), side="left").sum()
    res -= np.count_nonzero(a * a <= x)
    return res // 2


l, r = -10 ** 19, 10 ** 19
while r - l > 1:
    m = (l + r) // 2
    if count(m) >= k:
        r = m
    else:
        l = m
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_right
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ng, pz = [], []
z = 0
for x in a:
    if x > 0:
        pz.append(x)
    elif x < 0:
        ng.append(-x)
    else:
        z += 1
ra = list(reversed(list(map(lambda x: -x, a))))
l, r = -10 ** 19, 10 ** 19
while r - l > 1:
    if r - l < 100:
        r
    m = (l + r) // 2
    res = 0
    if m >= 0:
        res += z * (n - 1)
    for x in ng:
        idx = bisect_right(ra, m // x)
        if idx > 0 and ra[idx - 1] >= x:
            idx -= 1
        res += idx
    for x in pz:
        idx = bisect_right(a, m // x)
        if idx > 0 and a[idx - 1] >= x:
            idx -= 1
        res += idx
    if k <= res // 2:
        r = m
    else:
        l = m
print(r)


Fixed submission:
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
pz = a[a > 0]
ng = a[a < 0]
z = np.count_nonzero(a == 0)


def count(x):
    res = 0
    if x >= 0:
        res += z * n
    res += np.searchsorted(a, x // pz, side="right").sum()
    res += n * len(ng) - np.searchsorted(a, -(-x // ng), side="left").sum()
    res -= np.count_nonzero(a * a <= x)
    return res // 2


l, r = -10 ** 19, 10 ** 19
while r - l > 1:
    m = (l + r) // 2
    if count(m) >= k:
        r = m
    else:
        l = m
print(r)
Buggy python submission (verdict: Runtime Error):
h,a=map(int,inout().split())
print((h-1)//a+1)

Fixed submission:
h, a = map(int, input().split())
print((h - 1) // a + 1)
Buggy python submission (verdict: Runtime Error):
from math import gcd
n = int(input())
a = list(map(int, input().split()))
l = 1
for x in a:
    l = l * x // gcd(l, x)
ans = 0
for x in a:
    ans += l // x
print(ans % (10 ** 9 + 7))


Fixed submission:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
l = 1
for x in a:
    l = l * x // gcd(l, x)
ans = 0
for x in a:
    ans += l // x
print(ans % (10 ** 9 + 7))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x
    flg=True
print(ans)

Fixed submission:
n=int(input())
s=['']*n
a=[0]*n
for i in range(n):
  s[i],v=input().split()
  a[i]=int(v)
x=input()
flg=False
ans=0
for i in range(n):
  if flg:
    ans+=a[i]
  if s[i]==x:
    flg=True
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 = [0] * n
d = [0] * (2 * n - 1)
for i in range(n - 1):
    c[i] = b[i] ^ b[i + 1]
    d[i] = a[i] ^ a[i + 1]
c[n - 1] = b[0] ^ b[-1]
d[n - 1] = a[0] ^ a[-1]
for i in range(n - 1):
    d[n + i] = d[i]
t = [0] * (n + 1)
t[0] = -1
j = -1
for i in range(n):
    while j >= 0 and c[i] != c[j]:
        j = t[j]
    j += 1
    t[i + 1] = j
m = 0
ans = []
while m < n:
    for i in range(n):
        if c[i] != d[m + i]:
            m += i - t[i]
            if i > 0:
                i = t[i]
            break
    else:
        ans.append(m)
        m = m + n - t[n]
        i = t[n]
for k in ans:
    print(k, a[k] ^ b[0])


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [0] * n
d = [0] * (2 * n - 1)
for i in range(n - 1):
    c[i] = b[i] ^ b[i + 1]
    d[i] = a[i] ^ a[i + 1]
c[n - 1] = b[0] ^ b[-1]
d[n - 1] = a[0] ^ a[-1]
for i in range(n - 1):
    d[n + i] = d[i]
t = [0] * (n + 1)
t[0] = -1
j = -1
for i in range(n):
    while j >= 0 and c[i] != c[j]:
        j = t[j]
    j += 1
    t[i + 1] = j
m = 0
i = 0
ans = []
while m < n:
    if c[i] == d[m + i]:
        i += 1
        if i == n:
            ans.append(m)
            m += i - t[i]
            i = t[i]
    else:
        m += i - t[i]
        if i > 0:
            i = t[i]
for k in ans:
    print(k, a[k] ^ b[0])
Buggy python submission (verdict: Runtime Error):
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = n * n - a.searchsorted(m - a).sum()
    if res >= k:
        l = m
    else:
        r = m
b = np.array([0] * (n + 1))
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)


Fixed submission:
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = 0
    for x in a:
        res += n - bisect_left(a, m - x)
    if res >= k:
        l = m
    else:
        r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)

Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = 0
    for x in a:
        res += n - bisect_left(a, m - x)
    if res >= k:
        l = m
    else:
        r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)


Fixed submission:
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = 0
    for x in a:
        res += n - bisect_left(a, m - x)
    if res >= k:
        l = m
    else:
        r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
a.sort()
hq = [(a[0] + a[0], 0, 0)]
s = set()
ans = 0
for _ in range(m):
    x, i, j = heapq.heappop(hq)
    ans += x
    if i < n - 1 and (i + 1) * n + j not in s:
        heapq.heappush(hq, (a[i + 1] + a[j], i + 1, j))
        s.add((i + 1) * n + j)
    if j < n - 1 and i * n + j + 1 not in s:
        heapq.heappush(hq, (a[i] + a[j + 1], i, j + 1))
        s.add(i * n + j + 1)
print(-ans)


Fixed submission:
from bisect import bisect_left
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l, r = 0, 10000000000
while r - l > 1:
    m = (l + r) // 2
    res = 0
    for x in a:
        res += n - bisect_left(a, m - x)
    if res >= k:
        l = m
    else:
        r = m
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[n - i]
cnt = 0
ans = 0
for x in a:
    t = n - bisect_left(a, l - x)
    ans += b[t] + x * t
    cnt += t
print(ans - (cnt - k) * l)
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left
n,m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if v >= p:
    l, r = -1, n - p - 1
    while r - l > 1:
        flg = 0
        med = (l + r) // 2
        t = (v - p) * m
        for i in range(n - p + 1):
            if a[med] + m < a[i]:
                flg = 1
                break
        for i in range(n - p + 1):
            if i == med:
                continue
            t -= min(m, a[med] + m - a[i])
        if t > 0:
            flg = 1
        if flg:
            l = med
        else:
            r = med
    print(n - r)
else:
    exit(1)
    print(n - bisect_left(a,a[n - p] - m))


Fixed submission:
from bisect import bisect_left
n,m, v, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
if v >= p:
    l, r = -1, n - p
    while r - l > 1:
        flg = 0
        med = (l + r) // 2
        t = (v - p) * m
        for i in range(n - p + 1):
            if a[med] + m < a[i]:
                flg = 1
                break
        for i in range(n - p + 1):
            if i == med:
                continue
            t -= min(m, a[med] + m - a[i])
        if t > 0:
            flg = 1
        if flg:
            l = med
        else:
            r = med
    print(n - r)
else:
    print(n - bisect_left(a,a[n - p] - m))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0]*64
for i in range(n):
    c = bin(a[i])[2:]
    for j, q in enumerate(c):
        if q == '1':
            b[i] += 1
c = 0
b = b[::-1]
for i in range(64):
    c += b[i]*(n-b[i])*2**i
print(c % (10**9+7))


Fixed submission:
MOD = 10 ** 9 + 7
t = [0] * 60
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(60):
    cnt = 0
    for j in range(n):
        if (a[j] >> i) & 1:
            cnt += 1
    ans += cnt * (n - cnt) * pow(2, i, MOD)
print(ans % MOD)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(input())
for i in range(len(s)):
  s[i]=chr((ord(s[i])-ord('A')+n)%26+ord('A'))
print(''.join(s))


Fixed submission:
s = input()
print(['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'].index(s))
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
for i in range(len(s)):
  s[i]=chr((ord(s[i])-ord('A')+n)%26+ord('A'))
print(s)

Fixed submission:
n = int(input())
s = list(input())
for i in range(len(s)):
    s[i] = chr((ord(s[i]) - 65 + n) % 26 + 65)
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
a, b = x - t * 3, y - t * 3
if a * 2 == b or b * 2 == a:
    n = t * 2 + min(a, b)
    print((fac[n] * pow(fac[n - t], MOD - 2, MOD)
           * pow(fac[t], MOD - 2, MOD)) % MOD)
else:
    print(0)
    exit(1)


Fixed submission:
import random
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 6 * 2 + 2)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1) % MOD
x, y = map(int, input().split())
t = min(x, y) // 3
if (2 * x - y) % 3 or (2 * y - x) % 3 or 2 * x < y or 2 * y < x:
    print(0)
    exit(0)
a, b = (2 * x - y) // 3, (2 * y - x) // 3
k = min(a, b)
n = a + b
print((fac[n] * pow(fac[n - k], MOD - 2, MOD)
       * pow(fac[k], MOD - 2, MOD)) % MOD)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print(max(0,a-2*b)

Fixed submission:
a, b = map(int, input().split())
print(max(0, a - 2 * b))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if i == j:
            continue
        ans += bisect_left(l, l[i] + l[j], lo=j + 1) - j - 1
print(ans)

Fixed submission:
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        if i == j:
            continue
        ans += bisect_left(l, l[i] + l[j], lo=j + 1) - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


n, m, l = map(int, input().split())
mat = [[float('inf')] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[float('inf')] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1] - 1
    if d == float('inf'):
        print(-1)
    else:
        print(d)


Fixed submission:
def warshall_floyd(v_count: int, matrix: list) -> list:
    """ ワーシャルフロイド
    v_count: 頂点数
    matrix: 隣接行列(到達不能はfloat("inf"))
    """
    for i in range(v_count):
        for j, c2 in enumerate(row[i] for row in matrix):
            for k, (c1, c3) in enumerate(zip(matrix[j], matrix[i])):
                if c1 > c2+c3:
                    matrix[j][k] = c2+c3
    return matrix


INF = 10 ** 16
n, m, l = map(int, input().split())
mat = [[INF] * n for _ in range(n)]
for i in range(n):
    mat[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    mat[a - 1][b - 1] = c
    mat[b - 1][a - 1] = c
mat = warshall_floyd(n, mat)
fuel_mat = [[INF] * n for _ in range(n)]
for i in range(n):
    for j in range(n):
        if i == j:
            fuel_mat[i][j] = 0
        elif mat[i][j] <= l:
            fuel_mat[i][j] = 1
fuel_mat = warshall_floyd(n, fuel_mat)
q = int(input())
for _ in range(q):
    s, t = map(int, input().split())
    d = fuel_mat[s - 1][t - 1]
    if d == INF:
        print(-1)
    else:
        print(d - 1)