Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
k = int(input())

l = len(list(str(k)))

ans = l
r = int('7' * (l-1))
x = 0

while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)

Fixed submission:
k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)

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

ans = 1
r = 0
x = 0
while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)

Fixed submission:
k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)

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

ans = 1
r = 0
x = 0
while(True):
    if x == (r * 10 + 7) // k and r == (r * 10 + 7) % k:
        print(-1)
        exit()

    x = (r * 10 + 7) // k
    r = (r * 10 + 7) % k

    if r == 0:
        break
    else:
        ans += 1
print(ans)

Fixed submission:
k = int(input())

arr = [0] * (k+1)
r = 7 % k
ans = 1

while arr[r] == 0:
    if r == 0:
        print(ans)
        exit()
    arr[r] += 1
    r = (10 * r + 7) % k
    ans += 1

print(-1)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())

a = [[0] * m for j in range(n)]
c = [0] * n

ans = 10**10

for i in range(n):
    arr = list(map(int, input().split()))
    c[i] = arr[0]
    a[i] = arr[1:]

# bit全探索
import itertools
for bit in itertools.product([0,1], repeat=10):
    arr = [0] * m
    cost = 0
    for i in range(n):
        if bit[i] == 1:
            for k in range(len(a[i])):
                arr[k] += a[i][k]
            cost += c[i]

    NG = False
    for i in range(len(arr)):
        if arr[i] < x:
            NG = True
            
    if NG:
        pass
    else:
        ans = min(ans,cost)

if ans != 10**10:
    print(ans)
else:
    print(-1)


Fixed submission:
n, m, x = map(int, input().split())

a = [[0] * m for j in range(n)]
c = [0] * n

ans = 10**10

for i in range(n):
    arr = list(map(int, input().split()))
    c[i] = arr[0]
    a[i] = arr[1:]

# bit全探索
import itertools
for bit in itertools.product([0,1], repeat=n):
    arr = [0] * m
    cost = 0
    for i in range(n):
        if bit[i] == 1:
            for k in range(len(a[i])):
                arr[k] += a[i][k]
            cost += c[i]

    NG = False
    for i in range(len(arr)):
        if arr[i] < x:
            NG = True
            
    if NG:
        pass
    else:
        ans = min(ans,cost)

if ans != 10**10:
    print(ans)
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

for i in range(m):
    a[i], b[i] = map(int, input().split())

mat = [[0] * n for _ in range(n)]

for i in range(m):
    mat[a[i]-1][b[i]-1] = 1
    mat[b[i]-1][a[i]-1] = 1
ans = 0
for i in range(n):
    good = True
    for j in range(n):
        if mat[i][j] != 0:
            if h[i] <= h[j]:
                good = False
    if good:
        ans += 1

print(ans)


Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

ok = [True]*n

for i in range(m):
    a[i], b[i] = map(int, input().split())

    if h[a[i]-1] <= h[b[i]-1]:
        ok[a[i]-1] = False
    if h[b[i]-1] <= h[a[i]-1]:
        ok[b[i]-1] = False

ans = 0
for i in range(n):
    if ok[i] == True:
        ans += 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

for i in range(m):
    a[i], b[i] = map(int, input().split())

mat = [[0] * n for _ in range(n)]

for i in range(m):
    mat[a[i]-1][b[i]-1] = 1
    mat[b[i]-1][a[i]-1] = 1
ans = 0
for i in range(n):
    good = True
    for j in range(n):
        if mat[i][j] != 0:
            if h[i] <= h[j]:
                good = False
    if good:
        ans += 1

print(ans)


Fixed submission:
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m

ok = [True]*n

for i in range(m):
    a[i], b[i] = map(int, input().split())

    if h[a[i]-1] <= h[b[i]-1]:
        ok[a[i]-1] = False
    if h[b[i]-1] <= h[a[i]-1]:
        ok[b[i]-1] = False

ans = 0
for i in range(n):
    if ok[i] == True:
        ans += 1

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


arr = list(range(1,10))

x = 0
for i in range(k):
    x = arr.pop(0)
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)


Fixed submission:
k = int(input())

from collections import *
arr = deque(list(range(1,10)))

x = 0
for i in range(k):
    x = arr.popleft()
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)

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


arr = list(range(1,10))

x = 0
for i in range(k):
    x = arr.pop(0)
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)


Fixed submission:
k = int(input())

