Harryxun/stf_run huggingface dataset:
n,k= map(int, input().split())
a= list(map(int, input().split()))
a.sort()

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=-1
r=a[-1]+1
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=-(-a[i]//mid)-1
            cnt-=x

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)

### FIXED CODE ###

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

if k==0:
    print(a[-1])
    exit()


# めぐる式二部探索
l=0
r=pow(10,11)
while r-l>1:
    # rは常にOK、lは常にNG。
    mid=l+(r-l)//2
    cnt=k
    flag=True
    for i in range(n):
        if a[i]>mid:
            x=-(-a[i]//mid)-1
            cnt-=x

    # なんらかの判定
    if cnt>=0:
        r = mid  # 判定がOKのとき→範囲を左に狭める
    else:
        l = mid  # 判定がNGのとき→範囲を右に狭める

print(r)
from functools import reduce
import math


def solve():
    n, X = map(int, input().split())
    xs = list(map(int, input().split()))
    diffs = [abs(x - X) for x in xs]
    return reduce(math.gcd, diffs)


if __name__ == "__main__":
    print(solve())


### FIXED CODE ###

from functools import reduce
import fractions


def solve():
    n, X = map(int, input().split())
    xs = list(map(int, input().split()))
    diffs = [abs(x - X) for x in xs]
    return reduce(fractions.gcd, diffs)


if __name__ == "__main__":
    print(solve())
N = int(input())
A = input().split()
 
 
#リストAの要素をすべて掛け算
product = 1
for i in A:
    product *= int(i)
 
if product > 10 ** 18:
    product = -1
 
print(product)

### FIXED CODE ###

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

print(A * B)
s=intput()
if int(s[:4])<=2019:
    if int(s[4:6])<=4:
        if int(s[6:]):
            print("Heisei")
            exit()
print("TBD")


### FIXED CODE ###

s=input()
if int(s[:4])<=2019:
    if int(s[5:7])<=4:
        if int(s[8:]):
            print("Heisei")
            exit()
print("TBD")
A,B = input().split()

cnt = 1
num = A

if num < B:
  while num < B:
    num = num + (A -1)
    cnt += 1
elif B == 1:
  cnt = 0
  
print(cnt)

  

  
    


### FIXED CODE ###

A,B = map(int, input().split())
 
cnt = 1
num = A
 
if num < B:
  while num < B:
    num = num + (A - 1)
    cnt += 1
elif B == 1:
  cnt = 0
  
print(cnt)
n = int(input())
print(800*n - 200*(n//15)

### FIXED CODE ###

n = int(input())
print(800*n - 200*(n//15))
import sys
 
size = int(input())
a = map(int, input().split())
cnt = 0
 
while True:
  for i in range(size):
    if(a[i]%2 == 1):
      print(cnt)
      sys.exit()
    
  a = list(map(lambda x:x/2, a))
  cnt+=1

### FIXED CODE ###

a = input()
cnt = 0
for i in a:
  if i == '1':
    cnt+=1
    
print(cnt)
def main():
    n,a,b=map(int,input().split())
    t=n//(a+b)
    ans=a*t+min(n%(t*(a+b)),a)
    print(ans)

if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    n,a,b=map(int,input().split())
    if a==0:
        ans=0
    else:
        t=n//(a+b)
        if t==0:
            ans=min(a,n)
        else:
            ans=a*t+min(n%(t*(a+b)),a)
    print(ans)

if __name__=='__main__':
    main()
def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if len(p) == i:
            continue
        if i == n:
            p[i - 1], p[i] = p[i], p[i - 1]
            count += 1
    print(count)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def main():
    N = int(sys.stdin.readline())
    p = list(map(int, input().split()))
    count = 0
    for i, n in enumerate(p, 1):
        if i == n:
            count += 1
            if len(p) != i:
                p[i - 1], p[i] = p[i], p[i - 1]
    print(count)

if __name__ == '__main__':
    main()
a, b, c = map(int, input().split())
ans = c-(a-b)
if ans >= 0:
    print(ans)
else:
    print(o)


### FIXED CODE ###

a, b, c = map(int, input().split())
ans = c-(a-b)
if ans >= 0:
    print(ans)
else:
    print(0)
n,m=map(int,input().split())
c=n%(m//2)
d=m-2*c
c+=d//4
print(c)


### FIXED CODE ###

n,m=map(int,input().split())
if m<2:
    print(0)
    exit()
if n>m//2:
    print(m//2)
    exit()
c=n%(m//2)
d=m-2*c
c+=d//4
print(c)
A = input()
B = input()
if A.length() > B.length():
  print("GREATER")
elif A.length() < B.length():
  print("LESS")
else:
  for a,b in zip(A,B):
    if a > b:
      print("GREATER")
    elif a < b:
      print("LESS")
print("EQUAL")

### FIXED CODE ###

from sys import exit
A = input()
B = input()
if len(A) > len(B):
  print("GREATER")
elif len(A) < len(B):
  print("LESS")
else:
  for a,b in zip(A,B):
    if a > b:
      print("GREATER")
      exit()
    elif a < b:
      print("LESS")
      exit()
  print("EQUAL")
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)

    start = None

    for ti in range(tn):
        t_c = T[ti]
        for si in range(ti, sn):
            s_c = S[si]
            if (tn - ti) > (sn - si):
                return "UNRESTORABLE"
            if t_c == s_c:
                sj = si - ti
                start = sj
                for tj in range(tn):
                    sj_c = S[sj]
                    tj_c = T[tj]
                    if not (tj_c == sj_c or sj_c == '?'):
                        start = None
                        break
                    sj += 1
                if start is not None:
                    created_s = []
                    tj = 0
                    for sj in range(sn):
                        sj_c = S[sj]
                        tj_c = T[tj]
                        if sj >= start and sj <= start + tn:
                            created_s.append(tj_c)
                            tj += 1
                        else:
                            if sj_c == '?':
                                created_s.append('a')
                            else:
                                created_s.append(sj_c)
                    return ''.join(created_s)
    return "UNRESTORABLE"


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)


### FIXED CODE ###

import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start_tmp = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start_tmp = None
                    break
                sj += 1
            start = start_tmp if start_tmp is not None else start

    if start is None:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)
a=int(input())
if int(a[0])==0 and a[1]==0:
  print('NA')
elif int(a[2])==0 and a[3]==0:
  print('NA')
elif int(a[0])>=2:
  print ('YYMM')
elif int(a[0])>=1 and a[1]>=3:
  print('YYMM')
elif int(a[2])>=2:
  print ('MMYY')
elif int(a[2])>=1 and a[3]>=3:
  print('MMYY')


### FIXED CODE ###

S=input()
ab=int(S[0]+S[1])
cd=int(S[2]+S[3])
if ab==0:
  if cd==0:#0000
    print('NA')
  elif cd>=1 and cd<=12:
    #0001~0012
    print('YYMM')
  else: #0013~0099
    print('NA')
elif ab>=1 and ab<=12:
  if cd ==0:
    print('MMYY')
  elif cd>=1 and cd<=12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if cd>=1 and cd<=12:
    print('YYMM')
  else:
    print("NA")
def ABC_43_B():
    s = input()
    t=[]

    for i in range(len(s)):
        if s[i] == '0':
            t.append('0')
        elif s[i] == '1':
            t.append('1')
        else:
            if len(t)==0:
                a=0
            else:
                del t[i-1]

    print(''.join(t))



if __name__ == '__main__':

    ABC_43_B()

### FIXED CODE ###

def ABC_43_B():
    s = input()
    t=[]

    for i in range(len(s)):
        if s[i] == '0':
            t.append('0')
        elif s[i] == '1':
            t.append('1')
        else:
            if len(t)==0:
                a=0
            else:
                del t[len(t)-1]

    print(''.join(t))



if __name__ == '__main__':

    ABC_43_B()
data = {
    'S':[int(x) for x in range(1,14)],
    'H':[int(x) for x in range(1,14)],
    'C':[int(x) for x in range(1,14)],
    'D':[int(x) for x in range(1,14)]
    }
 
n = int(input())
for nc in range(n):
    (s, r) = input().split()
    index = cards[s].index(int(r))
    del cards[s][index]
  
for s in ['S', 'H', 'C', 'D']:
    for r in cards[s]:
        print(s, r)

### FIXED CODE ###

cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
        }
  
n = int(input())
for _ in range(n):
    (s, r) = input().split()
    r = int(r)
    cards[s][r - 1] = r
  
for s in ('S', 'H', 'C', 'D'):
    for r in range(13):
        if cards[s][r] == 0:
            print( '{0:s} {1:d}'.format(s, r+1))
import sys

N = int(sys.stdin.readline())
print(sum(n + 1 for n in range(N - 1)))

### FIXED CODE ###

import sys

S = str(sys.stdin.readline())
T = str(sys.stdin.readline())

# Neglect the last newline character
num_correct = sum(1 if S[i] == T[i] else 0 for i in range(len(S[:-1])))

print(num_correct)
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

a,b,n = inL()

i = 0

l = [0]*b
for i in range(1,min(b,n)+1):
    l[i] = int(a*i/b)-a*int(i/b)
    #if (q <= p):
        #break

print(max(l)) 


### FIXED CODE ###

def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

a,b,n = inL()

x = min(b-1,n)
print(int(a*x/b)-a*int(x/b))
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

### FIXED CODE ###

n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)
n,k = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if sum(a) < k:
    print(n)
    exit()

def search(m):
    if m >= k:
        return True
    x = k-a[m]
    dp = [[float("INF")]*(x+1) for i in range(n)]
    dp[0][0] = 0
    now = 0
    for i in range(n):
        if i == m:
            continue
        for j in range(x+1):
            if dp[now][j] !=float("INF"):
                dp[now+1][j] = min(dp[now][j],dp[now+1][j])
                if a[i]+j < x:
                    dp[now+1][a[i]+j] == a[i]+j
                else:    
                    dp[now+1][-1] = min(a[i]+j,dp[now+1][-1])
        now += 1
    if dp[-1][-1] >= k:
        return False
    else:
        return True
le = -1
ri = n+1


while ri > le+1:
    m = (ri+le)//2

    if search(m):
        ri = m
    else:
        le = m

print(le+1)

### FIXED CODE ###

n,k = map(int,input().split())
a = [0]+sorted(filter(lambda x: x < k, map(int,input().split())))
n = len(a)

def search(m):

    dp = [1] + [0]*k
    for i in range(n):
        if i == m:
            continue
        for j in range(k,a[i]-1,-1):
            dp[j] |= dp[j-a[i]]
    for i in range(k-a[m],k):
        if dp[i]:
            return True
    return False
le = 0
ri = n


while ri > le+1:
    m = (ri+le)//2

    if search(m):
        ri = m
    else:
        le = m

print(le)
X = int(input())

for b in range(-100,100):
    is_minus = False
    if (X + b**5) < 0 : is_minus = True
    result = abs((X + b**5))**(1/5)

    if type(result) is complex:
        continue
    if result - round(result) == 0:
        if is_minus:
            ans_a,ans_b = -b,-round(result)
        else:
            ans_a,ans_b = abs(b),-round(result)


print(ans_a,ans_b)
    

### FIXED CODE ###

X = int(input())

for a in range(-120,120):
    for b in range(-120,120):
        if a**5 - b**5 == X:
            ans_a,ans_b = a,b
            break


print(ans_a,ans_b)
X = int(input())
ans = 0
tmp = str(X)
if len(tmp) >= 2:
    upper = int(tmp[:-2])
    under = int(tmp[-2:])
    if upper * 5 < under:
        ans = 0
    else:
        ans = 1
else:
    ans = 0

print(ans)

### FIXED CODE ###

X = int(input())
ans = 0
tmp = str(X)
if len(tmp) > 2:
    upper = int(tmp[:-2])
    under = int(tmp[-2:])
    if upper * 5 < under:
        ans = 0
    else:
        ans = 1
else:
    ans = 0

print(ans)
# D - Sum of Divisors
from numba import njit


@njit
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# D - Sum of Divisors
def main():
    N = int(input())
    res = 0
    for a in range(1, N + 1):
        for b in range(1, N // a + 1):
            res += a * b
    print(res)


if __name__ == "__main__":
    main()
a,b,x=map(int,input().split())
n=b-a+1
l=[0]*(n+1)
init=a
for i in range(1,n+1):
    if init%x==0:
        l[i]=l[i-1]+1
    else:
        l[i]=l[i-1]
    init+=1
    
print(l)
print(l[-1]-l[0])

### FIXED CODE ###

#48-B
a,b,x=map(int,input().split())
b_count=b//x
a_count=(a-1)//x
print(b_count-a_count)
for i in range(n):
    if i<k:
        if t[i] =='r':
            ans+=p
        elif t[i] =='s':
            ans+=r
        else :
            ans+=s
    else:
        if t[i] =='r' and t[i-k]!='r':
            ans+=p
        elif t[i] =='s' and t[i-k]!='s':
            ans+=r
        elif t[i] =='p' and t[i-k]!='p':
            ans+=s
        else:
            t[i]='a'
            continue
print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())
ans =0
for i in range(n):
    if i<k:
        if t[i] =='r':
            ans+=p
        elif t[i] =='s':
            ans+=r
        else :
            ans+=s
    else:
        if t[i] =='r' and t[i-k]!='r':
            ans+=p
        elif t[i] =='s' and t[i-k]!='s':
            ans+=r
        elif t[i] =='p' and t[i-k]!='p':
            ans+=s
        else:
            t[i]='a'
            continue
print(ans)
#ALDS1_4-D Allocation
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = deque()
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
import numpy as np

Height, Width = map(int,input().split(" "))

lineBlocks = [(input()) for i in range(Height)]

twoDimMap = []
for Block in lineBlocks:
  twoDimMap.append(list(Block))
  
ansList = []
heightList = np.zeros((Height, Width), dtype=int)
widthList  = np.zeros((Height, Width), dtype=int)

for i in range(Height):
  for j in range(Width):
    
    if '#' == twoDimMap[i][j]:
      continue

    else:
        if heightList[i][j] == 0:

            k_up = i+1
            height_len = 0
            while( k_up < Height and twoDimMap[k_up][j] != "#"):
                height_len += 1
                k_up += 1
                
            
            k_down = i-1
            while( k_down >= 0 and twoDimMap[k_down][j] != "#"):
                height_len += 1
                k_down -= 1
            
            for k in range(k_down+1,k_up):
                heightList[k][i] = height_len


        if widthList[i][j] == 0:
            k_right = j+1
            width_len = 0
            while(k_right < Width and twoDimMap[i][k_right] != "#"):
                width_len += 1
                k_right += 1

            k_left = j-1
            while(k_left >= 0 and twoDimMap[i][k_left] != "#"):
                width_len += 1
                k_left -= 1
            
            for k in range(k_left+1,k_right):
                widthList[i][k] = width_len

print(np.array(heightList + widthList + 1).max())

### FIXED CODE ###

import numpy as np
h, w = map(int, input().split())
table = np.array([list(input())for _ in range(h)]) == '.'
 
d = np.zeros((h, w), dtype = int)
u = np.zeros((h, w), dtype = int)
r = np.zeros((h, w), dtype = int)
l = np.zeros((h, w), dtype = int)

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]

for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)
N = int(input())
A = list(map(int,input().split()))
ans = 0
m0 = 10**9+7
for i in range(0,N-1):
    for j in range(i+1,N):
        ans = (ans + A[i]*A[j]) % m0
print(ans)

### FIXED CODE ###

S = input().rstrip()
T = input().rstrip()
count = 0
lens = len(S)
lent = len(T)
for i in range(lens-lent+1):
    tempcount=0
    for j in range(lent):
        if S[i+j]==T[j]:
            tempcount += 1
    #print(tempcount)
    count = max(count,tempcount)

print(lent-count)
N = int(input())
s = []
for i in range(N):
    s.append(input()

M = int(input())
t = []
for i in range(N):
    t.append(input())

sum = 0
for i in range(N):
    temp = 0
    sample = s[i]
    for j in range(N):
        if sample == s[j]:
            temp += 1
    for k in range(M):
        if sample == t[k]:
            temp -= 1
    if temp > sum:
        sum = temp
print(sum)

### FIXED CODE ###

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

M = int(input())
t = []
for i in range(M):
    t.append(input())

sum = 0
for i in range(N):
    temp = 0
    sample = s[i]
    for j in range(N):
        if sample == s[j]:
            temp += 1
    for k in range(M):
        if sample == t[k]:
            temp -= 1
    if temp > sum:
        sum = temp
print(sum)
K = int(input())
S = input()

length = len(S)

if length <= K:
  print(S)
  
else:
  S = S[K:]
  print(S.apend("..."))
  

### FIXED CODE ###

K = int(input())
S = input()

length = len(S)

if length <= K:
  print(S)
  
else:
  S = S[:K]
  print(S + "...")
i = 1

while 1:
  x = input()
  if x = 0:
    break
  else:
    print 'case ' + i + ': ' + x
    i += 1

### FIXED CODE ###

i = 1

while 1:
  x = input()
  if x == 0:
    break
  else:
    print 'Case %d: %d' % (i, x)
    i += 1
print('Even' if int(input())*int(input())%2==0 else 'Odd')

### FIXED CODE ###

a,b=map(int,input().split())
print('Even' if a*b%2==0 else 'Odd')
W, H, x, y, r = map(int, input().split())
if x >= r and x + r <= W and y >= r and y + r <= H :
print("Yes")
else:
  print("No")


### FIXED CODE ###

W,H,x,y,r = map(int,input().split())

a = x+r
b = y+r
c = x-r
d = y-r

if a<=W and b<=H and c>=0 and d>=0:
    print("Yes")
else:
    print("No")
import sys

readline = sys.stdin.readline

def dfs(fr, now, num):
    global graph, addsum, ans
    tmp = num + addsum[now]
    for a in graph[now]:
        if a == fr:
            continue
        dfs(now, a, tmp)
    ans[now] = tmp
    

def main():
    global graph, addsum, ans
    N, Q = map(int, readline().split())
    graph = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1; b -= 1
        graph[a].append(b)
        graph[b].append(a)
    addsum = [0]*N
    for _ in range(Q):
        p, x = map(int, readline().split())
        p -= 1
        addsum[p] += x
    
    ans = [0]*N
    dfs(-1, 0, 0)

    print(*ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

# 深さ優先探索の問題
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

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

# 隣接リスト
t = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = [int(i) for i in readline().split()]
    t[a-1].append(b-1)
    t[b-1].append(a-1)

# スコア
s = [0] * N
for _ in range(Q):
    p, x = [int(i) for i in readline().split()]
    #s[p-1] = s[p-1] + x
    s[p-1] += x

ans = [0] * N

# 深さ優先探索
def dfs(v, p, value):
    #value = value + s[v]
    value += s[v]
    ans[v] = value
    for c in t[v]:
        if c == p:
            continue
        dfs(c, v, value)

dfs(0, -1, 0)

print(*ans)
a=input().split
int(a)
N=a(0) 
K=a(1)
X=a(2)
Y=a(3)
if N > K:
  tot = K*X+(N-K)*Y
else:
  tot = N*X
print(tot)


### FIXED CODE ###

N=int(input())
K=int(input())
X=int(input())
Y=int(input())

if N > K:
  print(K*X+(N-K)*Y)
else:
  print(N*X)
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
N = int(input())
print(lcm(2,N))


### FIXED CODE ###

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
def lcm(x, y):
    return (x * y) // gcd(x, y)
N = int(input())
print(lcm(2,N))
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]*n
y=[0]*m
x[0]=a[0]
y[0]=b[0]
for i in range(0,n-1):
    x[i+1]=x[i]+a[i+1]
for i in range(0,m-1):
    y[i+1]=y[i]+b[i+1]
print(x)
print(y)
ans,j=0,m
for i in range(n):
    if x[i]>k:
        break
    while y[j-1]>k-x[i]:
        j-=1
    ans=max(i+1+j,ans)
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x,y=[0],[0]
for i in range(n):
    x.append(a[i]+x[i])
for j in range(m):
    y.append(b[j]+y[j])

ans=0
j=m
for i in range(n+1):
    if x[i]>k:
        break
    while y[j]>k-x[i]:
        j-=1
    ans=max(i+j,ans)
print(ans)