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

s=[sorted(input()) for _ in range(int(input()))]
print(sum([sum(k) for k in [[s[i]==s[j] for j in range(i+1,len(s))] for i in range(len(s))]]))

### FIXED CODE ###

dict={}
for _ in range(int(input())):
  s=''.join(sorted(input()))
  if s not in dict: dict[s]=1
  else: dict[s]+=1
print(sum([i*(i-1)//2 for i in dict.values()]))
### BUGGY CODE ###

a,b,c,k = map(int,input().split())
p = 0

while k > 0:
    if a == 0:
        break
    
    a -= 1
    p += 1
    k -= 1


while k > 0:
    if b == 0:
        break
    
    b -= 1
    k -= 1

while k > 0:
    if c == 0:
        break
    
    c -= 1
    p -= 1
    k -= 1

print(p)

### FIXED CODE ###

a,b,c,k = map(int,input().split())
p = 0

if a >= k:
    print(k)
    exit(0)
else:
    p = p + a 
    k = k - a 

if b >= k:
    print(p)
    exit(0)
else:
    k = k - b

if c >= k:
    print(p - k)
    exit(0)
else:
    p = p - c

print(p)
### BUGGY CODE ###

from functools import reduce
from operator import mul
N = int(input())
An = input().split()
An_int = list(map(int, An))
AnS = reduce(mul,An_int)
if AnS <= 10**18:
    print(AnS)
else:
    print("-1")


### FIXED CODE ###

import sys
N = int(input())
An = list(map(int,input().split()))
a = 1
if 0 in An:
    print("0")
    sys.exit()
else:
    for i in range(N):
        a *= An[i]
        if a > 10**18:
            print("-1")
            sys.exit()
    if a <= 10**18:
        print(a)
        sys.exit()
### BUGGY CODE ###

N, M = map(int, input().split())
P = []
Y = []
D = {}
for i in range(M):
  p, y = map(int, input().split())
  P.append(p)
  Y.append(y)
  if p in D:
    D[p].append(y)
  else:
    D[p] = [y]

for p in D:
  D[p] = sorted(D[p])
answer = []

for i in range(M):
  a = str(P[i]).zfill(6)
  b = str(D[P[i]].index(Y[i])+1).zfill(6)
  print(a+b)

### FIXED CODE ###

N, M = map(int, input().split())
D = [[] for i in range(N)]

for i in range(M):
  p, y = map(int, input().split())
  D[p-1].append((y, i)) #市ごとにリストに入れる．この時，元の順番をタプルの1番目の要素として入れておく

ans = [None]*M

for i, d in enumerate(D): #enumerateは要素の中身とインデックス番号を持ってこれる．print(i, d)で確認
  d.sort()
  for k, (y, j) in enumerate(d): #こちらも同様．(y, j)となっているため，yには年数が，jには元の順番の情報が入る
    ans[j] = str(i+1).zfill(6) + str(k+1).zfill(6) #ans[j]に12桁の認識番号を挿入

print(*ans, sep = '\n')
### BUGGY CODE ###

#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
grid_int = [[0] * W for i in range(H)]
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                for l in range(count):
                    grid_int[i][j-l] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            for k in range(count):
                grid_int[i][j- k - 1] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                for m in range(count):
                    grid_int[i - m][j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            for k in range(count):
                grid_int[i-k-1][j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(ans)

### FIXED CODE ###

#import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    H,W = map(int,input().split())
    S = np.array([list(input()) for _ in range(H)]) == '.' #'.'に一致するならTrueしなければFalse

    up = np.zeros((H,W), dtype=int)
    down = np.zeros((H,W), dtype=int)
    left = np.zeros((H,W), dtype=int)
    right = np.zeros((H,W), dtype=int)
    
    for i in range(H-1):
        up[i+1,:] = (up[i,:] + 1) * S[i,:] #npの変数名[k,l]でk行l列を取り出す
    for i in range(H-1):                   #:なら全部をそれぞれについて見ていく
        down[H - 2 - i,:] = (down[H - 1 - i,:] + 1) * S[H - 1 - i,:]
    for i in range(W-1):
        left[:,i+1] = (left[:,i] + 1) * S[:,i]
    for i in range(W-1):
        right[:,W - 2 - i] = (right[:,W - 1 - i] + 1) * S[:,W - 1 - i]
        
    print(((up+down+left+right)*S).max()+1) #カケザンデ要素ごとの掛け算可能
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import defaultdict
N = int(input())
G = defaultdict(list)
A = list(map(int, input().split()))
A = sorted(A)
pow2 = [2 ** i for i in range(31)]
for i in range(N):
    for j in range(i + 1, N):
        for k in pow2:
            if i != j and A[i] + A[j] == k:
                G[i].append(N + j)
                G[j].append(N + i)
                break
            if A[i] + A[j] < k:
                break

used = [False] * 2 * N
match = [-1] * 2 * N


def dfs(v):
    global used
    used[v] = True
    for u in G[v]:
        w = match[u]
        if w < 0 or not used[w] and dfs(w):
            match[v] = u
            match[u] = v
            return True


ma = 0
for i in range(N):
    if match[i] < 0:
        used = [False] * 2 * N
        if dfs(i):
            ma += 1

print(ma // 2)


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
pow2 = [1]
for i in range(31):
    pow2.append(pow2[-1] * 2)
a = sorted(a, reverse=True)
d = defaultdict(int)
for i in a:
    d[i] += 1


num = 0
for i in range(N):
    if d[a[i]] == 0:
        continue
    for k in range(30, -1, -1):
        inv = pow2[k] - a[i]
        if inv < 0 or inv > a[i]:
            continue
        if inv != a[i]:
            if d[inv] > 0 and d[a[i]] > 0:
                p = min(d[inv], d[a[i]])
                num += p
                d[inv] -= p
                d[a[i]] -= p
                break
        else:
            if d[a[i]] >= 2:
                num += d[a[i]] // 2
                d[a[i]] %= 2
                break
print(num)
### BUGGY CODE ###

s = list(input())
t = []
p = len(s)
flg = True

while flg:
    flg = False
    i = 0
    while i < len(s):
        if i < len(s)-1:
            if s[i] != s[i+1]:
                i += 2
                flg = True
            else:
                t.append(s[i])
                i += 1
        else:
            t.append(s[i])
            i += 1
    s = list(t)
    t.clear()

print(p - len(s))

### FIXED CODE ###

s = list(input())
p = s.count('0')
q = s.count('1')
print(2 * min(p,q))
### BUGGY CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
A.sort()
for B,C in BC:
  for i in range(N):
    if (B==0)or(A[i]>=C):
      break
    else:
      A[i]=C
      B-=1
      
  A.sort()
  
print(sum(A))

### FIXED CODE ###

N,M=map(int,input().split())
A=list(map(int,input().split()))
BC=[list(map(int,input().split())) for _ in range(M)]
count=0
D=[]
BC.sort(key=lambda x:x[1],reverse=True)
A.sort()
for B,C in BC:
  D+=[C]*B
  count+=B
  if count>=N:
    break

D=D[:N]
for i in range(len(D)):
  d=D[i]
  if A[i]<d:
    A[i]=d
  else:
    break
  
print(sum(A))
### BUGGY CODE ###

s = input()
l = []
n = len(s)
mod = 2019
for i in range(n-1, -1, -1):
    l.append(int(s[i:])%mod)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)

### FIXED CODE ###

s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)
### BUGGY CODE ###

def main():
    n = int(input())
    n_list = [i+1 for i in range(n-1)]
    ans = sum(n_list)
    print(ans)

main()


### FIXED CODE ###

def main():
    n = int(input())
    ans = ( n * (n-1) )// 2
    print(ans)
main()
### BUGGY CODE ###

R,G,B,N = map(int,input().split(' '))
num = 0
for i in range(int(N//R)+1):
  for j in range(int(N//G)+1):
    if (N-R*i-G*j) >= 0  and (N-R*i-G*j) % B == 0:
      num += 1
print(num)

### FIXED CODE ###

R,G,B,N = map(int,input().split(' '))
A,B,C = sorted([R,G,B])
if A==1 and B==1 and C ==1:
  print(int((N+2)*(N+1)/2))
  exit()
num = 0
E = int(N//C+1)
F = int(N//B+1)
for i in range(E):
  for j in range(F):
    X = N-C*i-B*j
    if X >= 0  and X % A == 0:
      num += 1
print(num)
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
L.sort()

def b_search(L,key,left,right,slice):
    #L[i] < keyを満たす最大のi
    #L[i] < key <= L[i+1]
    if key <= L[left]:
        return 0
    elif key > L[len(L)-1]:
        return len(L) - slice
    else:
        mid = (left+right)//2
        if L[mid] < key and key <= L[mid+1]:
            return mid + 1 - slice
        elif L[mid] >= key:
            return b_search(L,key,left,mid,slice)
        else:
            return b_search(L,key,mid,right,slice)

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += b_search(L,L[i]+L[j],j+1,len(L),j+1)
print(ans)


### FIXED CODE ###

from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        ans += bisect_left(L,L[i]+L[j])-(j+1)
print(ans)
### BUGGY CODE ###

s = list(input())
cnt = 0


while True:
    for i in range(len(s)-1):
        if s[i] + s[i+1] == "01" or s[i] + s[i+1] == "10":
            del s[i]
            del s[i]
            cnt += 2
            break
    else:
        break
print(cnt)


### FIXED CODE ###

s = list(input())
cnt = 0

def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
c = counter(s)
if len(c) == 2:
    cnt = min(c[0][1],c[1][1])
print(cnt*2)
### BUGGY CODE ###

N,Q = map(int,input().split())
sons = {1:[]}
edges = {}
for _ in range(N-1):
    a,b = map(int,input().split())
    if a==1:
    	sons[a] += [b]
    if a in edges.keys():
        edges[a] = edges[a]+[b]
    else:
        edges[a] = [b]
            
    if b in edges.keys():
        edges[b] = edges[b]+[a]
    else:
        edges[b] = [a]

counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
        
stack = sons[1]
count_stack = [counts[1]]*len(stack)
ignores = set([1])
results = [0]*(N+1)
results[1] = counts[1]
next_stack = []
next_cstack = []
while stack != []:
    next_stack = []
    next_cstack = []
    for x,c in zip(stack,count_stack):
        results[x] = counts[x]+c
        sons[x] = set(edges[x])-ignores
        next_stack += sons[x]
        next_cstack += [results[x]]*len(sons[x])
        ignores = ignores | set([x])
    stack = next_stack
    count_stack = next_cstack
print(' '.join([str(results[i]) for i in range(1,N+1)]))

### FIXED CODE ###

N,Q = map(int,input().split())
parents = {1:0}
for _ in range(N-1):
    a,b = map(int,input().split())
    key,val = max(a,b), min(a,b)
    parents[key] = val
counts = [0]*(N+1)
for _ in range(Q):
    p,x = map(int,input().split())
    counts[p] += x
results = [0]*(N+2)
for i in range(1,N+1):
    results[i] = counts[i]+results[parents[i]]
    print(results[i], end=' ')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)
def dfs(i,we):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if vis[j]==0:
            vis[j]=1
            dfs(j,we)
            
    
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
vis=[0]*n
vis[0]=1
dfs(0,0)
for i in range(n):
    print(res[i],end=" ")
print()



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def dfs(i,we,par):
    global adj,co,res
    we+=co[i]
    res[i]=we
    for j in adj[i]:
        if j!=par:
            dfs(j,we,i)
            
input = sys.stdin.readline
n,q=map(int,input().split())
adj=[set() for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    adj[a-1].add(b-1)
    adj[b-1].add(a-1)
co=[0]*n
for i in range(q):
    a,b=map(int,input().split())
    co[a-1]+=b
res=[0]*n
dfs(0,0,None)
for i in range(n):
    print(res[i],end=" ")
print()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def modfact(n):
    fact=[1]*(n+1)
    invfact=[1]*(n+1)
    for i in range(1,n+1):
        fact[i]=i*fact[i-1]%MOD
    invfact[n]=pow(fact[n],MOD-2,MOD)
    for i in range(n-1,-1,-1):
        invfact[i]=invfact[i+1]*(i+1)%MOD
    return fact,invfact

def resolve():
    h,w,n=map(int,input().split())
    R=[(1,1),(h,w)]+[tuple(map(int,input().split())) for _ in range(n)]
    R.sort()
    n+=1
    dp=[[0]*2 for _ in range(n+1)]
    dp[0][0]=1
    fact,invfact=modfact(200000)
    for i in range(n):
        x,y=R[i]
        for j in range(i+1,n+1):
            dx=R[j][0]-x
            dy=R[j][1]-y
            if(dx<0 or dy<0): continue
            for m in range(2):
                dp[j][1-m]+=dp[i][m]*fact[dx+dy]*invfact[dx]*invfact[dy]
                dp[j][1-m]%=MOD
    print((dp[n][1]-dp[n][0])%MOD)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1); invfact=[1]*(n+1)
        for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact; self.__invfact=invfact

    def inv(self,n):
        assert(n>0)
        return self.__fact[n-1]*self.__invfact[n]%MOD

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[k]*self.__invfact[n-k]%MOD

    def perm(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[n-k]%MOD

def resolve():
    h,w,n=map(int,input().split())
    RC=[None]*n
    for i in range(n):
        r,c=map(int,input().split())
        r-=1; c-=1
        RC[i]=(r,c)
    RC.append((h-1,w-1))
    n+=1
    RC.sort(lambda p:sum(p))

    mf=modfact(h+w)
    f=lambda x,y:mf.comb(x+y,x)
    dp=[None]*n
    for i in range(n):
        r,c=RC[i]
        res=f(r,c)
        for j in range(i):
            r0,c0=RC[j]
            res-=dp[j]*f(r-r0,c-c0)
        dp[i]=res%MOD

    print(dp[-1])
resolve()
### BUGGY CODE ###

s = input()
q = int(input())
a = 0

for i in range(q):
    t = input().split()
    if t[0] == '2':
        if t[1] == '1' and a == 0 or t[1] == '2' and a == 1:
            s = ''.join([t[2], s])
        else:
            s = ''.join([s, t[2]])

    else:
        if a == 1:
            a = 0
        else:
            a = 1
        
if a == 1:
    print(s[::-1])
else:
    print(s)


### FIXED CODE ###

s = input()
q = int(input())
Flag = False
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            right += c
        else:
            left += c

ans = left[::-1] + s + right
print(ans if not Flag else ans[::-1])
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
S = sum(L)
A = []
for i in range(1,N):
  p = abs(2*sum(L[0:i])-S)
  A.append(p)
print(min(A))


### FIXED CODE ###

N = int(input())
L = list(map(int,input().split()))
S = sum(L)
k = 0
ans = abs(2*sum(L[0:1])-S)
for i in range(0,N-1):
  k += L[i]
  ans = min(ans,abs(2*k-S))
print(ans)
### BUGGY CODE ###

#import sys
#read = sys.stdin.buffer.read
#input = sys.stdin.buffer.readline
#inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	check=set()
	a=[None]*(n+1)

	for i in range(1,n+1):
		if i in check:
			continue
		elif li[i]==[]:
			continue
		else:
			q=[i]
			a[i]=0
			while q:
				now=q.pop()
				check.add(now)
				for r,d in li[now]:
					if r in check:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					elif r in q:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					else:
						a[r] = a[now] + d
						q.append(r)
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n,m=map(int,input().split())
	li=[[] for _ in range(n+1)]
	for i in range(m):
		l,r,d=map(int,input().split())
		li[l].append((r,d))
		li[r].append((l,-d))
	
	q=deque()
	a=[None]*(n+1)

	for i in range(1,n+1):
		if a[i]==None:
			q=[i]
			a[i]=0
			while q:
				now=q.pop()
				for r,d in li[now]:
					if a[r]==None:
						a[r] = a[now] + d
						q.append(r)
					else:
						if a[r]-a[now]!=d:
							print("No")
							exit(0)
						else:
							continue
					
	print("Yes")
	
	
if __name__ == '__main__':
	main()
### BUGGY CODE ###

S = "0" + input()

digits = [int(c) for c in S.rstrip("0")]

f = [
    None,
    [None] * len(digits),
    [None] * len(digits),
]  # f[sign][place] where sign is 1 or -1


for place in reversed(range(len(digits))):
    for sign in [-1, 1]:
        if place == len(digits) - 1:
            if sign > 0:
                exact = digits[place]
            else:
                exact = 10 - digits[place]
            f[sign][place] = exact
            continue

        if sign > 0:
            exact = digits[place]
            overpay = exact + 1  # Overpaying flips the sign of the balance
        else:
            assert sign < 0
            exact = 10 - digits[place] - 1
            overpay = exact + 1
        f[sign][place] = min(exact + f[sign][place + 1], overpay + f[-sign][place + 1])
print(f[1][0])


### FIXED CODE ###

S = "0" + input()

digits = [int(c) for c in S.rstrip("0")]
N = len(digits)

# Track number of bills necessary to create digits[:i]
# Can either pay exact or overpay by one bill to flip the sign of the balance
dpPos = [None] * len(digits)
dpNeg = [None] * len(digits)

dpPos[-1] = digits[-1]
dpNeg[-1] = 10 - digits[-1]

for place in reversed(range(len(digits) - 1)):
    # Positive balance case
    exact = digits[place]
    overpay = exact + 1
    dpPos[place] = min(exact + dpPos[place + 1], overpay + dpNeg[place + 1])
    # Negative balance case
    exact = 10 - digits[place] - 1
    overpay = exact + 1
    dpNeg[place] = min(exact + dpNeg[place + 1], overpay + dpPos[place + 1])
print(dpPos[0])
### BUGGY CODE ###

N = int(input())
prices = [int(n) for n in input().split()]
money = 1000
stock = 0
for n in range(N-1):
    p_today = prices[n]
    p_tomm = prices[n+1]
    if p_tomm >= p_today:
        while money >= p_today:
            stock += 1
            money -= p_today
    else:
        money += p_today * stock
        stock = 0

if stock > 0:
    money += prices[-1] * stock

print(money)

### FIXED CODE ###

N = int(input())
prices = [int(n) for n in input().split()]
money = 1000
stock = 0
p_today = prices[0]
for n in range(N-1):
    p_tomm = prices[n+1]
    if p_tomm >= p_today:
        n_stock = money // p_today
        stock += n_stock
        money = money - p_today * n_stock
        # while money >= p_today:
        #     stock += 1
        #     money -= p_today
    else:
        money += p_today * stock
        stock = 0
    p_today = p_tomm

if stock > 0:
    money += prices[-1] * stock

print(money)
### BUGGY CODE ###

import re

n = int(input())
s = input()
cnt = 0

for i in range(1000):
    tgt = str(i).zfill(3)
    pattern = '.*' + tgt[0] + '.*' + tgt[1] + '.*' + tgt[2] + '.*'
    if re.match(pattern, s):
        cnt += 1
print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
cnt = 0

for N in range(1000):
    tgt = str(N).zfill(3)
    if tgt[0] in s:
        i = s.index(tgt[0])
        if tgt[1] in s[i+1:]:
            j = s[i+1:].index(tgt[1]) + i
            if tgt[2] in s[j+2:]:
                cnt += 1
print(cnt)
### BUGGY CODE ###

n=int(input())
l=list(map(int, input().split(' ')))
ans=1
for i in l:
    ans*=i
if ans>10**18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

n=int(input())
l=list(map(int, input().split(' ')))
ans=1
if 0 in l:
    print(0)
else:
    for i in l:
        ans*=i
        if ans>10**18:
            print(-1)
            break
    if not ans>10**18:
        print(ans)
### BUGGY CODE ###

#辞書順で小さい文字から考えていく。まずｓ内を構成する文字で辞書順で小さいものを列挙。
#辞書順降順でその文字から始まる部分文字列を全列挙。その数がｋに達したら打ち切り。
s = input()
k = int(input())
substr = set()
for i in range(len(s)):
    substr.add(s[i])
check = sorted(list(substr))
x = 0
while True:
    for i in range(len(s)):
        if s[i] == check[x] and i < len(s) - 1:
            for j in range(i+1,len(s)+1):
                substr.add(s[i:j])
    if len(substr) >= k:
        break
    x += 1
lis_substr = sorted(list(substr))
print(lis_substr[k-1])

### FIXED CODE ###

s = input()
k = int(input())
x = 0
substr = set()
while x < k:
    x += 1
    for i in range(len(s) - x + 1):
        if s[i:i+x] not in substr:
            substr.add(s[i:i+x])
substr = list(substr)
substr.sort()
print(substr[k-1])
### BUGGY CODE ###

from collections import deque
def bfs():
    X, Y = map(int, input().split())
    que = deque([[0, 0]])
    ans = 0
    while que:
        x, y = que.popleft()
        for i, j in ([1,2], [2,1]):
            nx, ny = x+i, y+j
            if nx < X and ny < Y:
                que.append([nx, ny])
            elif nx == X and ny == Y:
                ans += 1
    return ans
print(bfs())

### FIXED CODE ###

import math
import numpy as np

def cmb(n, r, mod):
  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:

  A = np.array([[1, 2],[2, 1]])
  b = np.array([x, y])
  N = np.linalg.solve(A, b)
  if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
      print(cmb(int(N[0]+N[1]),int(N[0]),mod))
  else:
      print(0)
else:
  print(0)