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

# import sys
from collections import deque
# sys.setrecursionlimit(10 ** 5)
# input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    ans = deque([0] * N)
    con = deque([[] for _ in range(N)])

    for _ in range(N - 1):
        p, c = map(int, input().split())
        con[p-1].append(c-1)
        con[c-1].append(p-1)

    for _ in range(Q):
        p, v = map(int, input().split())
        ans[p-1] += v

    stacks = deque()
    stacks.append((0, -1))

    while stacks:
        stack = stacks.pop()
        node, parent = stack[0], stack[1]

        children = con[node]
        for child in children:
            if child == parent:
                continue
            ans[child] += ans[node]
            stacks.append((child, node))

    print(*ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
edge = [[] for i in range(N)]
ops = []
ans = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
for _ in range(Q):
    ops.append(tuple(map(int, input().split())))

for op in ops:
    node = op[0] - 1
    pnt = op[1]
    ans[node] += pnt

stack = deque()
stack.append((0, -1))

while stack:
    st = stack.pop()
    node, parent = st[0], st[1]
    children = edge[node]
    for child in children:
        if child == parent:
            continue
        ans[child] += ans[node]
        stack.append((child, node))

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

n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    sortlist.append(a)
    
count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    b=int(times*(times-1)/2)
    count+=b
    
print(int(count) )   

### FIXED CODE ###

n=int(input())

#単語が全て入ったリストを作るO(n)
wordlist=[input() for i in range(n)]

#wordlistを一つ一つソートさせたものをsortlistとして作るO（n）
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    sortlist.append(a)
    
count=0

#ソートリストをソートするO(nlogn)
sortlist.sort()

checkword=""
check=0

for i in range(n): #O(n)
    a=sortlist.pop()
    if checkword==a:
            check+=1
            count+=check
    else:
        check=0
        checkword=a
    
print(int(count) )
### BUGGY CODE ###

import math
A,B,N=map(int,input().split())
start=0
for i in range(1,N+1):
    K=math.floor((A*i)/B)-A*(math.floor(i/B))
    if start<=K:
        start=K
print(start)

### FIXED CODE ###

import math
A,B,N=map(int,input().split())
start=0
i=min(B-1,N)
K=math.floor((A*i)/B)-A*(math.floor(i/B))
if start<=K:
    start=K
print(start)
### BUGGY CODE ###

S = str(input())
Q = int(input())


for i in range(Q):
    query = input()
    if query[0] == '1':
        S = S[::-1]
    else:
        t, f, c = query.split()
        if f == '1':
            S = c + S
        else:
            S = S + c

print(S)


### FIXED CODE ###

from collections import deque

S = str(input())
Q = int(input())

d = deque([S[i] for i in range(len(S))])
#print(d)

flg = 0

for i in range(Q):
    query = input()
    if query[0] == '1':
        flg = flg%2 + 1
    else:
        t, f, c = query.split()
        if f == '1':
            if flg % 2 == 0:
                d.appendleft(c)
            else:
                d.append(c)
        else:
            if flg % 2 == 0:
                d.append(c)
            else:
                d.appendleft(c)
if flg % 2 == 0:
    print(''.join(list(d)))
else:
    tmp = ''.join(list(d))
    print(tmp[::-1])
### BUGGY CODE ###

n = int(input())
S = input()
ans = n

for i in range(n):
    num = S[:i].count('W') + S[i+1:].count('E')
    if num < ans:
        ans = num
print(ans)


### FIXED CODE ###

n = int(input())
S = input()
ans = n
num_list = []
W_count = 0

for i in range(n):
    if S[i] == 'W':
        W_count += 1
    num_list.append(W_count)

for i in range(1, n-1):
    left_w = num_list[i-1]
    right_e = n - num_list[n-1] - (1+i - num_list[i])
    pre_ans = left_w + right_e
    if ans > pre_ans:
        ans = pre_ans

ans_0 = n-num_list[n-1] - (1-num_list[0])
ans_n = num_list[n-2]
print(min(ans, ans_0, ans_n))
### BUGGY CODE ###

N, M = input().split()
N = int(N)
M = int(M)
li = []
for i in range(M):
  liin = input().split()
  li.append([int(liin[0]), str(liin[1])])

ans = [0, 0]
done = []
miss = {}

for i in range(M):
  if li[i][0] in done:
    continue
  if li[i][1] == "AC":
    ans[0] += 1
    done.append(li[i][0])
    if li[i][0] in miss.keys():
      ans[1] += miss[li[i][0]]
      del miss[li[i][0]]
  else: # "WA"
    if li[i][0] in miss.keys():
      miss[li[i][0]] += 1
    else:
      miss[li[i][0]] = 1

print(ans[0],ans[1])

### FIXED CODE ###

N, M = map(int, input().split())
li = []
for i in range(M):
  liin = input().split()
  li.append([int(liin[0]), liin[1]])

ans1, ans2 = 0, 0
done = set([0])
miss = {}

for i in range(M):
  if li[i][0] in done:
    continue
  if li[i][1] == "AC":
    ans1 += 1
    done.add(li[i][0])
    if li[i][0] in miss:
      ans2 += miss[li[i][0]]
      del miss[li[i][0]]
  else: # "WA"
    if li[i][0] in miss:
      miss[li[i][0]] += 1
    else:
      miss[li[i][0]] = 1

print(ans1,ans2)
### BUGGY CODE ###

n=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            flag1=False
            flag2=False
            flag3=False
            for s in S:
                if s==str(i) and not(flag1):
                    flag1=True
                    continue
                if s==str(j) and flag1 and not(flag2):
                    flag2=True
                    continue
                if s==str(k) and flag1 and flag2 and not(flag3):
                    flag3=True
                    continue
            if flag1 and flag2 and flag3:
                ans+=1
print(ans)



### FIXED CODE ###

n=int(input())
S=input()
ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            x=str(i)+str(j)+str(k)
            p=S.find(x[0])
            q=S.find(x[1],p+1)
            r=S.find(x[2],q+1)
            if p!=-1 and q!=-1 and r!=-1:
                ans+=1
print(ans)
### BUGGY CODE ###

#encoding utf-8

N, M, Q = map(int, input().split())

L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

p = []
q = []

for i in range(Q):
    pa, qa = map(int, input().split())
    p.append(pa)
    q.append(qa)

# def Answer(i):
#     count = 0
#     for j in range(M):
#         if p[i] <= L[j] and R[j] <= q[i]:
#             count += 1
#     return count

for i in range(Q):
    count = 0
    for j in range(M):
        if p[i] <= L[j] and R[j] <= q[i]:
            count += 1
    print(count)


### FIXED CODE ###


N, M, Q = map(int, input().split())
rail = []
for i in range(M):
    r = list(map(int, input().split()))
    rail.append(r)
 
query = []
for i in range(Q):
    q = list(map(int, input().split()))
    query.append(q)
 
f = [[0 for i in range(N)] for j in range(N)]
g = [[0 for i in range(N)] for j in range(N)]
 
for i in range(M):
    f[rail[i][0]-1][rail[i][1]-1] += 1
 
for i in range(N):
    j = 0
    while j + i < N:
        if i == 0:
            g[j][j+i] = f[j][j+i]
        else:
            g[j][j+i] = f[j][j+i] + g[j+1][j+i] + g[j][j+i-1] - g[j+1][j+i-1]
        j += 1
 
for i in range(Q):
    print(g[query[i][0]-1][query[i][1]-1])
### BUGGY CODE ###

from math import gcd
N = int(input())
A = list(map(int,input().split()))

A.reverse()
val = A[0]
flg = True
for i in range(1,N):
    if gcd(val,A[i]) != 1:
        flg = False
    val *= A[i]
if flg == True:
    print('pairwise coprime')
    exit()





val = A[0]
for i in range(1,N):
    val = gcd(val,A[i])
if val == 1:
    print('setwise coprime')
    exit()
print('not coprime')

### FIXED CODE ###

from math import gcd
INF = float('inf')
N = int(input())
A = list(map(int,input().split()))
flg = True
lis = [INF] * (10**6+5)
for i in range(2,int((10**6)**0.5)+1):
    if lis[i] == INF:
        for j in range(i*2,10**6+1,i):
            lis[j] = i
st = set()
for i in range(N):
    p = A[i]
    d  =[]
    while lis[p] != INF:
        d.append(lis[p])
        p //= lis[p]
    if p > 1:
        d.append(p)
    for i in range(len(d)):
        if d[i] in st:
            flg = False
    for i in range(len(d)):
        st.add(d[i]) 
#print(lis[:15])

if flg == True:
    print('pairwise coprime')
    exit()



val = A[0]
for i in range(1,N):
    val = gcd(val,A[i])
if val == 1:
    print('setwise coprime')
    exit()
print('not coprime')
### BUGGY CODE ###

a,b=map(int,input().split())
L=[]
l=[]
for i in range(b):
    L.append(list(map(int,input().split())))
for i in range(b):
    x=0
    for j in range(b):
        if not j==i and L[i][0]==L[j][0] and L[i][1]>L[j][1]:
            x+=1
    l.append('0'*(6-len(str(L[i][0])))+str(L[i][0])+'0'*(6-len(str(x+1)))+str(x+1))
for r in range(b):
        print(l[r])

### FIXED CODE ###

a,b=map(int,input().split())
L=[[] for i in range(a)]
u=0
for i in range(b):
    u+=1
    c=list(map(int,input().split()))
    c.append(u)
    L[int(c[0])-1].append(c)
for i in L:
    i.sort(key=lambda x:x[1])
for i in L:
    e=0
    for j in i:
        e+=1
        j.append(e)
q=[]
for w in L:
   q.extend(w) 
q.sort(key=lambda x:x[2])
for r in range(b):
        print('0'*(6-len(str(q[r][0])))+str(q[r][0])+'0'*(6-len(str(q[r][3])))+str(q[r][3]))
### BUGGY CODE ###

#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        if b not in not_good:
            not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        if a not in not_good:
            not_good.append(a)
        if b not in not_good:
            not_good.append(b)
    else:
        if a not in not_good:
            not_good.append(a)
ans = 0
not_good.sort()
# print(not_good)
idx = 0
for i in range(1, n + 1):
    if i < not_good[idx]:
        ans += 1
        # print(i, end=" ")
    elif i == not_good[idx]:
        idx += 1
        if idx == len(not_good):
            ans += n - i
            break
    else:
        pass
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
n, m = map(int, input().split())
h = list(map(int, input().split()))
not_good = []
for i in range(m):
    a, b = map(int, input().split())
    if h[a - 1] > h[b - 1]:  # bはダメ
        not_good.append(b)
    elif h[a - 1] == h[b - 1]:
        not_good.append(a)
        not_good.append(b)
    else:
        not_good.append(a)
ans = 0
not_good = list(set(not_good))
not_good.sort()
# print(not_good)
idx = 0
for i in range(1, n + 1):
    if i < not_good[idx]:
        ans += 1
        # print(i, end=" ")
    elif i == not_good[idx]:
        idx += 1
        if idx == len(not_good):
            ans += n - i
            break
    else:
        pass
print(ans)
### BUGGY CODE ###

import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
BlackVis = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and not BlackVis[h][w]:
            Visited = [[False for w in range(W)] for h in range(H)]
            Visited[h][w] = True
            Q = queue.Queue()
            Q.put((h,w))
            Mult = 1
            Count = 0
            while not Q.empty():
                now = Q.get()
                color = S[now[0]][now[1]]
                for s in Search:
                    if 0 <= now[0] + s[0] < H and 0 <= now[1]+s[1] < W:
                        if color == "#":
                            if S[now[0]+s[0]][now[1]+s[1]] == "." and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                Count += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
                        else:
                            if S[now[0]+s[0]][now[1]+s[1]] == "#" and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                BlackVis[now[0]+s[0]][now[1]+s[1]] = True
                                Mult += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
            Total += Count * Mult 
print(Total)

### FIXED CODE ###

import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)
### BUGGY CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
now = list(mapint())
from math import sqrt
import numpy as np
iteration = min(N.bit_length()*2, K)
for k in range(iteration):
    nx = np.array([0]*N)
    for i, a in enumerate(now):
        nx[max(0, i-a):min(i+a+1, N)] += 1
    now = list(nx)
