Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import math
import collections

def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n)/math.factorial(n-r)/math.factorial(r)

def solve(N: int, A: "List[int]"):

    count_dict = collections.Counter(A)

    del_list = []
    for key, value in list(count_dict.items()):
        if value == 1:
            count_dict.pop(key)
            del_list.append(key)


    ans_dic = {}
    sum_all = 0
    for key, value in count_dict.items():
        tmp = int(comb(value, 2))
        ans_dic[key] = tmp
        sum_all += tmp


    for k in range(N):
        if A[k] in del_list:
            ans = sum_all
        else:
            ans = sum_all - ans_dic[A[k]] \
                + int(comb(count_dict[A[k]]-1, 2))
        print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import math
import collections

def comb(n, r):
    if n ==0 or n == 1: return 0
    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

def solve(N: int, A: "List[int]"):

    count_dict = collections.Counter(A)

    comb_list = []
    for i in range(0, N+1):
        comb_list.append(int(comb(i, 2)))

    ans_dic = {}
    sum_all = 0
    for key, value in count_dict.items():
        ans_dic[key] = comb_list[value]
        sum_all += comb_list[value]

    for k in range(N):
        ans = sum_all - ans_dic[A[k]] \
            + comb_list[count_dict[A[k]]-1]
        print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
x,y,z,p = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
"""
if x*y*z <= 3*10**6:
    abc = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                abc.append(a[i]+b[j]+c[k])
    abc.sort()
    abc = abc[::-1]
    for i in range(p):
        print(abc[i])  
    exit()
"""
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
c = c[::-1]
ab = ab[::-1]
ab.append(-2**62)
ans = []
miru = [0]*z
for i in range(z):
    if i + 1 == z:
        d = -2**60
    else:
        d = c[i+1]+ab[0]
    for j in range(i+1):
        ans.sort()
        while ab[miru[j]] + c[j] >= d and (len(ans)<= p or ab[miru[j]] + c[j] >= ans[0]):
             ans.append(ab[miru[j]] + c[j])
             miru[j]+=1
ans.sort()
ans = ans[::-1]
for i in range(p):
    print(ans[i])

### FIXED CODE ###

import sys
import math
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
x,y,z,p = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
"""
if x*y*z <= 3*10**6:
    abc = []
    for i in range(x):
        for j in range(y):
            for k in range(z):
                abc.append(a[i]+b[j]+c[k])
    abc.sort()
    abc = abc[::-1]
    for i in range(p):
        print(abc[i])  
    exit()
"""
ab = []
for i in range(x):
    for j in range(y):
        ab.append(a[i]+b[j])
ab.sort()
c = c[::-1]
ab = ab[::-1]
ab.append(-2**62)
ans = []
miru = [0]*z
for i in range(z):
    if i + 1 == z:
        d = -2**60
    else:
        d = c[i+1]+ab[0]
    for j in range(i+1):
        flag = 0
        while ab[miru[j]] + c[j] >= d and (len(ans)<= p or ab[miru[j]] + c[j] >= ans[0]):
             ans.append(ab[miru[j]] + c[j])
             miru[j]+=1
             flag = 1
        if flag and len(ans) <=p+1:
            ans.sort()
ans.sort()
ans = ans[::-1]
for i in range(p):
    print(ans[i])
### BUGGY CODE ###

#!python3

import sys
sys.setrecursionlimit(10 ** 6)

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
AB = [LI() for _ in range(M)]

# params
link = [[] for _ in range(N)]
for a, b in AB:
    link[a - 1].append(b - 1)
impossible = [False] * N


def joint(v, visit):
    if impossible[v]:
        return []
    visit = visit + [v]
    ans = []
    for u in link[v]:
        if u in visit:
            i = visit.index(u)
            return visit[i:]
        t = joint(u, visit)
        if 0 < len(t):
            if ans == [] or 0 < len(t) < len(ans):
                ans = t
    if ans == []:
        impossible[v] = True
    return ans


