Harryxun/stf_run huggingface dataset:
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N-1]!=A[0]:
    flag = 1
if flag==0:
    indmaxT=0
    H[0] = T[0]
    for i in range(1,N):
        if T[i]>T[i-1]:
            H[i] = T[i]
            if H[i]==hmax:
                indmaxT = i
                break
    indmaxA = N-1
    H[N-1] = A[N-1]
    for i in range(N-2,-1,-1):
        if A[i]>A[i+1]:
            H[i]=A[i]
            if H[i]==hmax:
                indmaxA = i
                break
    if indmaxA<indmaxT:
        flag = 1
if flag==1:
    print(0)
else:
    hmax = max(H)
    cnt = 1
    cur = 0
    indH=0
    for i in range(1,indmaxT):
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    cur = N-1
    for i in range(N-2,indmaxA,-1):
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    for i in range(indmaxT+1,indmaxA):
        cnt = (cnt*hmax)%p
    print(cnt)

### FIXED CODE ###

p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
    if T[i]>T[i-1]:
        H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
    cnt = 0
else:
    H[-1] = A[-1]
    for i in range(-2,-N-1,-1):
        if H[i]==0 and A[i]>A[i+1]:
            if A[i]<=T[i]:
                H[i] = A[i]
            else:
                cnt = 0
                break
        elif H[i]>0 and A[i]>A[i+1]:
            if H[i]==A[i]:continue
            else:
                cnt = 0
                break
    if cnt==1:
        for i in range(1,N-1):
            if H[i]==0:
                cnt = (cnt*min(T[i],A[i]))%p
print(cnt)
a = int(input())
print(["ABC","ARC","AGC"][a<1200, a<2800, a>=2800])

### FIXED CODE ###

a = int(input())
print("ABC" if a<1200 else "ARC" if a<2800 else "AGC")
#!/usr/bin/env python3
from itertools import product
import sys

try:
    from typing import Dict, List, Tuple
except ImportError:
    pass


MOD = 1000000007  # type: int


def isvalid(ptn: "Tuple[bool]"):
    return not any(h1 and h2 for h1, h2 in zip(ptn, ptn[1:]))


def solve(H: int, W: int, K: int):
    validptns: "List[Tuple[bool]]" = [
        ptn
        for ptn in product((False, True), repeat=W - 1)
        if isvalid(ptn)
    ]
    dp: "List[int]" = [1 if i == K - 1 else 0 for i in range(W)]
    for _ in range(H):
        newdp: "List[int]" = [0] * W
        for ptn in validptns:
            for s in range(W):
                t = s
                if s < W - 1 and ptn[s]:
                    t = s + 1
                elif s > 0 and ptn[s - 1]:
                    t = s - 1
                newdp[t] += dp[s]
                newdp[t] %= MOD
        dp = newdp

    print(dp[0])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from itertools import product
import sys

try:
    from typing import List, Tuple
except ImportError:
    pass


MOD = 1000000007  # type: int


def isvalid(ptn: "Tuple[bool]"):
    return not any(h1 and h2 for h1, h2 in zip(ptn, ptn[1:]))


def solve(H: int, W: int, K: int):
    validptns = [
        ptn
        for ptn in product((False, True), repeat=W - 1)
        if isvalid(ptn)
    ]  # type: List[Tuple[bool]]
    dp = [1 if i == K - 1 else 0 for i in range(W)]  # type: List[int]
    for _ in range(H):
        newdp = [0] * W  # type: List[int]
        for ptn in validptns:
            for s in range(W):
                t = s
                if s < W - 1 and ptn[s]:
                    t = s + 1
                elif s > 0 and ptn[s - 1]:
                    t = s - 1
                newdp[t] += dp[s]
                newdp[t] %= MOD
        dp = newdp

    print(dp[0])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)


if __name__ == '__main__':
    main()
n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)-1):
    mini = i
    for j = i in xrange(len(A)-1):
        if A[j] < A[mini]
            mini = j
    A[i], A[mini] = A[mini], A[j]
    cnt += 1
for x in A:
	print x,
print
print cnt

### FIXED CODE ###