from collections import *
arr = deque(list(range(1,10)))

x = 0
for i in range(k):
    x = arr.popleft()
    if x % 10 != 0:
        arr.append(10*x - 1 + x%10)
    arr.append(10*x + x%10)
    if x % 10 != 9:
        arr.append(10*x + 1 + x%10)

print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())


arr = [[10**4] * n for i in range(n)]
for i in range(n-1):
        arr[i][i+1] = 1
        arr[i+1][i] = 1
arr[x-1][y-1] = 1
arr[y-1][x-1] = 1

import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

csr = csr_matrix(arr)
dist_m = shortest_path(csr, directed=False)

ans = [0] * (n-1)
for i in range(n):
    dist = dist_m[i].tolist()
    for j in range(len(dist)):
        ans[int(dist[j])] += 1

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


Fixed submission:
n, x, y = map(int, input().split())


min_dist = [0] * n

for i in range(n):
    for j in range(i+1,n):
        dist = min(abs(j-i), abs(j-(y-1)) + 1 +abs((x-1)-i))
        min_dist[dist] += 1

for i in range(1,n):
    print(min_dist[i])

Buggy python submission (verdict: Time Limit Exceeded):
n, x, y = map(int, input().split())


arr = [[10**4] * n for i in range(n)]
for i in range(n-1):
        arr[i][i+1] = 1
        arr[i+1][i] = 1
arr[x-1][y-1] = 1
arr[y-1][x-1] = 1