print(*now)

### FIXED CODE ###

import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
now = list(mapint())
from itertools import accumulate
iteration = min(N.bit_length()*4, K)
for k in range(iteration):
    nx = [0]*N
    for i, a in enumerate(now):
        nx[max(0, i-a)] += 1
        if i+a+1<N:
            nx[i+a+1] -= 1
    nx = list(accumulate(nx))
    now = nx[:]
print(*now)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def main():
  n = int(input())

  D = [[[-1]*(n+1) for _ in range(n+1)] for i in range(n+1)]
  def dfs(b, c, d):
    if b == c == d == 0:
      return 0
    if D[b][c][d] != -1:
      return D[b][c][d]
    rep = n
    if b != 0:
      rep += b * dfs(b-1, c, d)
    if c != 0:
      rep += c * dfs(b+1, c-1, d)
    if d != 0:
      rep += d * dfs(b, c+1, d-1)
    rep /= (b+c+d)
    D[b][c][d] = rep
    return rep

  L = [0]*3
  for a in map(int, input().split()):
    L[a-1] += 1
  ans = dfs(*L)
  print(ans)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
A = tuple(map(int, input().split()))
C = [0]*3
for a in A:
  C[a-1] += 1
dp = [[[-1]*(n+1) for i in range(n+1)] for j in range(n+1)]
dp[0][0][0] = 0
def f(i, j, k):
  if dp[i][j][k] != -1:
    return dp[i][j][k]
  res = 1
  if i:
    res += f(i-1, j, k)*(i/n)
  if j:
    res += f(i+1, j-1, k)*(j/n)
  if k:
    res += f(i, j+1, k-1)*(k/n)
  res /= (i+j+k)/n
  dp[i][j][k] = res
  return res
