Harryxun/stf_run huggingface dataset:
n, k = map(int, input().split())
p = list(map(lambda x: int(x) - 1, input().split()))
c = list(map(int, input().split()))

max_score = min(c)
for init_mass in range(n):
    curr_mass = p[init_mass]
    scores = [c[init_mass]]
    while curr_mass != init_mass:
        scores.append(scores[-1] + c[curr_mass])
        curr_mass = p[curr_mass]
    cycle_score = scores[-1]

    if len(scores) >= k:
        score = max(scores[:k])
    elif cycle_score <= 0:
        score = max(scores)
    else:
        cycle_len = len(scores)
        max_cycle_num, cycle_rem = divmod(k, cycle_len)
        score = max(cycle_score * (max_cycle_num - 1) + max(scores),
                    cycle_score * max_cycle_num + max(scores[:cycle_rem]))

    if score > max_score:
        max_score = score

print(max_score)


### FIXED CODE ###

n, k = map(int, input().split())
p_list = list(map(lambda x: int(x) - 1, input().split()))
c_list = list(map(int, input().split()))

max_score = -(1 << 64)
cycles = []
cycled = [False] * n
for i in range(n):
    if cycled[i]:
        continue

    cycle = [i]
    cycled[i] = True
    while p_list[cycle[-1]] != cycle[0]:
        cycle.append(p_list[cycle[-1]])
        cycled[cycle[-1]] = True

    cycles.append(cycle)

for cycle in cycles:
    cycle_len = len(cycle)

    accum = [0]
    for i in range(cycle_len * 2):
        accum.append(accum[-1] + c_list[cycle[i % cycle_len]])

    cycle_score = accum[cycle_len]

    max_series_sums = [max([accum[i + length] - accum[i]
                            for i in range(cycle_len)])
                       for length in range(cycle_len + 1)]

    if cycle_len >= k:
        score = max(max_series_sums[1:k + 1])
    elif cycle_score <= 0:
        score = max(max_series_sums[1:])
    else:
        max_cycle_num, cycle_rem = divmod(k, cycle_len)
        score = max(cycle_score * (max_cycle_num - 1) + max(max_series_sums),
                    cycle_score * max_cycle_num + max(max_series_sums[:cycle_rem + 1]))

    max_score = max(max_score, score)

print(max_score)
mport math
h, w = map(int, input().split())
print(math.ceil(h * w / 2))

### FIXED CODE ###

import math
h, w = map(int, input().split())
if h == 1 or w == 1:
    print(1)
else:
    print(math.ceil(h * w / 2))
n = int(input())
import sympy
prits = [0 for i in range(n+1)]

for i in range(1,n+1):
    k = 2
    while k*k<=i:
        while i%k == 0:
            i = i//k
            prits[k] += 1
        k += 1
    if i>1 :
        prits[i] += 1
#print(prits)

a,b,c,d,e = [],[],[],[],[]

for i in range(len(prits)):
    num = prits[i]
    if num >=2:
        e.append(i)
    if num >=4:
        d.append(i)
    if num >=14:
        c.append(i)
    if num >=24:
        b.append(i)
    if num >=74:
        a.append(i)

#print(len(a),len(b),len(c),len(d),len(e))

ans = 0
ans += len(a)
ans += len(c)*(len(d)-1)
ans += len(b)*(len(e)-1)
ans += len(d)*(len(d)-1)*(len(e)-2)//2

print(ans)


### FIXED CODE ###

n = int(input())
prits = [0 for i in range(n+1)]

for i in range(1,n+1):
    k = 2
    while k*k<=i:
        while i%k == 0:
            i = i//k
            prits[k] += 1
        k += 1
    if i>1 :
        prits[i] += 1
#print(prits)

a,b,c,d,e = [],[],[],[],[]

for i in range(len(prits)):
    num = prits[i]
    if num >=2:
        e.append(i)
    if num >=4:
        d.append(i)
    if num >=14:
        c.append(i)
    if num >=24:
        b.append(i)
    if num >=74:
        a.append(i)

