Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    A, B, C, K = map(int, open(0).read().split())

    flag = True
    for i in range(0, K):
        if abs(A - B) > 10**18:
            print('Unfair')
            flag = False
            break
        elif A == B == C:
            print(0)
            flag = False
            break
        else:
            tmpA = B + C
            tmpB = A + C
            tmpC = A + B
            A = tmpA
            B = tmpB
            C = tmpC
    if flag:
        print(A - B)


main()

Fixed submission:
#!/usr/bin/env python3

def main():
    A, B, C, K = map(int, open(0).read().split())

    if abs(A - B) > 10**18:
        print('Unfair')
    else:
        if K % 2:
            print(B - A)
        else:
            print(A - B)


main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    A, B, C, K = map(int, open(0).read().split())

    flag = True
    for i in range(0, K):
        if abs(A - B) > 10**18:
            print('Unfair')
            flag = False
            break
        elif A == B == C:
            print(0)
            flag = False
            break
        else:
            tmpA = B + C
            tmpB = A + C
            tmpC = A + B
            A = tmpA
            B = tmpB
            C = tmpC
    if flag:
        print(A - B)


main()

Fixed submission:
#!/usr/bin/env python3

def main():
    A, B, C, K = map(int, open(0).read().split())

    if abs(A - B) > 10**18:
        print('Unfair')
    else:
        if K % 2:
            print(B - A)
        else:
            print(A - B)


main()
Buggy python submission (verdict: Runtime Error):
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 判定
# 2で割った余りが0の時、Evenと出力
if (a * B)% 2 == 0:
  print('Even')
# 余りが0でないとき、Oddと出力
else:
  print('Odd)

Fixed submission:
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 判定
# 2で割った余りが0の時、Evenと出力
if (a * b)% 2 == 0:
  print('Even')
# 余りが0でないとき、Oddと出力
else:
  print('Odd')

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split)
if (a * b) % 2 == 0:
  return('Even')
  else:
    return('Odd')

Fixed submission:
# スペース区切りの整数の入力
a, b = map(int, input().split())
# 判定
# 2で割った余りが0の時、Evenと出力
if (a * b)% 2 == 0:
  print('Even')
