Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = list(input())
y = x.count("1")
s, t = y - 1, y + 1
p = [1] * 20
for i in range(1, 20):
    p[i] = p[i - 1] * 2
p.sort(reverse = True)
a, b, u, v = 1 / 2, 1 / 2, 0, 0
m1, m2 = [0] * n, [0] * n
for i in range(1, n + 1):
    a += a
    a %= s
    b += b
    b %= t
    m1[i - 1] = a
    m2[i - 1] = b
    if x[-i] == "1":
        u += a
        v += b
ans = [1] * n
for i in range(1, n + 1):
    if x[-i] == "1":
        j = (u - m1[i - 1]) % s
    else:
        j = (v + m2[i - 1]) % t
    if not j == 0:
        while not j == 0:
            ans[-i] += 1
            l = j
            cnt = 0
            for k in p:
                if l == 0:
                    break
                if k <= l:
                    cnt += 1
                    l -= k
            j = j % cnt
for i in ans:
    print(i)

Fixed submission:
n = int(input())
x = list(input())
y = x.count("1")
s, t = y - 1, y + 1
p = [1] * 20
for i in range(1, 20):
    p[i] = p[i - 1] * 2
p.sort(reverse = True)
a, b, u, v = 1 / 2, 1 / 2, 0, 0
m1, m2 = [0] * n, [0] * n
if not s == 0:
    for i in range(1, n + 1):
        a += a
        a %= s
        b += b
        b %= t
        m1[i - 1] = a
        m2[i - 1] = b
        if x[-i] == "1":
            u += a
            v += b
else:
    for i in range(1, n + 1):
        b += b
        b %= t
        m2[i - 1] = b
        if x[-i] == "1":
            v += b
ans = [1] * n
if not s == 0:
    for i in range(1, n + 1):
        if x[-i] == "1":
            j = (u - m1[i - 1]) % s
        else:
            j = (v + m2[i - 1]) % t
        if not j == 0:
            while not j == 0:
                ans[-i] += 1
                l = j
                cnt = 0
                for k in p:
                    if l == 0:
                        break
                    if k <= l:
                        cnt += 1
                        l -= k
                j = j % cnt
else:
    for i in range(1, n + 1):
        if x[-i] == "1":
            ans[-i] = 0
        else:
            j = (v + m2[i - 1]) % t
            if not j == 0:
                while not j == 0:
                    ans[-i] += 1
                    l = j
                    cnt = 0
                    for k in p:
                        if l == 0:
                            break
                        if k <= l:
                            cnt += 1
                            l -= k
                    j = j % cnt
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    a[0] = b[0]
    for i in range(1, n):
        a[i] = b[i] + a[i - 1]
    if sum(a) == pow(n, 2):
        break
print(*a)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    b = [0] * (n + 1)
    for i in range(n):
        b[max(0, i - a[i])] += 1
        b[min(n, i + a[i] + 1)] -= 1
    a[0] = b[0]
    for i in range(1, n):
        a[i] = b[i] + a[i - 1]
    if sum(a) == pow(n, 2):
        break
print(*a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = [[a[i], i] for i in range(n)]
b.sort(reverse = True)
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(n - i + 1):
        k = i + j - 1
        if k == -1:
            continue
        if i == 0:
            dp[i][j] = dp[i][j - 1] + abs(b[k][1] - (n - j)) * b[k][0]
        elif j == 0:
            dp[i][j] = dp[i - 1][j] + abs(b[k][1] - (i - 1)) * b[k][0]
        else:
            dp[i][j] = max(dp[i][j - 1] + abs(b[k][1] - (n - j)) * b[k][0], dp[i - 1][j] + abs(b[k][1] - (i - 1)) * b[k][0])
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[i][n - i])
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [[a[i], i] for i in range(n)]
b.sort(reverse = True)
dp = [[0] * (n + 1) for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(n - i + 1):
        k = i + j - 1
        if k == -1:
            continue
        if i == 0:
            dp[i][j] = dp[i][j - 1] + abs(b[k][1] - (n - j)) * b[k][0]
        elif j == 0:
            dp[i][j] = dp[i - 1][j] + abs(b[k][1] - (i - 1)) * b[k][0]
        else:
            dp[i][j] = max(dp[i][j - 1] + abs(b[k][1] - (n - j)) * b[k][0], dp[i - 1][j] + abs(b[k][1] - (i - 1)) * b[k][0])
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[i][n - i])
print(ans)
Buggy python submission (verdict: Runtime Error):
def f(i):
    global ans
    if i == n:
        u = [0] * n
        for j in range(1, 10):
            u[0] = j
            for l in range(1, n):
                if s[l] == 0:
                    if u[l - 1] - 1 >= 0:
                        u[l] = u[l - 1] - 1
                    else:
                        return
                elif s[l] == 2:
                    if u[l - 1] + 1 <= 9:
                        u[l] = u[l - 1] + 1
                    else:
                        return
                else:
                    u[l] = u[l - 1]
            v = "".join(map(str, u))
            ans.append(int(v))
        return
    f(i + 1)
    s[i] = 2
    f(i + 1)
    s[i] = 1
    f(i + 1)
    s[i] = 0