n = raw_input()
A = map(int, raw_input().split())
cnt = 0
for i in xrange(len(A)):
    mini = i
    for j in xrange(i, len(A)):
        if A[j] < A[mini]:
            mini = j
    if A[i]!=A[mini]:
	    cnt += 1
	    A[i], A[mini] = A[mini], A[i]
for x in A:
	print x,
print
print cnt
n=int(input())
V=list(map(int,input().split()))

A=[[0,i] for i in range(10**5)]
B=[[0,i] for i in range(10**5)]

for i in range(0,n,2):
    A[V[i]][0]+=1
for i in range(1,n,2):
    B[V[i]][0]+=1

A.sort(reverse=1)
B.sort(reverse=1)

#print(A[:10])
#print(B[:10])

Ma=[]
Mb=[]

ma=A[0][0]
mb=B[0][0]
i=0
j=0
while A[i][0]==ma :
    Ma.append(A[i][1])
    i+=1

while B[j][0]==mb :
    Mb.append(B[j][1])
    j+=1

if Ma==Mb :
    print(min(n-ma-B[j][0],n-mb-A[i][0]))
else :
    print(n-ma-mb)


### FIXED CODE ###

n = int(input())
V = list(map(int,input().split()))

A = [[0] * (10**5+1) for i in range(2)]

for i in range(n):
    A[i%2][V[i]] += 1

C = [[0] * (10**5+1) for i in range(2)]  # A[0][:i], A[1][:i]の最大値
for i in range(1, len(C[0])):
    C[0][i] = max(C[0][i-1], A[0][i])
    C[1][i] = max(C[1][i-1], A[1][i])

# print(A[0][:150])
# print(A[1][:150])
# print(C[:150])

ans = 0
for i in range(1, len(C[0])):
    ans = max(ans, C[1][i-1] + A[0][i])
    ans = max(ans, C[0][i-1] + A[1][i])

print(n - ans)
n,k=map(int,input().split())
a=list(input().split())
p = [0]*200000
q = [0]*200000
p[0]=1
p[1]=int(a[0])
q[0]=1
q[p[1]-1]=2
f=0
for i in range(k-1):
    p[i+2]=int(a[p[i+1]-1])
    if q[p[i+2]-1]>0:
        r=q[p[i+2]-1]-1
        q=i+2-r
        f=1
        break
    if f==1:
        break
    q[p[i+2]-1]=i+3
l=k-r
l%=q
s=p[r+l]
if f==0:    
    print(p[k])
else:
    print(s)

### FIXED CODE ###

n,k=map(int,input().split())
a=list(input().split())
p = [0]*200000
q = [0]*200000
p[0]=1
p[1]=int(a[0])
q[0]=1
q[p[1]-1]=2
f=0
for i in range(k-1):
    p[i+2]=int(a[p[i+1]-1])
    if q[p[i+2]-1]>0:
        r=q[p[i+2]-1]-1
        q=i+2-r
        f=1
        l=k-r
        l%=q
        s=p[r+l]
        break
    if f==1:
        break
    q[p[i+2]-1]=i+3
if f==0:    
    print(p[k])
else:
    print(s)
from fractions import gcd
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

N, X = map(int, input().split())
nums = list(map(int, input().split()))
nums.append(X)
nums.sort()
dists = []

for i in range(N):
    dist = nums[i + 1] - nums[i]
    dists.append(dist)
    
D = gcd(*dists)

print(D)

### FIXED CODE ###

from fractions import gcd
from functools import reduce
n,x = map(int,input().split())
 
l=list(map(int,input().split()))
l=list(map(lambda i: abs(i-x),l))
 
x = reduce(gcd,l)
print(x)
s=input()
t=input()

x=0
for i in renge(3):
  if s[i]==t[i]:
    x+=1
    
print(x)    


### FIXED CODE ###

s=input()
t=input()
c=0
for i in range(3):
    if s[i]==t[i]:
        c+=1

print(c)
H,W = tuple(int(n) for n in input().split())
    if H == 0 and W == 0:
        break
    for h in range(H):
        print("#"*W)


### FIXED CODE ###