def dk(s,n,w,cost):
    d = [10**4] * n
    us = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not us[i]) and v == -1:
               v = i
            elif (not us[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        us[v] = True
               
        for x in range(n):
               d[x] = min(d[x],d[v]+cost[v][x])
    return d

ans = [0] * (n-1)
for i in range(n):
    dist = dk(i,n,n,arr)
    for j in range(len(dist)):
        ans[dist[j]] += 1

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


Fixed submission:
n, x, y = map(int, input().split())


min_dist = [0] * n

for i in range(n):
    for j in range(i+1,n):
        dist = min(abs(j-i), abs(j-(y-1)) + 1 +abs((x-1)-i))
        min_dist[dist] += 1

for i in range(1,n):
    print(min_dist[i])
Buggy python submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p.reverse()
q = list(map(int, input().split()))
q.sort()
q.reverse()
r = list(map(int, input().split()))
r.sort()
r.reverse()

p = p[:x]
q = q[:y]


arr = p + q
arr.sort()
#print(arr)
#print(r)

for i in range(len(r)):
    if arr[i] <= r[i]:
        arr[i] = r[i]

print(sum(arr))



Fixed submission:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
p.reverse()
q = list(map(int, input().split()))
q.sort()
q.reverse()
r = list(map(int, input().split()))
r.sort()
r.reverse()

p = p[:x]
q = q[:y]


arr = p + q
arr.sort()
#print(arr)
#print(r)

for i in range(min(len(arr),len(r))):
    if arr[i] <= r[i]:
        arr[i] = r[i]

print(sum(arr))
Buggy python submission (verdict: Runtime Error):
l = int(input())

arr = []
for a in range(1,l):
    for b in range(1,l):
        c = l - a - b
        if a + b + c == l:
            arr.append(a*b*c)

print(max(arr))
            


Fixed submission:
l = int(input())
       
print((l/3) ** 3)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

arr = [0]*(n+1)
for i in range(n):
    arr[a[i]] += 1

from scipy.misc import comb

c = [0]*(n+1)
for i in range(n+1):
    c[i] = int(comb(arr[i],2))

d = [0]*(n+1)
for i in range(n+1):
    d[i] = int(comb(arr[i]-1,2))


for k in range(n):
    ans = sum(c[:a[k]]) + sum(c[a[k]+1:]) + d[a[k]]
    print(ans)


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

nums = [0] * (max(a) + 1)
for i in range(len(a)):
    nums[a[i]] += 1

from scipy.special import comb

all = 0
for i in range(len(nums)):
    all += comb(nums[i], 2, exact=True)

for k in range(n):
    print(all - (nums[a[k]] - 1))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

arr = [0]*(n+1)
for i in range(n):
    arr[a[i]] += 1

from scipy.special import comb
base = comb(5, 3, exact=True)

c = [0]*(n+1)
for i in range(n+1):
    c[i] = int(comb(arr[i],2))

d = [0]*(n+1)
for i in range(n+1):
    d[i] = int(comb(arr[i]-1,2))


for k in range(n):
    ans = sum(c[:a[k]]) + sum(c[a[k]+1:]) + d[a[k]]
    print(ans)


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

nums = [0] * (max(a) + 1)
for i in range(len(a)):
    nums[a[i]] += 1

from scipy.special import comb

all = 0
for i in range(len(nums)):
    all += comb(nums[i], 2, exact=True)

for k in range(n):
    print(all - (nums[a[k]] - 1))
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int, input().split())

M = 10**9 + 7


def my_pow(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return my_pow(x ** 2, n // 2) % M
    else:
        return x * my_pow(x ** 2, (n - 1) // 2) % M

    
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

all_pattern = my_pow(2, n)
dislike = cmb(n, a) + cmb(n, b)
dislike = dislike % M


print( (all_pattern - dislike - 1) )


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

M = 10 ** 9 + 7

all = pow(2, n, M) - 1
all %= M

def C(n,x):
    num = 1
    den = 1
    for i in range(x):
        num *= (n-i)
        num %= M
        den *= (i+1)
        den %= M

    inv = pow(den, M-2, M)

    return num * inv % M

ans = all - C(n,a) - C(n,b)
ans %= M
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int, input().split())

M = 10**9 + 7

import math

def my_pow(x, n):
    if n == 0:
        return 1
    if n % 2 == 0:
        return my_pow(x ** 2, n // 2) % M
    else:
        return x * my_pow(x ** 2, (n - 1) // 2) % M

from scipy.misc import comb

all_pattern = my_pow(2, n)
dislike = comb(n, a, exact=True) + comb(n, b, exact=True)
dislike = dislike % M

print( (all_pattern - dislike - 1) )


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

M = 10 ** 9 + 7

all = pow(2, n, M) - 1
all %= M

def C(n,x):
    num = 1
    den = 1
    for i in range(x):
        num *= (n-i)
        num %= M
        den *= (i+1)
        den %= M

    inv = pow(den, M-2, M)

    return num * inv % M

ans = all - C(n,a) - C(n,b)
ans %= M
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c = map(int, input().split())
if a == b and a!= c:
    print('Yes')
elif a == c and b != c:
    print('Yes')
elif b = c and a != c:
    print('Yes')
else:
    print('No')

Fixed submission:
a,b,c = map(int, input().split())
if a == b and a!= c:
    print('Yes')
elif a == c and b != c:
    print('Yes')
elif b == c and a != c:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
p = list(map(int, input().split()))

m = -1
index = -1
for i in range(n-k+1):
    tmp = sum(p[i:i+k])
    if tmp > m:
        m = tmp
        index = i


def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)


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

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
p = list(map(int, input().split()))

m = -1
index = -1
for i in range(n-k+1):
    tmp = sum(p[i:i+k])
    if tmp > m:
        m = tmp
        index = i


def calc_exp(p):
    num = list(range(1,p+1))
    return sum(num) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)


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

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
p = list(map(int, input().split()))

m = -1
index = -1
for i in range(n-k+1):
    tmp = sum(p[i:i+k])
    if tmp > m:
        m = tmp
        index = i


def calc_exp(p):
    e = 0
    for i in range(1,p+1):
        e += i/p
    return e
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)


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

m = sum(p[:k])
index = 0
tmp = sum(p[:k])
for i in range(n-k):
    tmp -= p[i]
    tmp += p[i+k]
    if tmp > m:
        m = tmp
        index = i+1

def calc_exp(p):
    return ((p * (p+1)) / 2) / p
        
exp = 0
for i in range(index,index+k):
    exp += calc_exp(p[i])

print(exp)
Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
a = list(map,input().split())

if sum(a) >= h:
    print('Yes')
else:
    print('No')


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

if sum(a) >= h:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
h,n = map(int,input.split())
a = list(map,input().split())

if sum(a) >= h:
    print('Yes')
else:
    print('No')


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

if sum(a) >= h:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
h = list(map(int, input().split()))

h.sort()
h.reverse()
for i in range(k):
    h.pop(0)
    if len(h) == 0:
        break
print(sum(h))


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

h.sort()
for i in range(k):
    h.pop(-1)
    if len(h) == 0:
        break
print(sum(h))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
p = list(map(int, input().split()))

count = 0
while True:
    if len(p) == 1:
        break
    num = p.pop(-1)
    if num <= min(p):
        count += 1
print(count+1)


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

count = 0

m = p[0]
for i in range(len(p)):
    if m >= p[i]:
        count += 1
        m = p[i]

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i],s[i] = map(str,input().split())
    p[i] = int(p[i])

ac = []
for i in range(m):
    if s[i] == 'AC':
        ac.append(p[i])

ac = list(set(ac))

first_sub = []
for i in ac:
    for j in range(m):
        if p[j] == i:
            first_sub.append(j)
            break

ans_ng = 0
for i in range(len(ac)):
    ng = 0
    for j in range(first_sub[i],m):
        if p[j] == ac[i] and s[j] == 'WA':
            ng += 1
        elif p[j] == ac[i] and s[j] == 'AC':
            break
    ans_ng += ng
            


print(len(ac),ans_ng)


Fixed submission:
n,m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i],s[i] = map(str,input().split())
    p[i] = int(p[i])