#print(len(a),len(b),len(c),len(d),len(e))

ans = 0
ans += len(a)
ans += len(c)*(len(d)-1)
ans += len(b)*(len(e)-1)
ans += len(d)*(len(d)-1)*(len(e)-2)//2

print(ans)
s = input()

sum = 700

for i in s:
  if i == o:
    sum += 100
  
  else:
    sum += 0
    
print (sum)

### FIXED CODE ###

s = input()

print(s.count("o")*100+700)
import sys
import math

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N = ir()
start = ir()
next = 0
for n in range(1, N):
    next = ir()
    start = lcm(start, next)

print(start)


### FIXED CODE ###

import sys
import fractions

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N = ir()
start = ir()
next = 0
for n in range(1, N):
    next = ir()
    start = lcm(start, next)

print(start)
N,M,K = map(int, input().split())
  # nは入力回数
A = [list(map(int, input().split())) for _ in range(N)]

B = [list(map(int, input().split())) for _ in range(M)]

sum=0
count = 0
for i in range(N+M):
    if A[0] >= B[0]:
        temp = B.pop(0)
        if sum+temp > K:
            break
            print(count)
        else:
            sum +=temp
            count += 1

    else:
        temp = A.pop(0)
        if sum + temp > K:
            break
            print(count)
        else:
            sum += temp
            count += 1








### FIXED CODE ###

n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


a = [0]
b = [0]

for i in range(n):
    a.append(a[i]+ A[i])
for i in range(m):
    b.append(b[i] + B[i])
# print(a)
# print(b)
# print(a[3])
ans=0
j = m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)
x = 117
if '7' in x
    print('yes')
else:
    print('no')

### FIXED CODE ###

x = input()
if '7' in x:
    print('Yes')
else:
    print('No')
H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
b =[0]*(H*W)
k = 0
for i in range(N):
    for j in range(a[i]):
        b[k] = i + 1
        k += 1
x, y = 0, 0
ans =[[0]*W for i in range(W)]
for i in range(H*W):
    ans[y][x] = b[i]
    if x == 0 and y%2 == 1 or x == W - 1 and y%2 == 0:
        y += 1
    elif y%2 == 0:
        x += 1
    else:
        x -= 1
for _ in range(H):
    print(*ans[_])

### FIXED CODE ###

H, W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
b =[0]*(H*W)
k = 0
for i in range(N):
    for j in range(a[i]):
        b[k] = i + 1
        k += 1
x, y = 0, 0
ans =[[0]*W for i in range(H)]
for i in range(H*W):
    ans[y][x] = b[i]
    if (x == 0 and y%2 == 1) or (x == W - 1 and y%2 == 0):
        y += 1
    elif y%2 == 0:
        x += 1
    else:
        x -= 1
for _ in range(H):
    print(*ans[_])
import sys

N = int(stdin.readline().restrip())
num_line = [stdin.readline().restrip() for _ in range(N)]
for i in range(N):
    save_num = num_line[i]
    num_line.pop(i)
    print(max(num_line))
    num_line.insert(i, save_num)

### FIXED CODE ###

N = int(input())
num_line = [int(input()) for _ in range(N)]
sort_line = sorted(num_line)
for i in num_line:
    if i == sort_line[N-1]:
        print(sort_line[N-2])
    else:
        print(sort_line[N-1])
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    x = int(input())
    p1 = 1
    while True:
        p15 = p1 ** 5
        rt1 = ((x + p15) ** 0.2) % 1
        rt2 = ((x - p15) ** 0.2) % 1
        if rt1 == 0:
            r = (int((x + p15) ** 0.2), p15)
            break
        elif rt2 == 0:
            r = (int((x - p15) ** 0.2), -p15)
            break
        print(p1)
        p1 += 1
    print(r)
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from math import pow
def main():
    x = int(input())
    for a in range(-1000,1001):
        for b in range(-1000,1001):
            if pow(a, 5) - pow(b, 5) == x:
                print(a, b)
                sys.exit()