while True:
    H,W = tuple(int(n) for n in input().split())
    if H == 0 and W == 0:
        break
    for h in range(H):
        print("#"*W)
    print("")
import math

def GCD(a,b):
	if b == 0:
		return a
	return GCD(b,a%b)

N = int(input())
T = [int(input()) for _ in range(N)]

def SKS(a,b):
	return (a*b)//GCD(a,b)

for i in range(1,N):
	if i == 1:
		temp = SKS(T[0], T[1])
		continue

	temp = SKS(temp, T[i])

print(temp)

### FIXED CODE ###

N = int(input())
T = [int(input()) for _ in range(N)]

def Eucrid(a,b):
	if b == 0:
		return a
	return Eucrid(b,a%b)


ans = 1
for i in range(N):
	ans = (ans * T[i]) // Eucrid(ans, T[i])

print(ans)
H, N = map(int, input().split())
A = input().split()

At = 0
for i in range(N):
  At += A[i]
  
if At >= H:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

H, N = map(int, input().split())
A = input().split()

At = 0
for i in range(N):
  At += int(A[i])
  
if At >= H:
  print('Yes')
else:
  print('No')
N = int(input())
listClock = [int(input()) for i in range(N)]
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

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

ans = 1

for i in listClock:
    ans = int(lcm(ans,i))

print(ans)

### FIXED CODE ###

N = int(input())
listClock = [int(input()) for i in range(N)]

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def lcm(x, y):
    g = gcd(x, y)
    # / で割ると小数判定になり、答えがイカれる。
    return x // g * y

ans = 1
for i in listClock:
    ans = lcm(ans, i)

print(ans)
def stringcc(W,F):
    a = W
    b = F
    c = a+b
    return c

W,F= input().split()
a = stringcc(FW)
print(a)

### FIXED CODE ###


a, b = input().split()

print(b,end='')
print(a,end='')
alpha = [chr(ord('a') + i) for i in range(26)]
# print(alpha)

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

scores = []

for word in P:
    score = 0
    for t in word[0]:
        score += alpha.index(t)
    scores.append({"word": word[0], "score": score})

sorted_dict_list = sorted(scores, key=lambda x:x['score'])

out_str = ""
for d in sorted_dict_list:
    out_str += d["word"]
print(out_str)

### FIXED CODE ###

# 入力
N,L=map(int,input().split())

l=[]
for i in range(N):
  l.append(input())

# ソート
l.sort()

# 出力
print(''.join(l))
A= [int(x) for x in input().split()]

sort(A)

if A == [5,5,7]:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

A= [int(x) for x in input().split()]
 
A.sort()

if A == [5,5,7]:
  print("YES")
else:
  print("NO")
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

ans = [0] * n
ans = 0
for i in range(n):
    ans[i] = (p[i] + 1) / 2

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + ans[i]
    
res = 0
for i in range(n):
    if k+i > n:
        break
    res = max(res, ruiseki[k + i] - ruiseki[i])
print(res)
    

### FIXED CODE ###

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

ans = [0] * n
for i in range(n):
    ans[i] = (p[i] + 1) / 2

ruiseki = [0] * (n + 1)
for i in range(n):
    ruiseki[i + 1] = ruiseki[i] + ans[i]
    
res = 0
for i in range(n):
    if k+i > n:
        break
    res = max(res, ruiseki[k + i] - ruiseki[i])
print(res)
a,b,c,d=map(int,input().split())

print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d)) or (abs(c-a)<=d) else "No") 


### FIXED CODE ###

a,b,c,d=map(int,input().split())

print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d)) or abs(c-a)<=d) else "No")
N = int(input)
print(N/2 if N%2==0 else (N+1)/2)

### FIXED CODE ###

N = int(input())
print(N/2/N if N%2==0 else (N+1)/2/N)
a=input()
ans = ''

for i,j in enumerate(a):
    if j == '?':
        if ans[-1] == 'P':
            ans+='D'
        elif a[i+1] == 'D':
            ans+='P'
        elif a[i+1] == '?':
            ans+='P'
        else:
            ans+='D'
    else:
        ans+=j

print(ans)