ac = [0] * (n+1)
wa = [0] * (n+1)
for i in range(m):
    if s[i] == 'WA':
        if ac[p[i]] == 0:
            wa[p[i]] += 1
        else:
            pass
    if s[i] == 'AC':
        ac[p[i]] = 1

ac_num = 0
for i in range(len(ac)):
    if ac[i] != 0:
        ac_num += 1
ng = 0
for i in range(len(wa)):
    if ac[i] != 0:
        ng += wa[i]
            
print(ac_num,ng)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i],s[i] = map(str,input().split())
    p[i] = int(p[i])

ac = []
for i in range(m):
    if s[i] == 'AC':
        ac.append(p[i])

ac = list(set(ac))

ans_ng = 0
for id in ac:
    ng = 0
    for j in range(m):
        if p[j] == id and s[j] == 'WA':
            ng += 1
        elif p[j] == id and s[j] == 'AC':
            break
    ans_ng += ng
            


print(len(ac),ans_ng)


Fixed submission:
n,m = map(int, input().split())
p = [0] * m
s = [0] * m
for i in range(m):
    p[i],s[i] = map(str,input().split())
    p[i] = int(p[i])

ac = [0] * (n+1)
wa = [0] * (n+1)
for i in range(m):
    if s[i] == 'WA':
        if ac[p[i]] == 0:
            wa[p[i]] += 1
        else:
            pass
    if s[i] == 'AC':
        ac[p[i]] = 1

ac_num = 0
for i in range(len(ac)):
    if ac[i] != 0:
        ac_num += 1
ng = 0
for i in range(len(wa)):
    if ac[i] != 0:
        ng += wa[i]
            
print(ac_num,ng)
Buggy python submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())
print(a*b//math.gcd(a,b))

Fixed submission:
import fractions
a,b = map(int, input().split())
print(a*b//fractions.gcd(a,b))

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


Fixed submission:
import fractions
a,b = map(int, input().split())
print(a*b//fractions.gcd(a,b))
Buggy python submission (verdict: Runtime Error):
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res % (10**9+7))


Fixed submission:
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)

Buggy python submission (verdict: Runtime Error):
from math import factorial
from scipy.special import comb
x,y = map(int, input().split())

if (x + y) % 3 != 0:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    c = comb(n+m, n, exact=True)
    print(c % (10**9+7))


Fixed submission:
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)

Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())


dp =[[0] * (y+1) for i in range(x+1)]
dp[0][0] = 0
dp[1][2] = 1
dp[2][1] = 1

for i in range(2,x+1):
    for j in range(2,y+1):
        dp[i][j] = dp[i-1][j-2] % (10**9+7) + dp[i-2][j-1] % (10**9+7)

print(dp[x][y] % (10**9+7))


Fixed submission:
x,y = map(int, input().split())

mod = 10**9+7
def inv(x):
        return pow(x, mod-2, mod)
def fact(x):
        f = 1 
        for i in range(1, x + 1): 
                f *= i
                f %= mod    
        return f
def comb(n, r): 
        return (fact(n) * inv(fact(n-r)) * inv(fact(r))) % mod 

if (x + y) % 3 != 0 or y / x < 1/2 or y/x > 2:
    print(0)
else:
    n = (2*y-x)//3
    m = (2*x-y)//3
    res = comb(n+m, m)
    print(res)