if __name__ == '__main__':
    main()
s = input()

n = len(str)

ans = 0
for i in range(int(n/2)):
  if s[i] != s[n-i-1]:
    ans += 1
    
print(ans)

### FIXED CODE ###

s = input()

n = len(s)

ans = 0
for i in range(int(n/2)):
  if s[i] != s[n-i-1]:
    ans += 1
    
print(ans)
N=int(input())
M=int(input())
A=list(range(M+1))
play_day=N-sum(A)
if play_day>0:
    print(play_day)
else:
    print(-1)

### FIXED CODE ###

a,b=map(int,input().split())
C=list(map(int,input().split()))
play_day=a-sum(C)
if play_day>=0:
    print(play_day)
else:
    print("-1")
A, B, C = map(int, input().split())

if A*C < B:
    print(C)

elif A*C = B:
    print(C)

elif A*C > B:
    print(B//A)

### FIXED CODE ###

A, B, C = map(int, input().split())

if A*C < B:
    print(C)

elif A*C == B:
    print(C)

elif A*C > B:
    print(B//A)
def main():
    n =int( input())
    sn=[]
    for i in range(n):
        
        inWord = str(input())
        addFlag = True
        for s in sn:
            if s["word"] == inWord and len(sn) !=0:
                s["count"]+=1
                addFlag = False
                break
        if addFlag ==True:
            sn.append( {"word":inWord,"count":1})
        
    a= sorted(sn, reverse=True,key=lambda x:x['count'])
    most = a[0]["count"]

    mostWords=[]
    for elm in a:
        if elm["count"] == most:
            mostWords.append(elm["word"])
        else :
            break
        
    mostWords.sort()

    for elm in mostWords:
        print(elm)
    return

main()



### FIXED CODE ###

A, B, C = map(int, input().split())

if A == B or B == C or C == A:
    if A == B and B == C:
        print("No")
    else:
        print("Yes")

else:
    print("No")
import math
import numpy as np

K = int(input())
sum = 0
ijkrange = np.arange(1, K+1)

for i in ijkrange:
    for j in ijkrange:
        for l in ijkrange:
            sum += math.gcd(i, math.gcd(j, l))

print(sum)

### FIXED CODE ###

import math

K = int(input())
sum = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for l in range(1, K+1):
            sum += math.gcd(i, math.gcd(j, l))

print(sum)
from collections import defaultdict
N, Q = map(int, input().split())
C = defaultdict(int)
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  
def AddPX(n, x):
  C[n] += x
  for i in D[n]:
    AddPX(i, x)
  
for i in range(Q):
  p, x = map(int, input().split())
  AddPX(p-1, x)
print (" ".join(map(str, C.values())))

### FIXED CODE ###

from collections import deque
from collections import defaultdict
N, Q = map(int, input().split())
C = [0]* N
D = defaultdict(set)
for i in range(N-1):
  a, b = map(int, input().split())
  D[a-1].add(b-1)
  D[b-1].add(a-1)
for i in range(Q):
  p, x = map(int, input().split())
  C[p-1] += x

Q = deque([])
Q.append(0)
vstd = set()

while len(Q)>0:
  a = Q.popleft()
  vstd.add(a)
  for b in D[a]:
    if b in vstd:
      continue
    C[b] += C[a]
    Q.append(b)

print (" ".join(map(str, C)))
N,K = map(int,input().split())
P_List=list(map(int,input().split()))
#print(N,K)
#print(P_List)

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

def Kitaichi2(p):
    return (p+1)*0.5

kitaichi_list=[]
ruisekiwa_list=[]
ruisekiwa=0
for a in range(N):
    kitaichi_list.append(Kitaichi2(P_List[a]))
    ruisekiwa += Kitaichi2(P_List[a])
    ruisekiwa_list.append(ruisekiwa)

#print(kitaichi_list)
#print(ruisekiwa_list)
pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    if j == 0:
        temp_max = ruisekiwa_list[j+K] - 0
    else:
        temp_max = ruisekiwa_list[j+K] - ruisekiwa_list[j-1]
    

    if pre_max < temp_max:
        pre_max = temp_max
    temp_max=0

print(pre_max)

### FIXED CODE ###


N,K = map(int,input().split())
P_List=list(map(int,input().split()))
#print(N,K)
#print(P_List)

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

def Kitaichi2(p):
    return (p+1)*0.5

kitaichi_list=[]
ruisekiwa_list=[]
ruisekiwa=0
for a in range(N):
    kitaichi_list.append(Kitaichi2(P_List[a]))
    ruisekiwa += Kitaichi2(P_List[a])
    ruisekiwa_list.append(ruisekiwa)

#print(kitaichi_list)
#print(ruisekiwa_list)
pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    if j == 0:
        temp_max = ruisekiwa_list[j+K-1] - 0
    else:
        temp_max = ruisekiwa_list[j+K-1] - ruisekiwa_list[j-1]
    

    if pre_max < temp_max:
        pre_max = temp_max
    temp_max=0

print(pre_max)
n,k = map(int,input().split())
mod = 10**9 + 7
combo1 = 1
combo2 = 1
p = 0
for i in range(1,k+1):
    if n-k >= i - 1:
        if i > 1:
            combo1 = int(combo1*(k-i+1)/(i-1))
            combo2 = int(combo2*(n-k+2-i)/i)
        else:
            combo1 = 1
            combo2 = int(combo2*(n-k+2-i)/i)
        print((((combo1)%mod)*((combo2)%mod))%mod)
        #print(combo1,combo2)
    else:
        p = i
        break
if p > 0:
    for i in range(k-p):
        print(0)

### FIXED CODE ###

n,k = map(int,input().split())
mod = 10**9 + 7
combo1 = 1
combo2 = 1
p = 0
for i in range(1,k+1):
    if n-k >= i - 1:
        if i > 1:
            combo1 = combo1*(k-i+1)//(i-1)
            combo2 = combo2*(n-k+2-i)//i
        else:
            combo1 = 1
            combo2 = combo2*(n-k+2-i)//i
        print((((combo1)%mod)*((combo2)%mod))%mod)
        #print(combo1,combo2)
    else:
        p = i
        break
if p > 0:
    for i in range(k-p+1):
        print(0)
n, k = map(int, input())

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree[i+k-1] - tree[i] for i in range(n-k+1))
print(min(res))

### FIXED CODE ###

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

tree = [int(input()) for i in range(n)]
tree.sort()

res = (tree[i+k-1] - tree[i] for i in range(n-k+1))
print(min(res))
S = str(input())
dic_wet = {1:"Sunny",2:"Cloudy",3:"Rainy"}
for k , v in dic_wet.items():
    if v == S:
        print(dic_wet[(k+1) % 3])

### FIXED CODE ###

S = str(input())
L = ["Sunny","Cloudy","Rainy"]
print(L[(L.index(S)+1)%3])
from fractions import gcd
import math

def get_prime_numbers(n):
  prime_nums = {}
  for i in range(2, math.ceil(math.sqrt(n)) + 1):
    while n % i == 0:
      if i in prime_nums:
        prime_nums[i] += 1
      else:
        prime_nums[i] = 1
      n //= i
  if n != 1:
    if n in prime_nums:
      prime_nums[n] += 1
    else:
      prime_nums[n] = 1
  return prime_nums

a, b = map(int, input().split())
gcd_n = gcd(a, b)
prime_nums = get_prime_numbers(gcd_n)
print(len(prime_nums.keys()))

if __name__ == '__main__':
  main()

### FIXED CODE ###

from fractions import gcd
import math
 
A, B = map(int, input().split())
 
N = gcd(A, B)
 
def prime(n):
    factor = {}
    tmp = int(math.sqrt(n)) + 1
    for num in range(2, tmp):
        while n % num == 0:
            n //= num
            if not num in factor.keys():
                factor[num] = 1
            else:
                factor[num] += 1
    if n != 1:
        if not n in factor.keys():
            factor[n] = 1
        else:
            factor[n] += 1
    return factor

factor = prime(N)
print(len(factor) + 1)
N,K,L = map(int, input().split())


class UFT:
    def __init__(self, N):
        self.UFdata = [-1] * (N+1)
        self.rank   = [0]  * (N+1)

    def find(self,x):
        UFdata = self.UFdata
        while UFdata[x] != -1:
            x = UFdata[x]
        return x

    def unite(self,x,y):
        UFdata = self.UFdata
        rank = self.rank 
        find = self.find

        x = find(x)
        y = find(y)
        if x != y:
            if rank[x] < rank[y]:
                x,y = y,x
            if rank[x] == rank[y]:
                rank[x] += 1
            UFdata[y] = x       
            

UF1 = UFT(N)
UF2 = UFT(N)
ans = [1] * (N+1)
MAP= [ [0] * (N+1) for _ in range(N+1)]
import sys
input = sys.stdin.readline
PQ = [ [int(j) for j in input().split()] for _ in range(K)]
RS = [ [int(j) for j in input().split()] for _ in range(L)]

for i in range(K):
    p,q = PQ[i]
    UF1.unite(p,q)
for i in range(L):
    p,q = RS[i]
    UF2.unite(p, q)
counter=[]
for i in range(1,N+1):
  counter.append((UF1.find(i),UF2.find(i)))
from collections import Counter  
p=Counter(counter)

ans = [0]*(N+1)
for i in range(1,N+1):
    ans[i] = p[(UF1.find(i),UF2.find(i))]

del ans[0]
# print(" ".join( map(lambda x: str(x), connected_num[1:])))
print(" ".join( map(lambda x: str(x), ans)))


### FIXED CODE ###

N,K,L = map(int, input().split())


class UFT:
    def __init__(self, N):
        self.UFdata = [-1] * (N+1)
        self.rank   = [0]  * (N+1)

    def find(self,x):
        UFdata = self.UFdata
        while UFdata[x] != -1:
            x = UFdata[x]
        return x

    def unite(self,x,y):
        UFdata = self.UFdata
        rank = self.rank 
        find = self.find

        x = find(x)
        y = find(y)
        if x != y:
            if rank[x] < rank[y]:
                x,y = y,x
            if rank[x] == rank[y]:
                rank[x] += 1
            UFdata[y] = x       
            

UF1 = UFT(N)
UF2 = UFT(N)
ans = [1] * (N+1)
# MAP= [ [0] * (N+1) for _ in range(N+1)]
import sys
input = sys.stdin.readline
#PQ = [ [int(j) for j in input().split()] for _ in range(K)]
#RS = [ [int(j) for j in input().split()] for _ in range(L)]

for i in range(K):
    p,q = map(int,input().split())
    UF1.unite(p,q)
for i in range(L):
    p,q = map(int,input().split())#RS[i]
    UF2.unite(p, q)
counter=[]
from collections import defaultdict
cntdic =defaultdict(int)
for i in range(1,N+1):
  counter.append(UF1.find(i)+UF2.find(i)*10**6)
  cntdic[counter[-1]]+=1 

ans = [0]*(N+1)
for i in range(1,N+1):
    ans[i] = cntdic[counter[i-1]]

del ans[0]
# print(" ".join( map(lambda x: str(x), connected_num[1:])))
print(" ".join( map(lambda x: str(x), ans)))
h = 14
w = 12
n = 112

n_push = []

for n_h in range(h):
  for n_w in range(w):
    n_tmp = n_h*w + n_w*h - (n_h*n_w)
    
    if n_tmp>n_push:
	    n_push.append = n_h + n_w
    
print min(n_push)

### FIXED CODE ###

h = int(input())
w = int(input())
n = int(input())

n_push = []

for n_h in range(h+1):
  for n_w in range(w+1):
    n_tmp = (n_h)*w + (n_w)*h - ((n_h)*(n_w))

    if n_tmp>=n:
      n_push.append(n_h + n_w)

print(min(n_push))
#!/usr/bin/env python
# -*- coding: utf-8 -*-

var = raw_input().split()

var = map(int, var)

if var[0] > var[1]
	tmp = var[0]
	var[0] = var[1]
	var[1] = tmp
if var[0] > var[2]
	tmp = var[0]
	var[0] = var[2]
	var[2] = tmp
if var[1] > var[2]
	tmp = var[1]
	var[1] = var[2]
	var[2] = tmp

var = map(str, var)

prini var[0],var[1],var[2]

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

var = raw_input().split()

var = map(int, var)

if var[0] > var[1]:
	tmp = var[0]
	var[0] = var[1]
	var[1] = tmp
	
if var[0] > var[2]:
	tmp = var[0]
	var[0] = var[2]
	var[2] = tmp
	
if var[1] > var[2]:
	tmp = var[1]
	var[1] = var[2]
	var[2] = tmp

print var[0],var[1],var[2]
c=input()
if c==a or c==i or c==u or c==e c==o:
    print('vowel')
else:
    print('consonant')
    

### FIXED CODE ###

c=input()
if c=='a' or c=='i' or c=='u' or c=='e' or c=='o':
    print('vowel')
else:
    print('consonant')
D, T, S = list(map((int, input().split()))
               if D <= T * S:
                 print("YES")
               else:
                 print("NO")

### FIXED CODE ###

D,T,S=map(int,input().split())
if D<=T*S:
    print("Yes")
else:
    print("No")
N,X=map(int,input().split())
L=list(map(int,input().split()))

D=0
for i in range(N+1):
  D+=L[i]
  if D>X:
    break
    
print(i+1)

### FIXED CODE ###

N,X=map(int,input().split())
L=list(map(int,input().split()))
#print(L)

D=0
for i in range(N):
  D+=L[i]
  if D>X:
    print(i+1)
    break
  if i==N-1:
    print(i+2)
    break
N,K = input().split()
N = int(N)
K = int(K)

have = []
result = 0

for i in range(N):
    have.append([1]*K)


for i in range(K):
    d = int(input())
    A = input().split()
    A = map(int,A)

    for a in A:
        have[a-1][d-1] = 0

        
for j in have:
    if j == [1]*K:
        result += 1

print(result)

### FIXED CODE ###

N,K = input().split()
N = int(N)
K = int(K)

have = []
result = 0

for i in range(N):
    have.append([1]*K)


for i in range(K):
    d = int(input())
    
    A = input().split()
    A = map(int,A)

    for a in A:
        have[a-1][i-1] = 0

        
for j in have:
    if j == [1]*K:
        result += 1

print(result)
def prob_d(n=None, k=None):
    if n is None and k is None:
        n, k = [int(a) for a in input().split()]
    div = 10 ** 9 + 7
    for i in range(k):
        if n - k + 1 < i:
            print("0")
        else:
            if k == 1:
                ans = cmb(n, i+1) % div
                print(str(ans))
            else:
                ans = cmb(k-1, i) % div
                ans *= (cmb(n - k + 1, i + 1) % div)
                ans = ans % div
                print(str(ans))


prob_d()

### FIXED CODE ###

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

def prob_d(n=None, k=None):
    if n is None and k is None:
        n, k = [int(a) for a in input().split()]
    div = 10 ** 9 + 7
    for i in range(k):
        if n - k + 1 < i + 1:
            print("0")
        else:
            if k == 1:
                ans = cmb(n, i+1) % div
                print(str(ans))
            else:
                ans = cmb(k-1, i) % div
                ans *= (cmb(n - k + 1, i + 1) % div)
                ans = ans % div
                print(str(ans))


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

mod = 10**9 + 7

# ある座標に来るパターンの数を記録するDPテーブル
dp = [[0 for _ in range(X+1)] for _ in range(Y+1)]

# 初期位置を設定
dp[0][0] = 1

for y in range(Y+1):
    for x in range(X+1):
        if (x-2) >= 0 and (y-1) >= 0:
            dp[x][y] += int(dp[x-2][y-1] % mod)
        if (x-1) >= 0 and (y-2) >= 0:
            dp[x][y] += int(dp[x-1][y-2] % mod)
        # dp[x][y] /= mod

print(dp[X][Y])

### FIXED CODE ###

def cmb(n, k, mod, fac, ifac):
    """
    nCkを計算する
    """
    k = min(k, n-k)
    return fac[n] * ifac[k] * ifac[n-k] % mod


def make_tables(mod, n):
    """
    階乗テーブル、逆元の階乗テーブルを作成する
    """
    fac = [1, 1] # 階乗テーブル・・・(1)
    ifac = [1, 1] #逆元の階乗テーブル・・・(2)
    inverse = [0, 1] #逆元テーブル・・・(3)
    
    for i in range(2, n+1):
        fac.append((fac[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod//i)) % mod)
        ifac.append((ifac[-1] * inverse[-1]) % mod)
    return fac, ifac


X, Y = map(int, input().split())
# 後の、n, mの大小を一定にするため
if X > Y:
    X, Y = Y, X
dist = X + Y
   
if dist % 3 != 0:
    print(0)
else:
    # (+1,+2) の移動の回数を n、(+2,+1) の移動の回数を m とする)
    # total = n + m
    # 以下の式は、2n + m = X, n + 2m = Y の連立方程式を解いた結果
    total = int((X+Y) / 3)
    n = X - total
    
    # n < 0 もしくは m < 0 の場合、たどり着けない
    # Y > X なので、m > n
    # n < 0 → 2X - Y < 0
    if Y > 2*X:
        print(0)
    else:
        MOD = 10**9 + 7

        fac, ifac = make_tables(MOD, total)
        ans = cmb(total, n, MOD, fac, ifac)
        print(ans)
n=int(input())
s=[]
for i in range(1:n+1):
  if a%3==0:
    continue
  elif a%5==0:
    continue
  else:
    s.append(i)
print(sum(s))

### FIXED CODE ###

print('YNeos'[not ('7'in input())::2])
a=int(input())
b=int(input())
print(a*b)

### FIXED CODE ###

a,b=[int(_) for _ in input().split()]
print(a*b)
a,b=input().split()
LIST=[a,b]
if "9" in LIST:
  print("Yes")
else:
  print("No)

### FIXED CODE ###

a=input()

if "9" in a:
  print("Yes")
else:
  print("No")
def maxBy(f, x, y):
    if f(x) > f(y):
        return x
    else:
        return y


table = {("", ""): ""}


def lcs(xs, ys):
    if (xs, ys) in table:
        return table[(xs, ys)]

    ret = ""
    if xs == "" or ys == "":
        ret = ""
    elif xs[-1] == ys[-1]:
        ret = lcs(xs[:-1], ys[:-1]) + xs[-1]
    else:
        ret = maxBy(len,
                    lcs(xs[:-1], ys),
                    lcs(xs, ys[:-1]))
    table[(xs, ys)] = ret
    return ret


s = input()
t = input()

c = lcs(s, t)
print(c)


### FIXED CODE ###

def lcs(x, y):
    m = len(x)
    n = len(y)

    c = [[0 for _ in range(n + 1)] for _ in range(m + 1)]
    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if x[i - 1] == y[j - 1]:
                c[i][j] = c[i - 1][j - 1] + 1
            else:
                c[i][j] = max(c[i - 1][j], c[i][j - 1])

    lcs_str = ''
    i, j = m, n
    while i > 0 and j > 0:
        if x[i-1] == y[j-1]:
            lcs_str += x[i-1]
            i -= 1
            j -= 1
        else:
            if c[i][j] == c[i-1][j]:
                i -= 1
            else:
                j -= 1

    return lcs_str[::-1]


s = input()
t = input()
print(lcs(s, t))