### FIXED CODE ###

a = input()

print(a.replace('P?', 'PD').replace('?D', 'PD').replace('??', 'PD').replace('?', 'D'))
N=int(input())
A=[int(input()) for x in range(N)]
y=set()
for i in A:
    if i in y:
        y.remove(i)
    else:
        y.append(i)
print(len(y))


### FIXED CODE ###

N=int(input())
A=[int(input()) for x in range(N)]
y=set()
for i in A:
    if i in y:
        y.remove(i)
    else:
        y.add(i)
print(len(y))
import math

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

print(int(A*B/math.gcd(A, B)))

### FIXED CODE ###

import fractions

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

print(int(A*B/fractions.gcd(A, B)))
'''
ITP-1_5-A
 ????????¢?????????
??????H cm ?????? W cm ???????????¢?????????????????°?????????????????????????????????
1 cm ?? 1cm ???????????¢??? '#'??§??¨????????????
???Input
??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
H W
H, W ?????¨?????? 0 ?????¨????????\?????????????????¨????????????
???Output
????????????????????????????????????H ?? W ?????? '#' ??§????????????????????¢???????????????????????????
?????????????????????????????????????????????????????\??????????????????
'''
# import
import sys

# ?????°??????????????????
for inputData in sys.stdin:
    inputData = inputData.split(" ")
    H, W = int(inputData[0]), int(inputData[1])
    if H == 0 and W == 0
        break;

    for cntH in H
        print("#", *H)

### FIXED CODE ###

'''
ITP-1_5-A
 ????????¢?????????
??????H cm ?????? W cm ???????????¢?????????????????°?????????????????????????????????
1 cm ?? 1cm ???????????¢??? '#'??§??¨????????????
???Input
??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
H W
H, W ?????¨?????? 0 ?????¨????????\?????????????????¨????????????
???Output
????????????????????????????????????H ?? W ?????? '#' ??§????????????????????¢???????????????????????????
?????????????????????????????????????????????????????\??????????????????
'''
# import
import sys

for line in sys.stdin:
    # ?????°??????????????????
    H, W = map(int, line.split())
    if H == 0 and W == 0:
        break
    # ?????¢??????
    print(('#' * W + '\n') * H)
S = input()
l = len(S)
Q = S.count('?')
ans = 0
for i in range(l-2):
    for j in range(l-i-2):
        for k in range(l-i-j-2):
            d = 3**Q
            s1 = S[i]; s2 = S[i+j+1]; s3 = S[i+j+k+2]
            if s1 == 'A' or s1 == '?':
                if s1 == '?':
                    d /= 3
                if s2 == 'B' or s2 == '?':
                    if s2 == '?':
                        d /= 3
                    if s3 == 'C' or s3 == '?':
                        if s3 == '?':
                            d /= 3
                        ans += d
                        ans = ans%(10**9+7)
print(int(ans))

### FIXED CODE ###

S = input()
memo = [[0,0,0,0] for i in range(len(S))]
Q = 0
memo[0][0] = 1
if S[0] == 'A':
  memo[0][1] = 1
elif S[0] == '?':
  memo[0][0] = 3
  memo[0][1] = 1
l = 1
while l < len(S):
  s = S[l]
  if s == 'A':
    memo[l][0] = memo[l-1][0]
    memo[l][1] = memo[l-1][1] + memo[l-1][0]
    memo[l][2] = memo[l-1][2]
    memo[l][3] = memo[l-1][3]
  elif s == 'B':
    memo[l][0] = memo[l-1][0]
    memo[l][1] = memo[l-1][1]
    memo[l][2] = memo[l-1][2] + memo[l-1][1]
    memo[l][3] = memo[l-1][3]
  elif s == 'C':
    memo[l][0] = memo[l-1][0]
    memo[l][1] = memo[l-1][1]
    memo[l][2] = memo[l-1][2]
    memo[l][3] = memo[l-1][3] + memo[l-1][2]
  else:
    memo[l][0] = memo[l-1][0]*3
    memo[l][1] = memo[l-1][1]*3 + memo[l-1][0]
    memo[l][2] = memo[l-1][2]*3 + memo[l-1][1]
    memo[l][3] = memo[l-1][3]*3 + memo[l-1][2]
    Q += 1
  memo[l] = [i%(10**9+7) for i in memo[l]]
  l += 1