def main():
    ans = []
    for i in range(N):
        t = joint(i, [])
        if 0 < len(t):
            if ans == [] or 0 < len(t) < len(ans):
                ans = t
    if ans == []:
        print(-1)
        return
    print(len(ans))
    for x in ans:
        print(x + 1)
        

if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

import sys
sys.setrecursionlimit(10 ** 6)

LI = lambda: list(map(int, input().split()))

# input
N, M = LI()
AB = [LI() for _ in range(M)]

# params
link = [[] for _ in range(N)]
for a, b in AB:
    link[a - 1].append(b - 1)
impossible = [False] * N


def joint(v, visit):
    if impossible[v]:
        return None
    visit = visit + [v]
    for u in link[v]:
        if u in visit:
            i = visit.index(u)
            return visit[i:]
        t = joint(u, visit)
        if t is not None:
            return t
    impossible[v] = True
    return None


def solve(l):
    n = len(l)
    d = {l[i]: i for i in range(n)}
    for i in range(n):
        x = l[i]
        for y in link[x]:
            if y in d:
                j = d[y]
                if (i + 1) % n == j:
                    continue
                if j < i:
                    l = l[j : i + 1]
                else:
                    l = l[: i + 1] + l[j:]
                return solve(l)
    return l
            

def main():
    t = None
    for i in range(N):
        t = joint(i, [])
        if t is not None:
            break
    if t is None:
        print(-1)
        return
    
    ans = solve(t)
    print(len(ans))
    for x in ans:
        print(x + 1)
        

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import math

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])


def sqrtl(num):
    eps = pow(1.0, -10)
    a = math.sqrt(num)
    while True:
        a = (a + num / a) / 2
        if math.fabs(num - a * a) > eps:
            break
    return a


if sqrtl(a) + sqrtl(b) - sqrtl(c) < 0:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

import decimal
import math

abc = input().split(' ')
a = int(abc[0])
b = int(abc[1])
c = int(abc[2])

if decimal.Decimal(a).sqrt() + decimal.Decimal(b).sqrt() < decimal.Decimal(c).sqrt():
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N, *A = map(int, read().split())
    A.sort()
    C = Counter(A)
    A_set = set(A)

    ans = 0
    for a in A_set:
        if C[a] != 1:
            continue
        D = divisors(a)
        if all(d not in A_set for d in D[:-1]):
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    N, *A = map(int, read().split())
    A.sort()

    M = 10 ** 6
    B = [True] * (M + 1)
    B[0] = False
    ans = 0
    for i in range(N):
        if not B[A[i]]:
            continue
        if i < N - 1 and A[i + 1] == A[i]:
            B[A[i]] = False
        else:
            ans += 1
        for n in range(2 * A[i], M + 1, A[i]):
            B[n] = False

    print(ans)
    return


if __name__ == '__main__':
    main()
### BUGGY CODE ###

def main():
    import sys
    input=sys.stdin.readline
    h,n=map(int,input().split())
    a=[]
    b=[]
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append(ai)
        b.append(bi)
    inf=max(b)*h
    
    #dp[i]=体力をi減らすために消耗する魔力の最小値
    dp=[inf]*(h+max(a))
    dp[0]=0
    for i in range(h):
        for j in range(n):
            dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])
    print(min(dp[h:]))
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input=sys.stdin.readline
    h,n=map(int,input().split())
    a=[]
    b=[]
    for i in range(n):
        ai,bi=map(int,input().split())
        a.append(ai)
        b.append(bi)
    inf=max(b)*h
    
    #dp[i]=体力をi減らすために消耗する魔力の最小値
    dp=[inf]*(h+max(a))
    dp[0]=0
    for i in range(h):
        for j in range(n):
            dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])
    print(min(dp[h:]))
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input()
q = int(input())
for i in range(q):
    ii = input().split()
    if ii[0] == '1':
        s = s[::-1]
    else:
        if ii[1] == '1':
            s = ii[2] + s
        else:
            s += ii[2]
print(s)

### FIXED CODE ###