ans = f(C[0], C[1], C[2])
print(ans)
### BUGGY CODE ###

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
    tmp %= 2019
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))
### BUGGY CODE ###

A,B,K = map(int,input().split())
while(K > 0):
    if A > 0:
        A -= 1
    else:
        B -= 1
    K -= 1
print(A,B)

### FIXED CODE ###

A,B,K = map(int,input().split())
if A >= K:
    print(A - K,B)
else:
    print(0, max( B - (K - A),0 )  )
### BUGGY CODE ###

#coding: utf-8
msprime = []
i = 6
MAX = 300000
while i <= MAX:
    for p in msprime:
        if i % p == 0:
            break
    else:
        msprime.append(i)
        j = i * 2
    if i % 7 == 6:
        i += 2
    else:
        i += 5
print msprime

while True:
    n = int(raw_input())
    if n == 1: break
    fact = []
    for i in msprime:
        if n % i == 0:
            fact.append(i)
    print str(n)+":",
    for i in fact:
        print i,
    print ""

### FIXED CODE ###

#coding: utf-8
import sys

msprime = []
i = 6
MAX = 300000
isprime = [1]*300001
while i*i <= MAX: #?????????????´???°?????????????±???????
    for p in msprime:
        if i % p == 0:
            break
    else:
        msprime.append(i)
        j = i * 2
        while j <= MAX:
            isprime[j] = 0
            j += i
    if i % 7 == 6:
        i += 2
    else:
        i += 5