# 余りが0でないとき、Oddと出力
else:
  print('Odd')
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    for i in range(1, (A + 1)//2):
        tmp = abs(2*A*C*i -A*B*C)
        if tmp < m:
            m = tmp

    for i in range(1, (B + 1)//2):
        tmp = abs(2*A*B*i -A*B*C)
        if tmp < m:
            m = tmp
    
    for i in range(1, (C + 1)//2):
        tmp = abs(2*B*C*i -A*B*C)
        if tmp < m:
            m = tmp
    
    print(m)



main()

Fixed submission:
#!/usr/bin/env python3

def main():
    A, B, C = map(int, open(0).read().split())

    m = A*B*C
    ans = min(abs(2*A*C*(B//2) - m), abs(2*C*B*(A//2) - m), abs(2*B*A*(C//2) - m))

    print(ans)


main()
Buggy python submission (verdict: Runtime Error):
S = input()
WEEK = {'SUN':7,'MON':6,'TUE':5,'WEN':4,'THU':3,'FRI':2,'SAT':1}
print(WEEK[S])

Fixed submission:
S = input()
WEEK = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
print(WEEK[S])

Buggy python submission (verdict: Runtime Error):
S = input()
WEEK = {'SUN':7,'MON':6,'TUE':5,'WEN':4,'THU':3,'FRI':2,'SAT':1}
print(WEEK[S])

Fixed submission:
S = input()
WEEK = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1}
print(WEEK[S])
Buggy python submission (verdict: Runtime Error):
n=int(input())
c=0
for i in range(n):
    a,b=input().split()
    if b=="JPY":
        c+=float(b)
    else:
        c+=float(b)*3800
print(c)

Fixed submission:
n=int(input())
c=0
for i in range(n):
    a,b=input().split()
    if b=="JPY":
        c+=float(a)
    else:
        c+=float(a)*380000
print(c)
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = math.gcd(ans, a[i])
print(ans)

Fixed submission:
def gcd(a,b):
    if a<b:
        tmp=a
        a=b
        b=tmp
    r=a%b
    while r!=0:
        a=b
        b=r
        r=a%b
    return b

n=int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
l=[]
if m==1 and x.length()==1:
    print("0")
else:
    for i in range(m-1):
        l.append(abs(x[i]-x[i+1]))
    l.sort()
    if range(len(l)-n+1)<=0:
        print("0")
    else:
        for i in range(len(l)-n+1):
            c+=l[i]
        print(c)

Fixed submission:
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
l=[]
for i in range(m-1):
    l.append(abs(x[i]-x[i+1]))
l.sort()
if len(l)-n+1<=0:
    print("0")
else:
    for i in range(len(l)-n+1):
        c+=l[i]
    print(c)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
l=[]
if m==1 and x.length()==1:
    print("0")
else:
    for i in range(m-1):
        l.append(abs(x[i]-x[i+1]))
    l.sort()
    for i in range(len(l)-n+1):
        c+=l[i]
    print(c)

Fixed submission:
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
l=[]
for i in range(m-1):
    l.append(abs(x[i]-x[i+1]))
l.sort()
if len(l)-n+1<=0:
    print("0")
else:
    for i in range(len(l)-n+1):
        c+=l[i]
    print(c)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
for i in range(n+1):
    c+=x[i]
print(c)

Fixed submission:
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
c=0
l=[]
for i in range(m-1):
    l.append(abs(x[i]-x[i+1]))
l.sort()
if len(l)-n+1<=0:
    print("0")
else:
    for i in range(len(l)-n+1):
        c+=l[i]
    print(c)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().solit()))
num=0
dist=abs(t-h[0]*0.006)
for i in range(1,n):
    if dist>abs((t-h[i]*0.006)):
        num=i
print(num+1)



Fixed submission:
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
num=0
dist=abs(a-(t-h[0]*0.006))
for i in range(1,n):
    if dist>abs(a-(t-h[i]*0.006)):
        num=i
        dist=abs(a-(t-h[i]*0.006))
print(num+1)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(max([a+b, a-b, a*b]))

Fixed submission:
a = int(input())
s = input()
print(s if a >= 3200 else 'red')

Buggy python submission (verdict: Runtime Error):
1 a = int(input())
2 s = input()
3 print(s if a >= 3200 else 'red')

Fixed submission:
a = int(input())
s = input()
print(s if a >= 3200 else 'red')
Buggy python submission (verdict: Runtime Error):
a, b = input().split(" ")
print(max([a+b, a-b, a*b]))

Fixed submission:
A, B = [int(i) for i in input().split(" ")] 
print(max([A+B, A-B, A*B]))

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
print(max([a+b, a-b, a*b]))

Fixed submission:
A, B = [int(i) for i in input().split(" ")] 
print(max([A+B, A-B, A*B]))
Buggy python submission (verdict: Runtime Error):
A, B, C = [int(i) for i in input().split(" ")]
print(C-A+B

Fixed submission:
A, B, C = [int(i) for i in input().split(" ")]
print(C-A+B if C-A+B > 0 else 0)
Buggy python submission (verdict: Runtime Error):
s = list(input()).sort()
if s[0] == s[1] and s[2] == s [3]:
  print("Yes")
else:
  print("No")

Fixed submission:
s = list(input())
s.sort()
if s[0] == s[1] and s[2] == s [3] and s[0] != s[2]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
li = list(input())
flag = False
for i in range(li):
  if i == 0:
    continue
  flag = li[i-1] == li[i]
  if flag:
    break
print("Bad" if flag else "Good")

Fixed submission:
li = list(input())
flag = False
for i in range(len(li)):
  if i == 0:
    continue
  flag = li[i-1] == li[i]
  if flag:
    break
print("Bad" if flag else "Good")
Buggy python submission (verdict: Runtime Error):
N, K= map(int, input().split())
Nli = [int(x) for x in input().split()]
Nli.sort()
if N > K:print(sum(Nli[0:N-K]))
else: print(0)

Fixed submission:
H, A = map(int, input().split())
times = H / A
if int(times) == times:
    print(int(times))
else:
    print(int(times) + 1)
Buggy python submission (verdict: Runtime Error):
A = int(input())
i = 0
while (2 ** i) <= A:
    if (2 ** i) = A:
        print(A)
        break
    else:
        i += 1
print(2 ** (i - 1))

Fixed submission:
A = int(input())
i = 0
while (2 ** i) <= A:
    if 2 ** i == A:
        print(A)
        break
    elif (2 ** i) < A:
        i += 1
        continue
else: print(2 ** (i - 1))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
c = int((a + b) / 2)
print(c) if c == (a + b) else print(c + 1)

Fixed submission:
r, g, b = input().split()
rgb = int(r + g + b)
result = rgb % 4

if result == 0:
    print("YES")
else :
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
num = input()
a = input().split()

b=1
if '0' in a:
	b = 0
else:
	for i in a:
		b *= int(i)

if b > 10**18:
	b = -1

print(b)

Fixed submission:
num = input()
a = input().split()

b=1
if '0' in a:
	b = 0
else:
	for i in a:
		b *= int(i)
		if b > 10**18:
			b = -1
			break

print(b)

Buggy python submission (verdict: Time Limit Exceeded):
num = input()
a = input().split()

b=1
for i in a:
	b *= int(i)

if b > 10**18:
  b = -1

print(b)

Fixed submission:
num = input()
a = input().split()

b=1
if '0' in a:
	b = 0
else:
	for i in a:
		b *= int(i)
		if b > 10**18:
			b = -1
			break

print(b)
Buggy python submission (verdict: Runtime Error):
t = input().split()
n = int(t[0])
m = int(t[1])

low = 0
high = n
for i in range(0, m):
  tmp = input().split()
  if int(tmp[0]) > low:
    low = int(tmp[0])
  if int(tmp[1]) < high:
    high = int(tmp[1])

if high =< low:
  num = 0
else:
  num = high-low+1
print(num)

Fixed submission:
t = input().split()
n = int(t[0])
m = int(t[1])

low = 0
high = n
for i in range(0, m):
  tmp = input().split()
  if int(tmp[0]) > low:
    low = int(tmp[0])
  if int(tmp[1]) < high:
    high = int(tmp[1])

if (high-low)<0:
  num = 0
else:
  num = high-low+1
print(num)
Buggy python submission (verdict: Runtime Error):
num =int(input())
value = list(map(int, input().split()))
value.sort()
point = 0
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
      point = j
  if cnt == 1 or cnt == 0:
    break
print(value[0] - i)

Fixed submission:
data = input().split()
A = int(data[0])
B = int(data[1])
T = int(data[2]) + 0.5
biscuit = 0
time = A
while time < T:
  biscuit += B
  time += A

print(biscuit)

Buggy python submission (verdict: Runtime Error):
num =int(input())
value = list(map(int, input().split()))
value.sort()
point = 0
for i in range (0, value[0]):
  cnt = 0
  for j in range(0, num):
    if value[j]%(value[0]-i)!=0:
      cnt += 1
      point = j
  if cnt == 1 or cnt == 0:
    break
print(value[0] - i)

Fixed submission:
data = input().split()
A = int(data[0])
B = int(data[1])
T = int(data[2]) + 0.5
biscuit = 0
time = A
while time < T:
  biscuit += B
  time += A

print(biscuit)
Buggy python submission (verdict: Runtime Error):
num =int(input())
value = list(map(int, input().split()))
value.sort()
if num == 2:
  answer = value[1]
else:
  cnt = 0
  for i in range(0, num):
      if value[i]%(value[1])!=0:
        cnt += 1
        if cnt == 2:
          break
  if cnt == 1:
    answer = value[1]
  elif cnt == 0:
    answer = value[0]
  else:
    for i in range (0, value[0]):
      cnt = 0
      for j in range(0, num):
        if value[j]%(value[0]-i)!=0:
          cnt += 1
          if cnt == 2:
            break
      if cnt == 1:
        answer = value[0] - i
        break
print(answer)

Fixed submission:
num =int(input())
value = list(map(int, input().split()))
value.sort()
if num == 2:
  answer = value[1]
else:
  cnt = 0
  for i in range(0, num):
      if value[i]%(value[1])!=0:
        cnt += 1
        if cnt == 2:
          break
  if cnt == 1:
    answer = value[1]
  elif cnt == 0:
    answer = value[0]
  else:
    for i in range (0, value[0]):
      cnt = 0
      for j in range(0, num):
        if value[j]%(value[0]-i)!=0:
          cnt += 1
          if cnt == 2:
            break
      if cnt == 1 or cnt == 0:
        answer = value[0] - i
        break
print(answer)
Buggy python submission (verdict: Runtime Error):
s = input()

cnt_0 = 0
cnt_1 = 0
for i in range(0, len(s), 2):
  if s[i] == '0':
    cnt_0 += 1
  else:
    cnt_1 += 1

if cnt_0 > cnt_1:
  start = '0'
  second = '1'
elif cnt_0 == cnt_1:
  if s[len(s)-1] == '1':
    start = '0'
    second = '1'
  else:
    start = '1'
    second = '0'
else:
  start = '1'
  secont = '0'
cnt = 0
for i in range(0, len(s)):
  if not i%2:
    if s[i] != start:
      cnt += 1
  else:
    if s[i] != second:
      cnt += 1
print(cnt)

Fixed submission:
s = input()

cnt_0 = 0
cnt_1 = 0
for i in range(0, len(s), 2):
  if s[i] == '0':
    cnt_0 += 1
  else:
    cnt_1 += 1

if cnt_0 > cnt_1:
  first = '0'
  second = '1'
elif cnt_0 == cnt_1:
  if s[len(s)-1] == '1':
    first = '0'
    second = '1'
  else:
    first = '1'
    second = '0'
else:
  first = '1'
  second = '0'

cnt = 0
for i in range(0, len(s)):
  if not i%2:
    if s[i] != first:
      cnt += 1
  else:
    if s[i] != second:
      cnt += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

cnt = 0
flg = True
while flg:
  flg = False
  for i in range(0, n):
    if not a[i]%2:
      a[i] = a[i] / 2
      flg = True
      cnt += 1
      break

print(cnt)

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

cnt = 0
flg = True
while flg:
  flg = False
  minus = 0
  for i in range(0, len(a)):
    if not a[i+minus]%2:
      a[i+minus] = a[i+minus] / 2
      flg = True
      cnt += 1
      break
    else:
      a.pop(i+minus)
      minus -= 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
d = {'B':'R', 'R':'B'}
s = str(input())
s[1] = d[s[1]]
print(s)

Fixed submission:
s = str(input())
if(s[1] == 'B'):
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Runtime Error):
p = 1
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	p *= a[i]
    if p > 10**18:
      return -1
    
return p

Fixed submission:
def main ():
	n = int(input())
	a = list(map(int,input(). split ()))
    
	if 0 in a:
		print(0)
		return
	prod = 1
	for i in a:
		prod *= i
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)
main ()
Buggy python submission (verdict: Runtime Error):
a, b = map(int , input().split())
print(a*b)

Fixed submission:
i = list(input().split())
a = int(i[0]);
b = int(i[1][:1] + i[1][2:])
print(a*b // 100)
Buggy python submission (verdict: Runtime Error):
import math as m
a, b, h, m = map(int, input().split())
hd = h*30
md = m*6
hd += md//12
d = abs(hd - md)
cd = m.cos(d* m.pi//180)
print(round(m.sqrt(a*a + b*b - 2*a*b*cd)), 20)

Fixed submission:
import math as mt
a, b, h, m = map(int, input().split())
hd = h*30
md = m*6
hd += md/12
d = abs(hd - md)
cd = mt.cos(d* mt.pi/180)
print(round(mt.sqrt(a*a + b*b - 2*a*b*cd), 20))
Buggy python submission (verdict: Runtime Error):
a, b, b, k = map(int, input().split())
p = min(a, k)
s = p
k -= p
 
q = min(b, k)
k -= q
s -= k

r = min(c, k)
k -= r
s -= k
print(s)

Fixed submission:
a, b, c, k = map(int, input().split())
p = min(a, k)
s = p
k -= p
 
q = min(b, k)
k -= q
s -= k
 
r = min(c, k)
k -= r
s -= k
print(s)
Buggy python submission (verdict: Runtime Error):
print(int(input)* 22/7)

Fixed submission:
r = int(input())
print( 2* 22/7 * r)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def main(*, int=int, input=input):
    N = int(input())

    # スペース区切りでの入力(定数個)
    A = list(map(int, input().split()))

    if 0 in A:
        Alog = [0]
    else:
        Alog = [math.log10(x) for x in A]

    print()
    if sum(Alog)>18:
        print(-1)
    else:
        ans = 1
        for a in A:
            ans = ans * a
        if ans > 10**18:
            print(-1)
        else:
            print(ans)
    


if __name__ == "__main__":
    import io, sys
    if "_INPUT" in locals():
        sys.stdin = io.StringIO(_INPUT)
    main()

Fixed submission:
import math

def main(*, int=int, input=input):
    N = int(input())

    # スペース区切りでの入力(定数個)
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return
    else:
        Alog = [math.log10(x) for x in A]

    if sum(Alog)>18:
        print(-1)
    else:
        ans = 1
        for a in A:
            ans = ans * a
        if ans > 10**18:
            print(-1)
        else:
            print(ans)
    


if __name__ == "__main__":
    import io, sys
    if "_INPUT" in locals():
        sys.stdin = io.StringIO(_INPUT)
    main()
Buggy python submission (verdict: Runtime Error):
def solve():
  X = int(input())

  for i in range(abs(X)):
    ii = i**5
    b = (X - ii)**(0.5**5)
    bb = b **5
    # print("A   " + str(i) +"   "+  str(i ** 5))
    # print("B   " + str(b) +"   "+str(b**5))
    # print(i+b)
    if bb.is_integer():
      if ii - bb== X:
        return str(i) +" " + str(bb)
      else:
        return str(i) +' ' + str(int(-1*bb))


def main():
  print(solve())

if __name__ == "__main__":
    main()

Fixed submission:
import sys
X = int(input())
for i in range(-120,120):
  for j in range(-120,120):
    if i**5 - j **5 == X:
      print(str(i)+" "+str(j))
      sys.exit()

Buggy python submission (verdict: Runtime Error):
def solve():
  X = int(input())

  for i in range(int(X ** 0.5)):
    ii = i**5
    b = (X - ii)**(0.5**5)
    bb = b **5
    # print("A   " + str(i) +"   "+  str(i ** 5))
    # print("B   " + str(b) +"   "+str(b**5))
    # print(i+b)
    if bb.is_integer():
      if ii - bb== X:
        return str(i) +" " + str(bb)
      else:
        return str(i) +' ' + str(int(-1*bb))


def main():
  print(solve())

if __name__ == "__main__":
    main()

Fixed submission:
import sys
X = int(input())
for i in range(-120,120):
  for j in range(-120,120):
    if i**5 - j **5 == X:
      print(str(i)+" "+str(j))
      sys.exit()
Buggy python submission (verdict: Time Limit Exceeded):
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = 9 * 6
for i in range(1, N + 1):
    for k in range(1, N - i + 1):
        if N == i + k:
            m = min(m, sumDigits(i) + sumDigits(k))

print(m)

Fixed submission:
def sumDigits(i):
    s = 0
    while i > 0:
        s += (i % 10)
        i = int(i / 10)
    return s

N = int(input())

m = N
for i in range(1, N):
    k = N - i
    m = min(m, sumDigits(i) + sumDigits(k))

print(m)
Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    a = [int(input()) for i in range(1, int(input()) + 1)]
    # ループしたら終わる
    l = []
    s = a[0]
    l.append(s)
    c = 1
    while(True):
        if s == 2:
            print(c)
            return True
        s = a[s - 1]
        if s in l:
            print(-1)
            return False
        l.append(s)
        c += 1
solve()


Fixed submission:
def solve():
    N = int(input())
    a = [int(input()) for i in range(1, N + 1)]
    # ループしたら終わる
    l = []
    s = a[0]
    l = [0] * N
    c = 1
    l[0]=True
    while(True):
        l[s - 1] = True
        if s == 2:
            print(c)
            return True
        s = a[s - 1]
        if l[s - 1] == True:
            print(-1)
            return False
        c += 1
solve()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
n = 1
for i in range(1, N + 1):
    n *= i

a,b = divmod(n , 10**9 + 7)
print(b)   

Fixed submission:
N = int(input())
n = 1
for i in range(1, N + 1):
    n *= i
    n %= (10**9 + 7)
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
c = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if x + y + z == S:
                c+=1
print(c)

Fixed submission:
K,S = map(int,input().split())
c = 0
for x in range(K + 1):
    for y in range(K + 1):
        z = S - x - y
        if 0 <= z and z<= K:
            c += 1
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,x = map(int,input().split())
print(sum([1 for i in range(a,b+1) if i % x == 0]))
#print(b // x - (a - 1) // x)


Fixed submission:
import math
a,b,x = map(int,input().split())
c = 0
#print(sum([1 for i in range(a,b+1) if i % x == 0]))
print(b // x - (a - 1) // x)
Buggy python submission (verdict: Runtime Error):
import math
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



mod=1000000007
X,Y=map(int,input().split())
flag=0
count=0
for i in range(min(X,Y)//3):
    if min(X,Y)*2==max(X,Y):
        flag=1
        count2=min(X,Y)
        break
    X-=3
    Y-=3
    count+=1
    #print(X,Y)

if min(X,Y)*2==max(X,Y):
    flag=1

if flag==0:
    print('0')
    exit(0)

print(cmb(count*2+count2,count)%mod)



Fixed submission:
import math
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


count2=0
mod=1000000007
X,Y=map(int,input().split())
flag=0
count=0
for i in range(min(X,Y)//3):
    if min(X,Y)*2==max(X,Y):
        flag=1
        count2=min(X,Y)
        break
    X-=3
    Y-=3
    count+=1
    #print(X,Y)

if min(X,Y)*2==max(X,Y):
    flag=1

if flag==0:
    print('0')
    exit(0)

print(cmb(count*2+count2,count)%mod)
Buggy python submission (verdict: Runtime Error):
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(60):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        #print(count1, count2,total)
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]
#print(A)
#print(count1,count2)


print(total)


Fixed submission:
S=input()
S+="1"
A=[]
count1=0
count2=0
total=0
for i in range(600000):
    total+=i
    A.append(total)

total=0
for i in range(len(S)):
    if S[i]=="<":
        count1+=1
    if S[i]==">":
        count2+=1
    if S[i]==">" and S[i+1]=="<":
        total+=A[max(count1,count2)]
        if min(count1, count2) != 0:
            total+=A[min(count1,count2)-1]
        #print(count1, count2,total)
        count1=0
        count2=0

total+=A[max(count1,count2)]
if min(count1,count2)!=0:
    total+=A[min(count1,count2)-1]
#print(A)
#print(count1,count2)


print(total)