print(int(memo[l-1][3]))
import sys
import numpy as np
def input(): return sys.stdin.readline().strip()
inf = sys.maxsize

if __name__ == '__main__':
    h, w, k = map(int,input().split())
    s = np.array([[int(i) for i in input()] for _ in range(h)])
    ans = inf
    for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(512)
        hdiv = [1 if i & 2 ** j else 0 for j in range(h - 1)]
        hdiv.append(1)
        sh = sum(hdiv)
        tmpans = sh - 1
        partsum = [0 for _ in range(sh)]
        j = 0
        while j < w: #O(2 * 10 ** 3)
            tmp = 0
            idx = 0
            flag = True
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum[idx] += tmp
                    if partsum[idx] > k:
                        tmpans += 1
                        partsum = [0 for _ in range(sh)]
                        flag = False
                        break
                    tmp = 0
                    idx += 1
            if flag:
                j += 1
        ans = min(ans, tmpans)
    print(ans)


### FIXED CODE ###

import sys
inf = sys.maxsize

if __name__ == '__main__':
    h, w, k = map(int, sys.stdin.readline().strip().split())
    s = [[int(i) for i in sys.stdin.readline().strip()] for _ in range(h)]
    
    ans = inf
    for i in range(2 ** (h - 1)): #縦方向の割り方を全探索 O(512)
        hdiv = [1 if i & 2 ** j else 0 for j in range(h - 1)]
        hdiv.append(1)
        sh = sum(hdiv)
        tmpans = sh - 1
        partsum = [0 for _ in range(sh)]
        partsum_p = [0 for _ in range(sh)]
        j = 0
        for j in range(w): #O(10 ** 3)
            tmp = 0
            idx = 0
            flag = False
            for kk in range(h): #O(10)
                tmp += s[kk][j]
                if hdiv[kk]:
                    partsum_p[idx] = partsum[idx]
                    partsum[idx] += tmp
                    if partsum[idx] > k and not flag:
                        tmpans += 1
                        flag = True
                    tmp = 0
                    idx += 1
            if flag:
                partsum = [partsum[l] - partsum_p[l] for l in range(sh)]
                partsum_p = [0 for _ in range(sh)]
                for kk in range(sh):
                    if partsum[kk] > k:
                        tmpans = inf
                        break
        ans = min(ans, tmpans)
    print(ans)
a,b=map(int,input().split())
print(''.join(sorted([ input() for i in range(a)])))


### FIXED CODE ###

abc =input()
five = abc.count("5")
seven = abc.count("7")
 
if five==2 and seven==1:
  print("YES")
else:
  print("NO")
import math
import copy
H,N=map(int,input().split())

dp=[0]+[None]*H

for i in range(N):
    A,B=map(int,input().split())
    ndp=[0]+[None]*H
    for j in range(A,H+1):
        if ndp[j]==None:
            if ndp[j-A]!=None:
                ndp[j]=ndp[j-A]+B
            continue
        
        if ndp[j-A]==None:
            if ndp[j]!=None:
                ndp[j]=dp[j]
            
            continue

        ndp[j]=min(ndp[j-A]+B,dp[j])

    for j in range(H-A+1,H+1):
        if ndp[j]==None:
            continue

        if ndp[-1]!=None:
            ndp[-1]=min(ndp[j]+B,ndp[-1])
        else:
            ndp[-1]=ndp[j]+B

    dp=ndp

print(dp[-1])

### FIXED CODE ###

import math

def main():
    H,N=map(int,input().split())

    inf=float('inf')
    dp=[0]+[inf]*H

    for i in range(N):
        A,B=map(int,input().split())
        if A>=H:
            #dp[-1]=min(B,dp[-1])
            if B < dp[-1]:
                dp[-1]=B
        else:
            for j in range(A,H+1):
                #dp[j]=min(dp[j-A]+B,dp[j])
                if dp[j-A]+B<dp[j]:
                    dp[j]=dp[j-A]+B

                if j > H-A:
                    #dp[-1]=min(dp[-1],dp[j]+B)
                    if dp[j]+B < dp[-1]:
                        dp[-1]=dp[j]+B

    print(dp[-1])