else:
    tmp = i

for i in range(tmp,MAX):
    if isprime[i] == 1 and i % 7 in (1,6):
        msprime.append(i)

while True:
    n = int(raw_input())
    if n == 1: break
    fact = []
    for i in msprime:
        if n % i == 0:
            fact.append(i)
    sys.stdout.write(str(n)+":")
    for i in fact:
        sys.stdout.write(" "+str(i))
    print ""
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
cnt = 0
max_A = max(A)

for i in range(-1,max_A+1):
    temp_cnt = 0
    for j in range(n):
        if A[j]-1 == i or A[j] == i or A[j]+1 == i:
            temp_cnt += 1
    if temp_cnt > cnt:
        cnt = temp_cnt

print(cnt)

### FIXED CODE ###

import collections
n = int(input())
A = list(map(int,input().split()))
counter = collections.Counter(A)
max_A = max(A)
cnt = 0

for i in range(-1,max_A):
    temp_cnt = counter[i-1] + counter[i] + counter[i+1]
    cnt = max(cnt,temp_cnt)

print(cnt)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in reversed(range(60)):
    one = 0
    zero = 0
    for i in range(n):
        b = str(bin(a[i]))[2:]
        c = b.zfill(60)
        s = int(c[j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(59-j)) 
    ans %= mod
print(ans%mod)

### FIXED CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k):
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)
### BUGGY CODE ###

N = int(input())
S = str(input())
x = '000'
ans = 0
while int(x) < 1000:
  st = 0
  cnt = 0
  if x[0] in S:
    for i in range(N):
      if x[0] == S[i]:
        st = i+1
        cnt += 1
        break
  if x[1] in S[st:]:
    for j in range(st, N):
      if x[1] == S[j]:
        st = j+1
        cnt += 1
        break
  if x[2] in S[st:]:
    for k in range(st, N):
      if x[2] == S[k]:
        st = k+1
        cnt += 1
        break
                
  if cnt == 3:
    ans += 1
  x = '{:03d}'.format(int(x)+1)
print(ans)

### FIXED CODE ###

N = int(input())
S = str(input())
x = '000'
ans = 0
while int(x) < 1000:
  st = 0
  cnt = 0
  if x[0] in S:
    for i in range(N):
      if x[0] == S[i]:
        st = i+1
        cnt += 1
        break
  if x[1] in S[st:]:
    for j in range(st, N):
      if x[1] == S[j]:
        st = j+1
        cnt += 1
        break
  if x[2] in S[st:]:
    for k in range(st, N):
      if x[2] == S[k]:
        st = k+1
        cnt += 1
        break
                
  if cnt == 3:
    ans += 1
  x = '{:03d}'.format(int(x)+1)