k = int(input())
dp = [[0] * 12 for _ in range(11)]
for i in range(1, 11):
    dp[i - 1][0], dp[i - 1][11] = 0, 0
    for j in range(1, 11):
        if i == 1 and j >= 2:
            dp[i][j] = 1
        else:
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] + dp[i - 1][j + 1]
t = 0
for i in range(1, 11):
    t += sum(dp[i])
    m = t - sum(dp[i])
    if k <= t:
        n = i
        break

ans = []
s = [0] * n
f(0)
ans = list(set(ans))
ans.sort()

print(ans[k - m - 1])

Fixed submission:
from collections import deque

k = int(input())
q = deque()
for i in range(1, 10):
    q.append(i)
for _ in range(k):
    p = q.popleft()
    r = p % 10
    if r != 0:
        q.append(10 * p + r - 1)
    q.append(10 * p + r)
    if r != 9:
        q.append(10 * p + r + 1)
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def bfs(i):
    global ans
    q = deque()
    c = [0] * n
    d = [0] * n
    c[i] = 1
    d[i] = 0
    q.append(i)
    while q:
        p = q.popleft()
        if p != 0:
            if c[p - 1] == 0:
                q.append(p - 1)
                d[p - 1] += d[p] + 1
                c[p - 1] = 1
                ans[d[p - 1]] += 1
        if p != n - 1:
            if c[p + 1] == 0:
                q.append(p + 1)
                d[p + 1] += d[p] + 1
                c[p + 1] = 1
                ans[d[p + 1]] += 1
        if p == x:
            if c[y] == 0:
                q.append(y)
                d[y] = d[x] + 1
                c[y] = 1
                ans[d[y]] += 1
        if p == y:
            if c[x] == 0:
                q.append(x)
                d[x] = d[y] + 1
                c[x] = 1
                ans[d[x]] += 1
    #print(ans)
    #print(d)



n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
    bfs(i)