main()
A,B,C = (input() for i in range(3))
count_A=1
count_B=0
count_C=0
arr = A[0]
for i in range(len(A)+len(B)+len(C)):
    arr = A[count_A] if arr=='a' else B[count_B] if arr=='b' else C[count_C]
    if arr=='a':
        count_A+=1
    elif arr=='b':
        count_B+=1
    else:
        count_C+=1
    if count_A==len(A):
        print('A')
        break
    elif count_B==len(B):
        print('B')
        break
    elif count_C==len(C):
        print('C')
        break
    else:
        continue

### FIXED CODE ###

a = input()
b = input()
c = input()
win = 'a'
while len(a)>=0 and len(b)>=0 and len(c)>=0:
    if win == 'a':
        if len(a)==0:
            break
        win = a[0]
        a = a[1:]
    elif win == 'b':
        if len(b)==0:
            break
        win = b[0]
        b = b[1:]
    else:
        if len(c)==0:
            break
        win = c[0]
        c = c[1:]
print('A' if win == 'a' else 'B' if win == 'b' else 'C')
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)


### FIXED CODE ###

N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    P[k-1] += n
ans = [0] * N
def make(num, A, p):
    ans[num] += p
    for i in A[num]:
        make(i, A, p)
    return
for i in range(0, N):
    if P[i] == 0:
        continue
    else:
        make(i, A, P[i])
print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(2*10**9)
N, Q = map(int, input().split())
A = [[] for _ in range(N)]
for _ in range(N-1):
    i, k = map(int, input().split())
    A[i-1].append(k-1)
    A[k-1].append(i-1)
n_P = [0] * N
for _ in range(Q):
    k, n = map(int, input().split())
    n_P[k-1] += n
ans = [0] * N
visited = [0] * N
def make(num, p):
    ans[num] += n_P[num] 
    ans[num] += p
    visited[num] = 1
    for i in A[num]:
        if visited[i] == 0:
            make(i,ans[num])
    return
make(0, ans[0])
print(*ans)
a,s,d=input(),split(',')
print(a,s,d)

### FIXED CODE ###

a,s,d=input().split(',')
print(a,s,d)
def pin(type=int):
    return map(type,input().rstrip().split())
from math import gcd
def resolve():
    A,B=pin()
    ans=0
    plug=1
    while(1):
        ans+=1
        plug=plug-1+A
        if plug>=B:
            print(ans)
            break


### FIXED CODE ###

def pin(type=int):
    return map(type,input().rstrip().split())

def resolve():
    A,B=pin()
    ans=0
    plug=1
    while(1):
        if plug>=B:
            print(ans)
            break
        ans+=1
        plug=plug-1+A
        
resolve()
n = input()
while(n > 0):
    n -= 1000
print(-n)


### FIXED CODE ###

n = int(input())
while(n > 0):
    n -= 1000
print(-n)
N=int(input())
if N==1:
    print("Hello World")
else:
    A,B=map(int,input().split())
    print(A+B)


### FIXED CODE ###

N=int(input())
if N==1:
    print("Hello World")
else:
    A=int(input())
    B=int(input())
    print(A+B)
#--import&define---------------------
import math
import sys
input = sys.stdin.readline
def yes():
    print("Yes")
def no():
    print("No")

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
#--以下解答---------------------------------
x = int(input())
prime_list = primes(10**5)

i = x+1
flag = True
while flag == True:
    if prime_list[i] == True:
        print(i)
        sys.exit()
    i += 1
#

### FIXED CODE ###

#--import&define---------------------
import math
import sys
input = sys.stdin.readline
def yes():
    print("Yes")
def no():
    print("No")

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
#--以下解答---------------------------------
x = int(input())
prime_list = primes(10**6)

i = x
flag = True
while True:
    if prime_list[i] == True:
        print(i)
        sys.exit()
    i += 1