Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a = [list(map(str, input().split())) for i in range(q)]

head = 1

for i in range(q):
    if(a[i][0] == '1'):
        head *= -1
    else:
        if(a[i][1] == '2' and head == 1):
            s = s + a[i][2]
        elif(a[i][1] == '1' and head == -1):
            s = s + a[i][2]    
        else:
            s = a[i][2] + s
if(head == 1):
    print(s)
else:
    print(s[::-1])


Fixed submission:
s = input()
q = int(input())
a = [list(map(str, input().split())) for i in range(q)]

head = 1
ss = ''

for i in range(q):
    if(a[i][0] == '1'):
        head *= -1
    else:
        if(a[i][1] == '2' and head == 1):
            s = s + a[i][2]
        elif(a[i][1] == '1' and head == -1):
            s = s + a[i][2]    
        else:
            ss = ss + a[i][2]
if(head == 1):
    print(ss[::-1] + s)
else:
    print(s[::-1] + ss)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
a = [list(map(str, input().split())) for i in range(q)]

head = 1

for i in range(q):
    if(a[i][0] == '1'):
        head *= -1
    else:
        if(a[i][1] == '2' and head == 1):
            s = s + a[i][2]
        elif(a[i][1] == '1' and head == -1):
            s = s + a[i][2]    
        else:
            s = a[i][2] + s
if(head == 1):
    print(s)
else:
    print(s[::-1])


Fixed submission:
s = input()
q = int(input())
a = [list(map(str, input().split())) for i in range(q)]

head = 1
ss = ''

for i in range(q):
    if(a[i][0] == '1'):
        head *= -1
    else:
        if(a[i][1] == '2' and head == 1):
            s = s + a[i][2]
        elif(a[i][1] == '1' and head == -1):
            s = s + a[i][2]    
        else:
            ss = ss + a[i][2]
if(head == 1):
    print(ss[::-1] + s)
else:
    print(s[::-1] + ss)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