for i in range(1, n):
    print(ans[i] // 2)

Fixed submission:
from collections import deque

def bfs(i):
    global ans
    q = deque()
    c = [0] * n
    d = [0] * n
    c[i] = 1
    d[i] = 0
    q.append(i)
    while q:
        p = q.popleft()
        if p != 0:
            if c[p - 1] == 0:
                q.append(p - 1)
                d[p - 1] += d[p] + 1
                c[p - 1] = 1
                ans[d[p - 1]] += 1
        if p != n - 1:
            if c[p + 1] == 0:
                q.append(p + 1)
                d[p + 1] += d[p] + 1
                c[p + 1] = 1
                ans[d[p + 1]] += 1
        if p == x:
            if c[y] == 0:
                q.append(y)
                d[y] = d[x] + 1
                c[y] = 1
                ans[d[y]] += 1
        if p == y:
            if c[x] == 0:
                q.append(x)
                d[x] = d[y] + 1
                c[x] = 1
                ans[d[x]] += 1
    #print(ans)
    #print(d)


n, x, y = map(int, input().split())
x -= 1
y -= 1
ans = [0] * n
for i in range(n):
    bfs(i)

for i in range(1, n):
    print(ans[i] // 2)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
c = 0
for _ in range(q):
    t = input()
    if t != "1":
        t = t.split()
        if t[1] == "1":
            if c % 2 == 0:
                s.insert(0, t[2])
            else:
                s.append(t[2])
        else:
            if c % 2 == 0:
                s.append(t[2])
            else:
                s.insert(0, t[2])
    else:
        c += 1

if c % 2 == 1:
    s.reverse()
print("".join(s))

Fixed submission:
s = list(input())
q = int(input())
c = 0
s1 = []
s2 = []
for _ in range(q):
    t = input()
    if t != "1":
        t = t.split()
        if t[1] == "1":
            if c % 2 == 0:
                s1.append(t[2])
            else:
                s2.append(t[2])
        else:
            if c % 2 == 0:
                s2.append(t[2])
            else:
                s1.append(t[2])
    else:
        c += 1

if c % 2 == 0:
    s1.reverse()
    s = s1 + s + s2
else:
    s2.reverse()
    s3 = s
    s3.reverse()
    s = s2 + s3 + s1
print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
q = int(input())
for _ in range(q):
    c = list(map(str, input().split()))
    if int(c[0]) == 1:
        s[int(c[1]) - 1] = c[2]
    else:
        d = []
        for i in range(int(c[1]) - 1, int(c[2])):
            if not s[i] in d:
                d.append(s[i])
        print(len(d))

Fixed submission:
def RSQ_add(i, x, y):
    while True:
        if i > n:
            break
        BIT[y][i] += x
        i += i & -i

def RSQ_getsum(i, x):
    s = 0
    while True:
        if i <= 0:
            break
        s += BIT[x][i]
        i -= i & -i
    return s

n = int(input())
s = list(input())
q = int(input())
BIT = [[0] * (n + 1) for _ in range(26)]
for i in range(n):
    y = ord(s[i]) - 97
    RSQ_add(i + 1, 1, y)
for _ in range(q):
    com, a, b = map(str, input().split())
    com, a = int(com), int(a)
    if com == 1:
        RSQ_add(a, -1, ord(s[a - 1]) - 97)
        RSQ_add(a, 1, ord(b) - 97)
        s[a - 1] = b
    else:
        b = int(b)
        ans = 0
        for i in range(26):
            if RSQ_getsum(b, i) - RSQ_getsum(a - 1, i) >= 1:
                ans += 1
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
t = []
c = 0
for i in range(n):
    s = input()
    for j in range(len(t)):
        if s == t[j][0]:
            t[j][1] += 1
            c = 1
            break
    if c == 0:
        t.append([s, 1])
    c = 0
a = []
b = 0
for i in range(len(t)):
    if b < t[i][1]:
        b = t[i][1]
        a = [t[i][0]]
    elif b == t[i][1]:
        a.append(t[i][0])
a.sort()
for i in a:
    print(i)

Fixed submission:
n = int(input())
s = {}
m = 1
for _ in range(n):
    t = input()
    if t in s:
        s[t] += 1
        if s[t] > m:
            m = s[t]
    else:
        s.update({t : 1})
ans = [i for i, j in s.items() if j == m]
ans.sort()
for i in ans:
    print(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = 0
for i in range(n):
    if b == 1:
        break
    for j in range(i + 1, n):
        if a[i] == a[j]:
            b = 1
            break
if b == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = 0
for i in range(0, n - 1):
    if a[i] == a[i + 1]:
        b = 1
        break
if b == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
a = 0
b = 0
for i in range(n - k + 1):
    b = 0
    for j in range(i, i + k):
        b += p[j]
    if b > a:
        a = b
print((a + k) / 2)

Fixed submission:
n, k = map(int, input().split())
p = list(map(int, input().split()))
a = 0
b = 0
for i in range(k):
    a += p[i]
    b += p[i]
for i in range(n - k):
    a += p[i + k]
    a -= p[i]
    if b < a:
        b = a
    
print((b + k) / 2)
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a, b = [0], [0]
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
dp = [[0 for _ in range(h + max(a))] for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(1, h + max(a)):
        if i == 0:
            dp[i][j] = 10 ** 9
        elif a[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i])
ans = 10 ** 9
for i in range(h, h + max(a)):
    if ans > dp[n][i]:
        ans = dp[n][i]
print(ans)

Fixed submission:
h, n = map(int, input().split())
a, b = [0], [0]
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
dp = [[0 for _ in range(h + max(a))] for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(1, h + max(a)):
        if i == 0:
            dp[i][j] = 10 ** 9
        elif a[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i])
ans = 10 ** 9
for i in range(h, h + max(a)):
    if ans > dp[n][i]:
        ans = dp[n][i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

dp = [[10 ** 8 for _ in range(h + max(A) + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
    for j in range(1, h + max(A) + 1):
        if j <= A[i - 1]:
            dp[i][j] = min(dp[i - 1][j], B[i - 1])
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - A[i - 1]] + B[i - 1])

ans = min([dp[n][i] for i in range(h, h + max(A) + 1)])
print(ans)

Fixed submission:
h, n = map(int, input().split())
a, b = [0], [0]
for _ in range(n):
    s, t = map(int, input().split())
    a.append(s)
    b.append(t)
dp = [[0 for _ in range(h + max(a))] for _ in range(n + 1)]
for i in range(n + 1):
    for j in range(1, h + max(a)):
        if i == 0:
            dp[i][j] = 10 ** 9
        elif a[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i])
ans = 10 ** 9
for i in range(h, h + max(a)):
    if ans > dp[n][i]:
        ans = dp[n][i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
a = list(map(int, input().split()))
a.sort()
mod = 10 ** 9 + 7
ans = 0
b = [0] * n
for i in range(n - 1):
    g = gcd(a[i], a[i + 1])
    if i == 0:
        b[i] = a[i + 1] // g
        b[i + 1] = a[i] // g
        ans += b[i] + b[i + 1]
    else:
        c = a[i + 1] // g
        l = lcm(b[i], c)
        if not l == b[i]:
            ans *= l // b[i]
            ans %= mod
        c = l // c
        b[i + 1] = c * a[i] // g
        ans += b[i + 1]
    ans %= mod
print(ans if n >= 2 else 1)

Fixed submission:
def prime_factorize(n):
    ans = []
    for i in range(2, int(n ** (1 / 2)) + 1):
        c = 0
        while True:
            if not n % i == 0:
                ans.append([i, c])
                break
            n //= i
            c += 1
        if n == 1:
            break
    if n != 1:
        ans.append([int(n), 1])
    return ans

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = [0] * (5 * (10 ** 5))
for i in a:
    p = prime_factorize(i)
    for q in p:
        r = (q[0] - 1) // 2
        s[r] = max(s[r], q[1])
l = 1
for i in range(len(s)):
    l *= pow(max(2 * i + 1, 2), s[i], mod)
    l %= mod
ans = 0
for i in a:
    ans += pow(i, mod - 2, mod) * l % mod
    ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd(a, b)

n = int(input())
a = list(map(int, input().split()))
a.sort()
mod = 10 ** 9 + 7
ans = 0
b = [0] * n
for i in range(n - 1):
    g = gcd(a[i], a[i + 1])
    if i == 0:
        b[i] = a[i + 1] // g
        b[i + 1] = a[i] // g
        ans += b[i] + b[i + 1]
    else:
        c = a[i + 1] // g
        l = lcm(b[i], c)
        if not l == b[i]:
            ans *= l // b[i]
            ans %= mod
        c = l // c
        b[i + 1] = c * a[i] // g
        ans += b[i + 1]
    ans %= mod
print(ans if n >= 2 else 1)

Fixed submission:
def prime_factorize(n):
    ans = []
    for i in range(2, int(n ** (1 / 2)) + 1):
        c = 0
        while True:
            if not n % i == 0:
                ans.append([i, c])
                break
            n //= i
            c += 1
        if n == 1:
            break
    if n != 1:
        ans.append([int(n), 1])
    return ans

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
s = [0] * (5 * (10 ** 5))
for i in a:
    p = prime_factorize(i)
    for q in p:
        r = (q[0] - 1) // 2
        s[r] = max(s[r], q[1])
l = 1
for i in range(len(s)):
    l *= pow(max(2 * i + 1, 2), s[i], mod)
    l %= mod
ans = 0
for i in a:
    ans += pow(i, mod - 2, mod) * l % mod
    ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))

Fixed submission:
a, b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
def lcm(x, y):
    return (x * y) // gcd(x, y)

print(lcm(a, b))

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))

Fixed submission:
a, b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
def lcm(x, y):
    return (x * y) // gcd(x, y)

print(lcm(a, b))

Buggy python submission (verdict: Runtime Error):
import math
a, b = map(int, input().split())
c = math.gcd(a, b)
print(int(a * b / c))

Fixed submission:
a, b = map(int, input().split())

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
def lcm(x, y):
    return (x * y) // gcd(x, y)

print(lcm(a, b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
numcount = [0] * 10
ans = 0
for i in s:
    numcount[int(i)] += 1
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 0
            if numcount[i] == 0 or numcount[j] == 0 and numcount[k] == 0:
                continue
            elif ((i == j or i == k) and numcount[i] <= 1) or (j == k and numcount[j] <= 1):
                continue
            elif i == j == k and numcount[i] <= 2:
                continue
            else:
                c, l = 0, 0
                m = [i, j, k]
                while True:
                    if m[l] == int(s[c]):
                        l += 1
                    c += 1
                    if l == 3:
                        ans += 1
                        break
                    if c == n:
                        break
print(ans)

Fixed submission:
n = int(input())
s = list(input())
numcount = [0] * 10
ans = 0
for i in s:
    numcount[int(i)] += 1
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 0
            if numcount[i] == 0 or numcount[j] == 0 and numcount[k] == 0:
                continue
            elif ((i == j or i == k) and numcount[i] <= 1) or (j == k and numcount[j] <= 1):
                continue
            elif i == j == k and numcount[i] <= 2:
                continue
            else:
                c, l = 0, 0
                m = [i, j, k]
                while True:
                    if m[l] == int(s[c]):
                        l += 1
                    c += 1
                    if l == 3:
                        ans += 1
                        break
                    if c == n:
                        break
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[i - 1]
for i in range(n + 1):
    b[i] -= i
    b[i] %= k
d = dict()
for i in range(k):
    if b[i] in d:
        d[b[i]] += 1
    else:
        d[b[i]] = 1
ans = []
j = k
for i in range(n):
    ans.append(d[b[i]])
    d[b[i]] -= 1
    if j <= n:
        if b[j] in d:
            d[b[j]] += 1
        else:
            d[b[j]] = 1
    j += 1
ans = sum(ans) - n
print(ans)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * (n + 1)
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[i - 1]
for i in range(n + 1):
    b[i] -= i
    b[i] %= k
d = dict()
for i in range(min(n + 1, k)):
    if b[i] in d:
        d[b[i]] += 1
    else:
        d[b[i]] = 1
ans = []
j = min(n + 1, k)
for i in range(n):
    ans.append(d[b[i]])
    d[b[i]] -= 1
    if j <= n:
        if b[j] in d:
            d[b[j]] += 1
        else:
            d[b[j]] = 1
    j += 1
ans = sum(ans) - n
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

x, y = map(int, input().split())
n = (x + y) // 3
p = 10 ** 9 + 7
if (x + y) % 3 == 0:
    r = 0
    if x > y:
        x, y = y, x
    while True:
        if 2 * x == y:
            break
        r += 1
        x -= 2
        y -= 1
    print(comb(n, r, p))
else:
    print(0)

Fixed submission:
def comb(n, r, p):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
        x %= p
        y %= p
    return pow(y, p - 2, p) * x % p

x, y = map(int, input().split())
n = (x + y) // 3
p = 10 ** 9 + 7
if (x + y) % 3 == 0 and max(x, y) <= 2 * min(x, y):
    r = 0
    if x > y:
        x, y = y, x
    a = (2 * x - y) // 3
    r = min(a, n - a)
    print(comb(n, r, p))
else:
    print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = bisect.bisect_left(l[j + 1 : n], l[i] + l[j])
        ans += a
print(ans)

Fixed submission:
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = bisect.bisect_left(l, l[i] + l[j]) - j - 1
        ans += a
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
m = 0

for i in range(n - 2):
    for j in range(n - i - 2):
        for k in range(n - i - j - 2):
            if l[i] < l[j + i + 1] + l[k + j + i + 2] and l[j + i + 1] < l[k + j + i + 2] + l[i] and l[k + j + i + 2] < l[i] + l[j + i + 1]:
                m += 1
                
print(m)

Fixed submission:
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = bisect.bisect_left(l, l[i] + l[j]) - j - 1
        ans += a
print(ans)