print(ans)
### BUGGY CODE ###

import numpy as np
 
def main():
    a,b,k = map(int,input().rstrip().split())
    numbers=[i for i in range(a,b+1)]
    A=set(numbers[:k])
    B=set(numbers[-k:])
    answers = A|B
    
    for i in sorted(answers):
        print("{}".format(i))
 
 
if __name__=="__main__":
    main()

### FIXED CODE ###

a, b, k = [int(i) for i in input().split()]

lim_1 = min(a + k, b)
lim_2 = max(b - k + 1, a)
ans = set(list(range(a, lim_1)) + list(range(lim_2, b + 1)))

for n in ans:
    print(n)
### BUGGY CODE ###

import math

X,Y = map(int,input().split())

if (X + Y) % 3 != 0:
  print(0)
  
else:
  a = Y - (X + Y) // 3
  b = X - (X + Y) // 3
  total = a + b
  m = min(a,b)
  def permod(n, r):
    return (math.factorial(n) // math.factorial(n - r)) % (10 ** 9 + 7)
  
  ans = permod(total,m)
  print(ans)

### FIXED CODE ###

def cmb(n, k, mod, fac, infac):
  k = min(k,n-k)
  return fac[n] * infac[k] * infac[n-k] % mod

def tables(mod, n):
  fac = [1, 1] 
  infac = [1, 1] 
  inverse = [0, 1] 
  for i in range(2, n+1):
    fac.append((fac[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    infac.append((infac[-1] * inverse[-1]) % mod)
  return fac,infac

X,Y = map(int, input().split())

if X > Y:
  X, Y = Y, X

move = X + Y

if move % 3 != 0:
  print(0)
else:
  total = move // 3
  n = X - total
  
  if n < 0:
    print(0)
    
  else:
    MOD = 10 ** 9 + 7
    fac, infac = tables(MOD, total)
    ans = cmb(total, n, MOD, fac, infac)
    
    print(ans)
### BUGGY CODE ###

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

hyouten = 1
for i in range(K):
    hyouten *= A[i]
    
for i in range(K, N):
    hyouten2 = hyouten // A[i-K] * A[i]
    if hyouten2 > hyouten:
        print("Yes")
    else:
        print("No")
    hyouten = hyouten2

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
    
for i in range(K, N):
    if A[i] > A[i-K]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N=int(input())
s=sorted(list(map(int,input().split())))
t=sorted(list(map(int,input().split())),reverse=True)
u=sorted(list(map(int,input().split())),reverse=True)
ans=0
for j in range(N):
    tt=[]
    for k in range(N):
        if s[j]<t[k]:
            tt.append(t[k])
        else:
            break
    for ii in range(len(tt)):
        for jj in range(N):
            if tt[ii]<u[jj]:
                ans+=1
            else:
                break
print(ans)            
                

### FIXED CODE ###

import bisect
N=int(input())
a=sorted(list(map(int,input().split())))
b=list(map(int,input().split()))
c=sorted(list(map(int,input().split())))
ans=0
for i in b:
    aa=bisect.bisect_left(a,i)
    cc=N-bisect.bisect_right(c,i)
    ans+=aa*cc
print(ans)
### BUGGY CODE ###

n = int(input())
l = [1]*(n + 1)
ans = 0

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        l[j] += 1

for i in range(1, n + 1):
    ans += i*l[i]

print(ans)

### FIXED CODE ###

n = int(input())
l = [1]*(n + 1)
ans = 0

for i in range(2, n + 1):
    for j in range(i, n + 1, i):
        l[j] += 1

for i in range(1, n + 1):
    ans += i*l[i]

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

n, kosuu = map(int, input().split(" "))
a=list(map(int, input().split(" ")))
maxi = 0
for i in range(n - kosuu + 1):
  if maxi < sum(a[i:i+kosuu]):
    maxi = sum(a[i:i+kosuu])
print((maxi + kosuu) / 2)
  

### FIXED CODE ###

n, kosuu = map(int, input().split(" "))
a=list(map(int, input().split(" ")))
first = sum(a[:kosuu])
temp = []
temp.append(first)
for i in range(n - kosuu):
  first = first + a[i + kosuu] - a[i]
  temp.append(first)
print((max(temp) + kosuu) / 2)