s = input()
q = int(input())
seq1 = ''
seq2 = ''
flg = 1
for i in range(q):
    ii = input().split()
    if ii[0] == '1':
        seq1, seq2 = seq2, seq1
        flg *= -1
    else:
        if ii[1] == '1':
            seq1 += ii[2]
        else:
            seq2 += ii[2]
print(seq1[::-1] + s[::flg] + seq2)
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 1
for _ in range(1,n):
    for j in range(_):
        if p[_] <= p[j]:
            if _ == j+1:
                cnt += 1
        else:
            break
print(cnt)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
cnt = 0
for _ in p:  #p[i]よりも小さいものが出てきたらだめ
    if _ <= n:
        cnt += 1
        n = _
print(cnt)
### BUGGY CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
A = []

for i in range (N - K + 1):
    x = 0
    for j in range (K):
        x += ((P[i+j]+1)/2)
        #print("i={} j={}".format(i,j))
    A.append(x)

print(max(A))

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
L = [(x+1)/2 for x in P]

ans = tmp = sum(L[:K])

for i in range (N-K):
    nxt = tmp + L[K+i] - L[i]
    ans = max(ans, nxt)
    tmp = nxt

print(ans)
### BUGGY CODE ###

n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]

m = [k] * n

for c in a :
    for e in range(n) :
        if(not(c-1 == e)) :
            m[e] -= 1

for j in range(n) :
    if(m[j] > 0) :
        print('Yes')
    else :
        print('No')

### FIXED CODE ###

n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]
m = [k-q] * n

for c in a :
    m[c-1] += 1

for j in range(n) :
    if(m[j] > 0) :
        print('Yes')
    else :
        print('No')
### BUGGY CODE ###

from collections import defaultdict
N, M, K = map(int, input().split())

F = [set() for _ in range(N)]
B = [set() for _ in range(N)]
for m in range(M):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    F[a].add(b)
    F[b].add(a)

for k in range(K):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    B[c].add(d)
    B[d].add(c)


D = defaultdict(set)
parents = [-1] * N
visited = set()
for s in range(N):
    if s in visited:
        continue

    stack = [s]
    D[s].add(s)
    while stack:
        n = stack.pop()
        visited.add(n)
        parents[n] = s
        for to in F[n]:
            if to in visited:
                continue
            D[s].add(to)
            stack.append(to)

ans = [0] * N
#print(D)
for i in range(N):
    #print(D[parents[i]] - F[i] - B[i] - {i}, F[i], B[i])
    ans[i] = len(D[parents[i]] - F[i] - B[i] - {i})

print(*ans, sep=' ')


### FIXED CODE ###

def main():
    import sys
    from collections import defaultdict
    N, M, K = map(int, sys.stdin.readline().split())

    F = [set() for _ in range(N)]
    B = [set() for _ in range(N)]
    for m in range(M):
        a, b = map(int, sys.stdin.readline().split())
        a, b = a - 1, b - 1
        F[a].add(b)
        F[b].add(a)

    for k in range(K):
        c, d = map(int, sys.stdin.readline().split())
        c, d = c - 1, d - 1
        B[c].add(d)
        B[d].add(c)

    D = defaultdict(set)
    parents = [-1] * N
    visited = set()
    for s in range(N):
        if s in visited:
            continue

        stack = [s]
        D[s].add(s)
        while stack:
            n = stack.pop()
            visited.add(n)
            parents[n] = s
            for to in F[n]:
                if to in visited:
                    continue
                D[s].add(to)
                stack.append(to)

    ans = [0] * N
    for i in range(N):
        X = D[parents[i]]
        tmp_ans = 0
        tmp_ans += len(X)
        tmp_ans -= len(F[i])
        tmp_ans -= 1
        for b in B[i]:
            if b in X:
                tmp_ans -= 1
        ans[i] = tmp_ans

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():

    s = input()

    l = len(s)

    cnt = [0 for _ in range(2019)]

    for i in range(l + 1):
        tmp = s[i:]
        if len(tmp) == 0:
            tmp = '0'
        tmp = int(tmp)
        tmp %= 2019
        cnt[tmp] += 1

    ans = 0
    for c in cnt:
        if c > 1:
            ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = input()

    cnt = [0 for _ in range(2019)]
    cnt[0] += 1
    dec = 1
    num = 0
    for i in reversed(s):
        num += int(i) * dec
        num %= 2019
        dec *= 10
        dec %= 2019
        cnt[num] += 1

    ans = 0
    for c in cnt:
        ans += c * (c - 1) // 2

    print(ans)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