score = [0 for i in range(n)]
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -float('inf')
for i in range(n):
    start = i
    cur = i
    i_s_score = 0
    i_s_score_max = C[P[cur]-1]
    move_num = 0
    for j in range(n):
        cur = P[cur]-1
        i_s_score += C[cur]
        i_s_score_max = max(i_s_score, i_s_score_max)
        move_num += 1
        if cur == start:
            break
    if i_s_score <= 0:
        ans = max(ans, i_s_score_max)
    else:
        temp = i_s_score*(k//move_num)
        rest = k%move_num
        ans = max(ans, temp)
        i_s_score = temp
        for j in range(rest):
            cur = P[cur]-1
            i_s_score += C[cur]
            ans = max(ans, i_s_score)
print(ans)


Fixed submission:
n,k = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = -10**100
for i in range(n):
    start = i
    cur = i
    i_s_score = 0
    i_s_score_max = C[P[cur]-1]
    move_num = 0
    for j in range(n):
        cur = P[cur]-1
        i_s_score += C[cur]
        i_s_score_max = max(i_s_score, i_s_score_max)
        move_num += 1
        if cur == start:
            break
    if i_s_score <= 0:
        ans = max(ans, i_s_score_max)
    else:
        temp = i_s_score*(k//move_num)
        if (k//move_num >= 1):
            temp_dash = i_s_score*(k//move_num-1)+i_s_score_max
            ans = max(ans, temp_dash)
        rest = k%move_num
        ans = max(ans, temp)
        i_s_score = temp
        for j in range(rest):
            cur = P[cur]-1
            i_s_score += C[cur]
            ans = max(ans, i_s_score)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    for j in range(n):
        res += (L[j]-1)//K[i]
    if res <= k:
        P.append(K[i])
print(min(P))


Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    if K[i] > 0:
        for j in range(n):
            res += (L[j]-1)//K[i]
        if res <= k:
            P.append(K[i])
print(min(P))

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
    print(mid,cur)
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    for j in range(n):
        res += (L[j]-1)//K[i]
    if res <= k:
        P.append(K[i])
print(min(P))

Fixed submission:
n,k = map(int,input().split())
L = list(map(int,input().split()))
ok = 0
ng = 10**9
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    cur = 0
    for i in range(n):
        cur += L[i]//mid
    if cur > k:
        ok = mid
    elif cur <= k:
        ng = mid
K = [mid-1, mid, mid+1]
P = []
for i in range(3):
    res = 0
    if K[i] > 0:
        for j in range(n):
            res += (L[j]-1)//K[i]
        if res <= k:
            P.append(K[i])
print(min(P))
Buggy python submission (verdict: Runtime Error):
find . -name *.c | xargs wc -l | sort -nk1 | awk '{print $2}' | grep -v "total"

Fixed submission:
import math
p = math.pi
n = int(input())
print(2*n*p)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
S = input()
r = 0
g = 0
b = 0
for i in range(n):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        cur = j-i
        if j+cur <= n-1:
            if S[i] != S[j] and S[j] != S[j+cur] and S[j+cur] != S[i]:
                ans -= 1
print(ans)


Fixed submission:
n = int(input())
S = input()
r = 0
g = 0
b = 0
for i in range(n):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1
ans = r*g*b
for i in range(n):
    for j in range(i+1, n):
        cur = j-i
        if j+cur <= n-1:
            if S[i] != S[j] and S[j] != S[j+cur] and S[j+cur] != S[i]:
                ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w,lim = map(int,input().split())
S = []
ans = 10**10
for i in range(h):
    S.append(input())
for i in range(2**(h-1)):
    bit = ''
    cur = 1
    for j in range(h-1):
        if i&cur != 0:
            bit = '1'+bit
        else:
            bit = '0'+bit
        cur *= 2
    group = []
    if i == 0:
        group = [[i for i in range(h)]]
    else:
        div = []
        for j in range(len(bit)):
            if bit[j] == '0':
                div.append(j)
            else:
                div.append(j)
                group.append(div)
                div = []
        div.append(j+1)
        if len(div) != 0:
            group.append(div)
    num = [0]*len(group)
    cur = len(group)-1
    flag1 = True
    for j in range(w):
        next = [0]*len(group)
        flag2 = True
        for k in range(len(group)):
            plus = 0
            for l in range(len(group[k])):
                if S[group[k][l]][j] == '1':
                    plus += 1
            if plus > lim:
                flag1 = False
                break
            elif plus+num[k] > lim:
                flag2 = False
                next[k] += plus
            else:
                next[k] += plus
        if flag1 == False:
            break
        else:
            if flag2 == False:
                cur += 1
                num = next
            else:
                for k in range(len(group)):
                    num[k] += next[k]
    if flag1:
        ans = min(ans, cur)
print(ans)


Fixed submission:
h,w,lim = map(int,input().split())
S = []
ans = 10**10
for i in range(h):
    S.append(input())
for i in range(2**(h-1)):
    bit = ''
    cur = 1
    for j in range(h-1):
        if i&cur != 0:
            bit = '1'+bit
        else:
            bit = '0'+bit
        cur *= 2
    group = []
    if i == 0:
        group = [[i for i in range(h)]]
    else:
        div = []
        for j in range(len(bit)):
            if bit[j] == '0':
                div.append(j)
            else:
                div.append(j)
                group.append(div)
                div = []
        div.append(j+1)
        if len(div) != 0:
            group.append(div)
    num = [0]*len(group)
    cur = len(group)-1
    flag1 = True
    for j in range(w):
        next = [0]*len(group)
        flag2 = True
        for k in range(len(group)):
            plus = 0
            for l in range(len(group[k])):
                if S[group[k][l]][j] == '1':
                    plus += 1
            if plus > lim:
                flag1 = False
                break
            elif plus+num[k] > lim:
                flag2 = False
                next[k] += plus
            else:
                next[k] += plus
        if flag1 == False:
            break
        else:
            if flag2 == False:
                cur += 1
                num = next
            else:
                for k in range(len(group)):
                    num[k] += next[k]
    if flag1:
        ans = min(ans, cur)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
if b*10 <= a*100/8 < (b+1)*10:
    if int(a*100/8) == a*100/8:
        print(int(a*100/8))
    else:
        printf(int(a*100/8)+1)
else:
    if a*100/8 <= b*10 < (a+1)*100/8:
        print(b*10)
    else:
        print(-1)


Fixed submission:
a,b = map(int,input().split())
if b*10 <= a*100/8 < (b+1)*10:
    if int(a*100/8) == a*100/8:
        print(int(a*100/8))
    else:
        print(int(a*100/8)+1)
else:
    if a*100/8 <= b*10 < (a+1)*100/8:
        print(b*10)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])


Fixed submission:
h,a = map(int,input().split())
if h%a == 0:
  print(h//a)
else:
  print(h//a+1)
Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(10000,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])

Fixed submission:
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] > dp[i+1]:
    dp[i] = dp[i+1]
print(dp[h])

Buggy python submission (verdict: Runtime Error):
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(10000,-1,-1):
  if dp[i] == 10**8:
    dp[i] = dp[i+1]
print(dp[h])

Fixed submission:
h,n = map(int,input().split())
L = []
for i in range(n):
  l = list(map(int,input().split()))
  L.append(l)
dp = [10**8]*10001
dp[0] = 0
for i in range(n):
  dp[L[i][0]] = L[i][1]
for i in range(10001):
  for j in range(n):
    if i-L[j][0] >= 0:
      dp[i] = min(dp[i],dp[i-L[j][0]]+L[j][1])
for i in range(9999,-1,-1):
  if dp[i] > dp[i+1]:
    dp[i] = dp[i+1]
print(dp[h])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    ans = (ans+(lcm//L[i]))%m
else:
  ans = 1
print(ans)

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    k = (lcm%m)*pow(L[i],10**9+5,m)
    ans = (ans+k)%m
else:
  ans = 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    ans = (ans+((lcm//L[i])%m))%m
else:
  ans = 1
print(ans)

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    k = (lcm%m)*pow(L[i],10**9+5,m)
    ans = (ans+k)%m
else:
  ans = 1
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
lcm = L[0]*L[1]//gcd(L[0],L[1])
for i in range(2,n):
  p = gcd(L[i],lcm)
  lcm = L[i]*lcm//p
ans = 0
for i in range(n):
  ans = (ans+((lcm//L[i])%m))%m
print(ans)

Fixed submission:
n = int(input())
L = list(map(int,input().split()))
m = 10**9+7
ans = 0
def gcd(x,y):
  while y != 0:
    cur = x
    x = y
    y = cur%y
  return x
if n != 1:
  lcm = L[0]*L[1]//gcd(L[0],L[1])
  for i in range(2,n):
    p = gcd(L[i],lcm)
    lcm = L[i]*lcm//p
  for i in range(n):
    k = (lcm%m)*pow(L[i],10**9+5,m)
    ans = (ans+k)%m
else:
  ans = 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur == 0
if n != 1:
    while A[0]%2 == 0:
        cur += 1
        A[0] = A[0]//2
        flag = True
    for i in range(1,n):
        temp = 0
        while A[i]%2 == 0:
            temp += 1
            A[i] = A[i]//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= 2*m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int((2*m/A[0]-1)/2)+1)
    else:
        print(0)


Fixed submission:
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int(((2*m/A[0])-1)/2)+1)
    else:
        print(0)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
ans = 0
g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
for i in range(2, n):
    u = g
    v = A[i]//2
    p = u*v//gcd(u,v)
    g = p
if g <= m:
    print(int((m/g-1)/2)+1)
else:
    print(0)


Fixed submission:
n,m = map(int,input().split())
A = list(map(int,input().split()))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
cur = 0
if n != 1:
    t = A[0]
    while t%2 == 0:
        cur += 1
        t = t//2
        flag = True
    for i in range(1,n):
        temp = 0
        s = A[i]
        while s%2 == 0:
            temp += 1
            s = s//2
        if temp != cur:
            flag = False
            break
    if flag:
        g = A[0]*A[1]//(4*gcd(A[0]//2, A[1]//2))
        for i in range(2, n):
            u = g
            v = A[i]//2
            p = u*v//gcd(u,v)
            g = p
        if g <= m:
            print(int((m/g-1)/2)+1)
        else:
            print(0)
    else:
        print(0)
else:
    if A[0] <= 2*m:
        print(int(((2*m/A[0])-1)/2)+1)
    else:
        print(0)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
count_rsp = [0,0,0]
for i in range(k):
  hand = ['N']*(n//k+1)
  if t[i] == 'r':
      hand[0] = 'p'
      count_rsp[2] += 1
  elif t[i] == 's':
      hand[0] = 'r'
      count_rsp[0] += 1
  else:
      hand[0] = 's'
      count_rsp[1] += 1
  for j in range(i+k,n,k):
    if t[j] == 'r':
      if hand[j//k-1] != 'p':
        hand[j//k] = 'p'
        count_rsp[2] += 1
      else:
        if j+k <= n and t[j+k] == 'p':
          hand[j//k] = 'r'
        else:
          hand[j//k] = 's'
    elif t[j] == 's':
      if hand[j//k-1] != 'r':
        hand[j//k] = 'r'
        count_rsp[0] += 1
      else:
        if j+k <= n and t[j+k] == 's':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 's'
    else:
      if hand[j//k-1] != 's':
        hand[j//k] = 's'
        count_rsp[1] += 1
      else:
        if j+k <= n and t[j+k] == 's':
          hand[j//k] = 'p'
        else:
          hand[j//k] = 'r'
print(count_rsp[0]*r+count_rsp[1]*s+count_rsp[2]*p)

Fixed submission:
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
L = [[] for i in range(k)]
for i in range(n):
    L[i%k].append(t[i])
ans = 0
for i in range(k):
    if L[i][0] == 's':
        ans += r
    elif L[i][0] == 'p':
        ans += s
    else:
        ans += p
    lose = False
    for j in range(1,len(L[i])):
        if L[i][j] != L[i][j-1]:
            lose = False
            if L[i][j] == 's':
                ans += r
            elif L[i][j] == 'p':
                ans += s
            else:
                ans += p
        elif L[i][j] == L[i][j-1]:
            if lose == True:
                if L[i][j] == 's':
                    ans += r
                elif L[i][j] == 'p':
                    ans += s
                else:
                    ans += p
                lose = False
            else:
                lose = True
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
L = list(map(int,input().split()))
t = max(L)
maxstr = ''
cur = 1
while t >= cur:
    if t&cur != 0:
        maxstr = '1'+maxstr
    else:
        maxstr = '0'+maxstr
    cur *= 2
calc = [0]*len(maxstr)
for i in range(n):
    cur = 1
    temp = len(maxstr)-1
    while L[i] >= cur:
        if L[i]&cur != 0:
            calc[temp] += 1
        cur *= 2
        temp -= 1
ans = 0
cur = 1
for i in range(len(maxstr)):
    ans += cur*calc[len(maxstr)-i-1]*(n-calc[len(maxstr)-i-1])
    ans %= 10**9+7
    cur *= 2
print(ans)


Fixed submission:
n = int(input())
L = list(map(int,input().split()))
t = max(L)
maxstr = ''
cur = 1
while t >= cur:
    if t&cur != 0:
        maxstr = '1'+maxstr
    else:
        maxstr = '0'+maxstr
    cur *= 2
calc = [0]*len(maxstr)
for i in range(n):
    cur = 1
    temp = len(maxstr)-1
    while L[i] >= cur:
        if L[i]&cur != 0:
            calc[temp] += 1
        cur *= 2
        temp -= 1
ans = 0
cur = 1
for i in range(len(maxstr)):
    ans += cur*calc[len(maxstr)-i-1]*(n-calc[len(maxstr)-i-1])
    ans %= 10**9+7
    cur *= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
S = input()
cnt = 0
for i in range(1000):
  hy = i//100
  zyu = (i-hy*100)//10
  ichi = i%10
  cnt_hy = float('inf')
  cnt_zyu = float('inf')
  cnt_ichi = float('inf')
  t = 0
  for j in range(n):
    if int(S[j]) == hy and t == 0:
      cnt_hy = j
      t += 1
    elif int(S[j]) == zyu and t == 1:
      cnt_zyu = j
      t += 1
    elif int(S[j]) == ichi and t == 2:
      cnt_ichi = j
  if cnt_hy < cnt_zyu < cnt_ichi <= n-1:
    cnt += 1
print(cnt)

Fixed submission:
a,b = map(int,input().split())
c,d = map(int,input().split())
if a != c:
  print('1')
else:
  print('0')
Buggy python submission (verdict: Runtime Error):
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
x,y = map(int,input().split())
if (x+y)%3 != 0:
  print(0)
else:
  n = (x+y)//3
  r = min(abs(2*n-x),abs(n-x))
a = cmb(n,r,mod)
print(a)

Fixed submission:
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
x,y = map(int,input().split())
if (x+y)%3 != 0:
  print(0)
else:
  n = (x+y)//3
  r = min(abs(2*n-x),abs(n-x))
  if 2*n < x or x < n:
    print(0)
  else:
    a = cmb(n,r,mod)
    print(a)