import copy
N = int(input())
S = input()
ans = 0

for i in range(N-3):
    for k in range(i+3, N):
        if S[i] != S[k]:
            L = "RGB"
            L = L.replace(S[i],"",1)
            L = L.replace(S[k],"",1)
            ans += S[i+1:k].count(L)
            if (k-i) % 2 == 0:
                if S[int((k-i)/2 + i)] == L:
                    ans -= 1


print(ans)

### FIXED CODE ###

import copy
N = int(input())
S = input()

R = set()
G = set()
B = set()

for i in range(N):
    if S[i] == "R":
        R.add(i)
    elif S[i] == "G":
        G.add(i)
    else:
        B.add(i)

ans = len(R)*len(G)*len(B)

for r in R:
    for g in G:
        L = g - r
        if g + L in B:
            ans -= 1
        if r - L in B:
            ans -= 1
        if L % 2 == 0 and L//2 + r in B:
            ans -= 1
            



print(ans)
### BUGGY CODE ###

import heapq as hp

n,q=[int(x) for x in input().rstrip().split()]

l=[[] for i in range(n)]
ans=[0]*n

for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x

def dfs():
  que=[0]
  done=[0]*n  
  while(que):
    now=que.pop(0)
    done[now]=1
    for i in l[now]:
      if done[i]==0:
        que.append(i)
        ans[i]+=ans[now]
        
dfs()
print(*ans)


### FIXED CODE ###

n,q=[int(x) for x in input().rstrip().split()]
l=[[] for i in range(n)]
ans=[0]*n

for i in range(n-1):
  a,b=map(int,input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

for i in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x

def dfs():
  que=[0]
  done=[0]*n  
  done[0]=1
  while(que):
    now=que.pop()

    for i in l[now]:
      if done[i]==0:
        done[i]=1
        que.append(i)
        ans[i]+=ans[now]

dfs()
print(*ans)
### BUGGY CODE ###

l,r = map(int,input().split())
s = 2019
for k in range(l,r):
    i = k
    for l in range(i+1,r+1):
        j = l
        mo = (i*j)%2019
        if s > mo:
            s = mo
print(s)

### FIXED CODE ###

l,r = map(int,input().split())
r=min(r,l+2019)
s = 2019
for k in range(l,r):
    i = k
    for l in range(i+1,r+1):
        j = l
        mo = (i*j)%2019
        if s > mo:
            s = mo
print(s)
### BUGGY CODE ###

import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

L = []
R = []
for i in range(Q):
    (l, r) = [int(n) for n in input().split()]
    L.append(l - 1)
    R.append(r - 1)

for i in range(Q):
    count = 0
    for j in range(L[i], R[i]):
        if S[j] == 'A' and S[j + 1] == 'C':
            count += 1
    print(count)


### FIXED CODE ###

import os, sys, re, math

(N, Q) = [int(n) for n in input().split()]
S = input()

oc = [0]
n = 0
for i in range(len(S) - 1):
    if S[i:i+2] == 'AC':
        n += 1
    oc.append(n)
oc.append(n)

for i in range(Q):
    (l, r) = [int(n) for n in input().split()]
    print(oc[r - 1] - oc[l - 1])
### BUGGY CODE ###

# D - Lucky PIN

N = int(input())
S = str(input())

# 文字列Sから3文字選ぶ組み合わせを数え上げる

ans = set()
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            ans.add((S[i], S[j], S[k]))

print(len(ans))


### FIXED CODE ###

# D - Lucky PIN

N = int(input())
S = str(input())

# 文字列Sから3文字選ぶ組み合わせを数え上げるとTLE
# 暗証番号の組み合わせが高々1,000通りしかないので、
# それごとに条件に該当するかをチェックしてカウントする。
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            # i, j, kの組み合わせが起き得るか
            chk = str(i)+str(j)+str(k)
            idx = 0
            for s in S:
                if s==chk[idx]:
                    idx += 1
                    if idx == 3:
                        ans += 1
                        break
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
B = sorted([a for a in set(A) if 2<=A.count(a)])[::-1]
x = 0
y = 0

for b in B:
  if x==0:
    if 4<=A.count(b):
      x = b
      y = b
    elif 2<=A.count(b):
      x = b
  else:
    if 2<=A.count(b):
      y = b

  if x*y!=0:
    break

print(x*y)

### FIXED CODE ###

N = int(input())
A = sorted(list(map(int,input().split())),reverse=True)

for i in range(N-1):
    if A[i]==A[i+1]:
        A[i+1]=0
    else:
        A[i]=0

A.sort(reverse=True)
print(A[0]*A[1])
### BUGGY CODE ###

n,r,l=map(int,raw_input().split())
id_t=[0]*n
id_x=[0]*n
log=[map(int,raw_input().split()) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
for i in range(1,r+2):
	id_t[id_x.index(max(id_x))]+=log[i][1]-log[i-1][1]
	id_x[log[i][0]-1]+=log[i][2]
print id_t.index(max(id_t))+1

### FIXED CODE ###

def findMaxId(id_x):
	max_x=0
	max_id=0
	for i in range(n):
		if id_x[i]>max_x:
			max_x=id_x[i]
			max_id=i
	return max_id
	
n,r,l=map(int,raw_input().split())
log=[map(int,raw_input().split()) for i in range(r)]
log.insert(0,[1,0,0])
log.append([1,l,0])
id_t=[0]*n
id_x=[0]*n
max_id=0
for i in range(1,r+2):
	cur_id=log[i][0]-1
	id_t[max_id]+=log[i][1]-log[i-1][1]
	id_x[cur_id]+=log[i][2]
	if cur_id==max_id and log[i][2]<0:
		max_id=findMaxId(id_x)
	elif id_x[max_id]<id_x[cur_id] or (id_x[max_id]==id_x[cur_id] and max_id>cur_id):
		max_id=cur_id
print id_t.index(max(id_t))+1
### BUGGY CODE ###

n,k,s = map(int, input().split())

ans = ""
if s !=10**9:
    for i in range(k):
        ans = ans + str(s) + " "
    for i in range(n-k):
        ans = ans + str(10**9) + " "
    print(ans.strip())
else:
    for i in range(k):
        ans = ans + str(s) + " "
    for i in range(n-k):
        ans = ans + str(1) + " "
    print(ans.strip())
        

### FIXED CODE ###

import collections
n,k,s = input().split()



dq = collections.deque()
max_value = str(10**9)
if int(s) !=10**9:
    for i in range(int(k)):
        dq.append(s)
    for i in range(int(n)-int(k)):
        dq.append(max_value)
    ans = " ".join(list(dq))
    print(ans)
else:
    for i in range(int(k)):
        dq.append(s)
    for i in range(int(n)-int(k)):
        dq.append("1")
    ans = " ".join(list(dq))
    print(ans)
### BUGGY CODE ###

from scipy.misc import comb

x, y = map(int, input().split())
s, l = min(x,y), max(x,y)
if 2*s-l<0 or (2*s-l)%3!=0:
  print(0)
else:
  r = (2*s-l)//3
  n = 2*r+l-s
  print(comb(n,r,exact=True)%1000000007)

### FIXED CODE ###

import sys

x, y = map(int, input().split())
s, l = min(x,y), max(x,y)

if 2*s-l<0 or (2*s-l)%3!=0:
    print(0)
    sys.exit()

r = (2*s-l)//3
n = (s+l)//3
mod = 10**9+7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod%i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def comb(n, r):
    if r<0 or r>n:
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

print(comb(n, r))