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

#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(temp)
    if len(ls_target)>=k*8:
    #if i==n:
        break
    i+=1

def check(num):
    for i in range(100):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = sum(ls_target[0])
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if sum(ls) & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)

### FIXED CODE ###

#coding:utf-8
n,k  = map(int,input().split())
ls_a  = list(map(int,input().split()))
target = int(k*(k+1)/2)
ls_target = []
i = 1
while(1):
    for j in range(i):
        temp = ls_a[j:(len(ls_a)-i+j+1)]
        ls_target.append(sum(temp))
    if i==n:
        break
    i+=1

def check(num):
    for i in range(50):
        if (num < 2**i):
            return i-1, 2**(i-1)
mx = ls_target[0]
digit, mx_bin = check(mx)
ans = 0
for d in range(digit+1):
#    print (mx_bin)
#    print (ls_target)
    new_idx = []
    cnt = 0
    for idx,ls in enumerate(ls_target):
        if ls & mx_bin > 0:
            cnt += 1
            new_idx.append(idx)
    if cnt >= k:
        ls_target = [ls_target[i] for i in new_idx]
        ans += mx_bin
    mx_bin = int(mx_bin/2)
print (ans)
### BUGGY CODE ###

MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
ifact = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
    ifact.append(pow(f[-1], MOD-2, MOD))
def nCr(n, r):
    return f[n] * ifact[r] * ifact[n-r] % MOD

def nPr(n, r):
    return f[n] * ifact[n-r] % MOD

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    # tmp = pow(nPr(m-k, n-k), 2, MOD) * nPr(m, k) * nCr(n,k) % MOD
    tmp = nPr(m-k, n-k) * nPr(m, n) * nCr(n,k) % MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans = (ans + MOD) % MOD
print(ans)


### FIXED CODE ###

MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def nPr(n, r, mod=MOD):
    return f[n] * pow(f[n-r], mod-2, mod) % mod

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    tmp = nPr(m-k, n-k)
    tmp *= tmp
    tmp %= MOD
    tmp *= nPr(m, k)
    tmp %= MOD
    tmp *= nCr(n,k)
    tmp %= MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans += MOD
ans %= MOD
print(ans)
### BUGGY CODE ###

import math
def dis(x1,y1,r1,x2,y2,r2):
    if math.sqrt(abs(x1-x2)**2+abs(y1-y2)**2)>r1+r2:
        return  math.sqrt(abs(x1-x2)**2+abs(y1-y2)**2)-r1-r2
    else:
        return 0
import heapq

def dijkstra(s,g,c,n):
    d=[float('inf')]*n
    d[s]=0
    pq=[]
    heapq.heappush(pq,[0,s])
    while len(pq)!=0:
        t,u=heapq.heappop(pq)
        if d[u]<t:
            continue
        for v in g[u]:
            if d[u]+c[u][v]<d[v]:
                d[v]=d[u]+c[u][v]
                heapq.heappush(pq,[d[v],v])
    return d
def main():
    xs,ys,xt,yt=map(int,raw_input().split())
    n=int(raw_input())
    c=[[xs,ys,0]]+[map(int,raw_input().split()) for _ in xrange(n)]+[[xt,yt,0]]
    g=[[] for _ in xrange(n+2)]
    dist=[[float("inf")]*(n+2) for _ in xrange(n+2)]
    for i in xrange(n+2):
        for j in xrange(n+2):
            if i==j:continue
            g[i].append(j)
            dist[i][j]=min(dist[i][j],dis(c[i][0],c[i][1],c[i][2],c[j][0],c[j][1],c[j][2]))
            dist[j][i]=dist[i][j]
    ans=dijkstra(0,g,dist,n+2)
    print(ans[n+1])
main()

### FIXED CODE ###

import math
import heapq
def dijkstra(s,m,n):
    visited=[0]*n
    d=[float("inf")]*n
    d[s]=0
    while True:
        mincost=float("inf")
        for i in xrange(n):
            if visited[i]!=2 and d[i]<mincost:
                mincost=d[i]
                u=i
        if mincost==float("inf"):
            break
        visited[u]=2
        for v in xrange(n):
            if visited[v]!=2:
                if d[u]+m[u][v]<d[v]:
                    d[v]=d[u]+m[u][v]
                    visited[v]=1
    return d

def main():
    xs,ys,xt,yt=map(int,raw_input().split())
    n=int(raw_input())
    c=[[xs,ys,0]]+[map(int,raw_input().split()) for _ in xrange(n)]+[[xt,yt,0]]
    dist=[[float("inf")]*(n+2) for _ in xrange(n+2)]
    for i in xrange(n+2):
        for j in xrange(n+2):
            if i==j:continue
            dist[i][j]=min(dist[i][j],dist[j][i],max(math.sqrt(abs(c[i][0]-c[j][0])**2+abs(c[i][1]-c[j][1])**2)-c[i][2]-c[j][2],0))
            dist[j][i]=dist[i][j]
    ans=dijkstra(0,dist,n+2)
    print(ans[n+1])
main()
### BUGGY CODE ###

from collections import defaultdict

n = int(input())
alist = list(map(int,input().split()))
q = int(input())


dict_n = defaultdict(lambda:0)

for i in alist:
    dict_n[i] += 1

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])


for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]

    dict_n[c] += dict_n[b]
    dict_n[b] = 0

    sum = 0
    for key in dict_n:
        sum += key * dict_n[key]
    print(sum)

### FIXED CODE ###

from collections import defaultdict

n = int(input())
alist = list(map(int,input().split()))
q = int(input())


dict_n = defaultdict(lambda:0)

for i in alist:
    dict_n[i] += 1

bclist = []
for i in range(q):
    b,c  = map(int,input().split())
    bclist.append([b,c])

sum = sum(alist)
for i in range(q):
    
    b = bclist[i][0]
    c = bclist[i][1]

    sum += dict_n[b]*c - dict_n[b]*b
    dict_n[c] += dict_n[b]
    del(dict_n[b])

    print(sum)
### BUGGY CODE ###

import sys
INF = 1_000_000_007


def comb(n, k):
    if n == 0 or k == 0:
        return 1
    a = n
    for i in range(n - 1, n - k, -1):
        a *= i
    b = 1
    for i in range(2, k + 1):
        b *= i
    return a // b


N, M = list(map(int, input().split()))
A = [-1] + [int(input()) for _ in range(M)] + [N + 1]
res = 1
for i in range(M + 1):
    t = A[i + 1] - A[i] - 2
    if t < 0:
        print(0)
        sys.exit()
    else:
        _t = 0
        for i in range(t // 2 + 1):
            _t += comb(t - i, i)
        res *= _t
print(res % INF)


### FIXED CODE ###

MOD = 10 ** 9 + 7
N, M = list(map(int, input().split()))
B = [True] * (N + 1)
D = [1] + [0] * N
for _ in range(M):
    a = int(input())
    B[a] = False
for i in range(N):
    for j in range(i + 1, min(N, i + 2) + 1):
        if B[j]:
            D[j] = (D[j] + D[i]) % MOD
print(D[N])
### BUGGY CODE ###

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

import sys

def make_prime_list(lim):
    lst = [True for i in xrange(lim + 1)]

    num = 2
    while num ** 2 <= lim:
        for i in xrange(num * 2, lim + 1, num):
            lst[i] = False
        num += 1
        while not lst[num]:
            num += 1
    return [i for i in xrange(2, lim + 1) if lst[i]]

def binary_search(n, prime_list):
    rLim = len(prime_list) - 1
    lLim = 0
    while lLim < rLim:
        middle = (rLim + lLim) / 2
        if prime_list[middle] == n:
            return middle
        elif prime_list[middle] < n:
            lLim = middle + 1
        else:
            rLim = middle - 1
    while prime_list[rLim] < n and rLim < len(prime_list) - 1:
        rLim += 1
    return rLim    

def solve():
    prime_list = make_prime_list(50000)
    while True:
        n = input()
        if n > 0:
            count = 0
            index = 0
            rev_index = binary_search(n, prime_list)
            while index <= rev_index:
                while prime_list[index] + prime_list[rev_index] > n:
                    rev_index -= 1
                if prime_list[index] + prime_list[rev_index] == n:
                    count += 1
                index += 1
            print count
        else:
            sys.exit()

if __name__ == "__main__":
    solve()
    

### FIXED CODE ###

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

import sys

def make_prime_list(lim):
    lst = [True for i in xrange(lim + 1)]

    num = 2
    while num ** 2 <= lim:
        for i in xrange(num * 2, lim + 1, num):
            lst[i] = False
        num += 1
        while not lst[num]:
            num += 1
    return [i for i in xrange(2, lim + 1) if lst[i]]

def binary_search(n, prime_list):
    rLim = len(prime_list) - 1
    lLim = 0
    while lLim < rLim:
        middle = (rLim + lLim) / 2
        if prime_list[middle] == n:
            return middle
        elif prime_list[middle] < n:
            lLim = middle + 1
        else:
            rLim = middle - 1
    while prime_list[rLim] < n and rLim < len(prime_list) - 1:
        rLim += 1
    return rLim    

def solve():
    prime_list = make_prime_list(50000)
    while True:
        n = input()
        if n > 0:
            if n % 2 == 0:
                count = 0
                index = 0
                rev_index = binary_search(n, prime_list)
                while index <= rev_index:
                    while prime_list[index] + prime_list[rev_index] > n:
                        rev_index -= 1
                    if index <= rev_index and prime_list[index] + prime_list[rev_index] == n:
                        count += 1
                    index += 1
                print count
            else:
                if n - 2 in prime_list:
                    print 1
                else:
                    print 0
        else:
            sys.exit()

if __name__ == "__main__":
    solve()
### BUGGY CODE ###

import sys
#DEBUG=True
DEBUG=False
if DEBUG:
    f=open("202006_5th/D_input.txt")
else:
    f=sys.stdin
ans=1
n=int(f.readline().strip())
prime=[]
# Start from where n is equal to 2
for _ in range(1,n):
    number_of_multiply = []
    tmp=_+1
    for __ in prime:
        cnt=0
        while (tmp%__)==0:
            cnt+=1;tmp=int(tmp/__);
        if cnt>0:
            number_of_multiply.append(cnt)
    if len(number_of_multiply)==0:
        prime.append(_+1)
        ans+=(_+1)*2
    else:
        num_of_divisor=1
        for ___ in number_of_multiply:
            num_of_divisor*=___+1
        ans+=(_+1)*num_of_divisor
print(ans)

### FIXED CODE ###

import sys
#DEBUG=True
DEBUG=False
if DEBUG:
    f=open("202006_5th/D_input.txt")
else:
    f=sys.stdin
ans_sum=0
n=int(f.readline().strip())
for _ in range(1,n+1):
    num=n//_
    ans_sum+=_*((num*(num+1))//2)
print(ans_sum)
### BUGGY CODE ###

N = int(input())
numlist = list(map(int,input().split()))

check = 0
i = 0
while i < N-1:
    a = numlist[i]
    j = i + 1
    while j < N:
        if a == numlist[j]:
            check = 1
            break
        j = j + 1
    i = i + 1

if check == 1:
    print('NO')
else:
    print('YES')

### FIXED CODE ###

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

check = 0
i = 0
while i < N-1:
    j = i + 1
    if numlist[i] == numlist[j]:
        check = 1
        break
    i = i + 1

if check == 1:
    print('NO')
else:
    print('YES')
### BUGGY CODE ###

N = int(input())
S = input()
 
ans = set()
 
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            ans.add(S[i] + S[j] + S[k])
 
print(len(ans))

### FIXED CODE ###

N = int(input())
S = input()

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            fi = S.find(str(i))
            if fi < 0:
                continue
            fj = S[fi+1:].find(str(j))
            if fj < 0:
                continue
            fk = S[fi+fj+2:].find(str(k))
            if fk < 0:
                continue
            ans += 1

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

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
A.extend(A)
odds = [s for s in range(N) if s%2 ==0]
Ans=[-S + 2*sum([s for s,num in zip(A[i:i+N], range(N)) if num in odds] )
     for i in range(N) ]
print(" ".join(map(str,Ans) ))

### FIXED CODE ###

N = int( input() )
A = list(map(int, input().split() ))
S = sum(A)
odds = range(0,N,2)
Ans=[]
Ans.append(-S + 2*sum([s for s,num in zip(A, range(N)) if num in odds] ) )
for i in range(1,N):
    Ans.append(2*A[i-1]-Ans[i-1])
print(" ".join(map(str,Ans) ))
### BUGGY CODE ###

from operator import mul
from functools import reduce

n, a, b = map(int, input().split())

r1 = min(a, n - a)
r2 = min(b, n - b)

if r1 > r2:
  r1, r2 = r2, r1

numer1 = reduce(mul, range(n, n - r1, -1), 1)
denom1 = reduce(mul, range(1, r1 + 1), 1)
numer2 = reduce(mul, range(n - r1, n - r2, -1), numer1)
denom2 = reduce(mul, range(r1 + 1, r2 + 1), denom1)

print((2 ** n - 1 - numer1 // denom1 - numer2 // denom2) % (10 ** 9 + 7))


### FIXED CODE ###

from operator import mul
from functools import reduce

n, a, b = map(int, input().split())

mod = 10 ** 9 + 7

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     :
      return 1
    elif y == 1     :
      return x % mod
    elif y % 2 == 0 :
      return power(x, y//2)**2 % mod
    else            :
      return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

r1 = min(a, n - a)
r2 = min(b, n - b)

if r1 > r2:
  r1, r2 = r2, r1

numer1 = reduce(mul, range(n, n - r1, -1), 1)
denom1 = reduce(mul, range(1, r1 + 1), 1)
numer2 = reduce(mul, range(n - r1, n - r2, -1), numer1)
denom2 = reduce(mul, range(r1 + 1, r2 + 1), denom1)

print((power(2, n) - 1 - div(numer1, denom1) - div(numer2, denom2)) % (10 ** 9 + 7))
### BUGGY CODE ###

from collections import Counter
import copy

N = int(input())

target_list = list(map(int, input().split()))
check = [Counter(target_list)]
result_list = [sum(target_list)]


for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check[index]:
        result = copy.deepcopy(check[index])
        change = result.pop(B)
        diff = change * (C - B)
        if C in result:
            result[C] = result[C] + change
        else:
            result[C] = change

    else:
        result = copy.deepcopy(check[index])
        diff = 0
    check.append(result)
    print(result_list[index] + diff)
    result_list.append(result_list[index] + diff)


### FIXED CODE ###

from collections import Counter

N = int(input())

target_list = list(map(int, input().split()))
check = Counter(target_list)
result = sum(target_list)


for index in range(int(input())):
    B, C = map(int, input().split())
    if B in check:
        result = result + (check[B]) * (C - B)
        if C in check:
            check[C] = check[C] + check[B]
        else:
            check[C] = check[B]
        check[B] = 0
    print(result)
### BUGGY CODE ###

import collections
n, m = map(int, input().split())
linked = collections.defaultdict(set)
for i in range(1, n + 1):
  linked[i].add(i)

for i in range(m):
  a, b = map(int, input().split())
  if len(linked[a]) > len(linked[b]):
     tmp = a
     a = b
     b = tmp
  linked[a].update(linked[b])
  tmp =linked[a]

  for t in linked[b]:
    linked[t] = tmp

n_connected = 0
n_group = 0
for s in linked.values():
  if s:
    n_group += 1
    n_connected += len(s)
    s.clear()
print((n - n_connected) + (n_group - 1))


### FIXED CODE ###

import collections
n, m = map(int, input().split())
linked = collections.defaultdict(list)
i2group = dict()

gid = n + 1
def get_root(i):
  if i not in linked:
    return i
  j = get_root(linked[i])
  linked[i] = j
  return j

def get_groups():
  return [get_root(i) for i in range(1, n + 1)]

for i in range(m):
  a, b = map(int, input().split())
  ra, rb = get_root(a), get_root(b)
  if ra == rb: continue
  linked[ra] = gid
  linked[rb] = gid
  gid += 1

g = get_groups()
print(len(set(g)) - 1)
exit()

n_connected = 0
n_group = 0
for s in linked.values():
  s = s[0]
  if s:
    n_group += 1
    n_connected += len(s)
    s.clear()
print((n - n_connected) + (n_group - 1))
### BUGGY CODE ###

import sys
import heapq

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

def removeWalls(wallPointH,wallPointW):
  if maze[wallPointH][wallPointW]=="#":
    changeTo = "."
  elif maze[wallPointH][wallPointW]=="1":
    changeTo = "0"
  if maze[wallPointH][wallPointW]=="#" or maze[wallPointH][wallPointW]=="1":
    maze[wallPointH][wallPointW]=changeTo
    if wallPointH+1 <= H-1:
      removeWalls(wallPointH+1,wallPointW)
    if wallPointW+1 <= W-1:
      removeWalls(wallPointH,wallPointW+1)

if maze[0][0]=="#":
  flag=1
else:
  flag=0
      
que = [[flag,0,0]]
heapq.heapify(que)
count = 0
      
while que:
  qu = heapq.heappop(que)
  if qu[0]==1:
    heapq.heappush(que, qu)
    count += 1
    for q in que:#いったん"#"の撤去作業を行う
      q[0]=0
      removeWalls(q[1],q[2])
  else:#queの中身にまだ進める場所があるなら
    nowH = qu[1]
    nowW = qu[2]
    if nowH==H-1 and nowW==W-1:#ゴールの場合
      print(count)
      sys.exit()
    else:#それ以外の場合
      #右近傍と下近傍、それぞれマップの中ならqueに格納。
      if nowH+1 <= H-1:
        if maze[nowH+1][nowW]=="#":
          maze[nowH+1][nowW]=="1"
          heapq.heappush(que, [1,nowH+1,nowW])
        elif maze[nowH+1][nowW]==".":
          maze[nowH+1][nowW]=="0"
          heapq.heappush(que, [0,nowH+1,nowW])
      if nowW+1 <= W-1:
        if maze[nowH][nowW+1]=="#":
          maze[nowH][nowW+1]=="1"
          heapq.heappush(que, [1,nowH,nowW+1])
        elif maze[nowH][nowW+1]==".":
          maze[nowH][nowW+1]=="0"
          heapq.heappush(que, [0,nowH,nowW+1])
        



### FIXED CODE ###

import sys
import heapq

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

def removeWalls(wallPointH,wallPointW):
  if maze[wallPointH][wallPointW]=="#":
    changeTo = "."
  elif maze[wallPointH][wallPointW]=="1":
    changeTo = "0"
  if maze[wallPointH][wallPointW]=="#" or maze[wallPointH][wallPointW]=="1":
    maze[wallPointH][wallPointW]=changeTo
    if wallPointH+1 <= H-1:
      removeWalls(wallPointH+1,wallPointW)
    if wallPointW+1 <= W-1:
      removeWalls(wallPointH,wallPointW+1)

if maze[0][0]=="#":
  flag=1
else:
  flag=0
      
que = [[flag,0,0]]
heapq.heapify(que)
count = 0
      
while que:
  qu = heapq.heappop(que)
  if qu[0]==1:
    heapq.heappush(que, qu)
    count += 1
    for q in que:#いったん"#"の撤去作業を行う
      q[0]=0
      removeWalls(q[1],q[2])
  else:#queの中身にまだ進める場所があるなら
    nowH = qu[1]
    nowW = qu[2]
    if nowH==H-1 and nowW==W-1:#ゴールの場合
      print(count)
      sys.exit()
    else:#それ以外の場合
      #右近傍と下近傍、それぞれマップの中ならqueに格納。
      if nowH+1 <= H-1:
        if maze[nowH+1][nowW]=="#":
          maze[nowH+1][nowW]="1"
          heapq.heappush(que, [1,nowH+1,nowW])
        elif maze[nowH+1][nowW]==".":
          maze[nowH+1][nowW]="0"
          heapq.heappush(que, [0,nowH+1,nowW])
      if nowW+1 <= W-1:
        if maze[nowH][nowW+1]=="#":
          maze[nowH][nowW+1]="1"
          heapq.heappush(que, [1,nowH,nowW+1])
        elif maze[nowH][nowW+1]==".":
          maze[nowH][nowW+1]="0"
          heapq.heappush(que, [0,nowH,nowW+1])
### BUGGY CODE ###

from functools import reduce
from operator import mul

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

result = reduce(mul, a_list)

if result > 10 ** 18:
    print(-1)
else:
    print(result)

### FIXED CODE ###

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

if 0 in a_list:
    print(0)
else:
    result = 1
    for a in a_list:
        result = result * a
        if result > 10 ** 18:
            print(-1)
            break
    else:
        print(result)
### BUGGY CODE ###

S = input()
mod = 2019
cnt = [0]*mod
cnt[0] = 1
n = 0
t = 1
for i in map(int,S[::-1]):
    n += i*t
    cnt[n%mod] += 1
    t *= 10
print(sum(i*(i-1)//2 for i in cnt))

### FIXED CODE ###

S = input()
cnt = [0]*2019
cnt[0] = 1
n = 0
t = 1
for i in reversed(S):
    n += int(i)*t
    n %= 2019
    cnt[n] += 1
    t *= 10
    t %= 2019
print(sum(i*(i-1)//2 for i in cnt))
### BUGGY CODE ###

import sys
from collections import Counter
from collections import defaultdict
sys.setrecursionlimit(10**8)
input = lambda: sys.stdin.readline()[:-1]
cnt=Counter()
data=defaultdict(set)
visited=Counter()
n,q=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n-1)]
px=[tuple(map(int,input().split())) for i in range(q)]
ab.sort(key=lambda tup:(tup[0],tup[1]))
for i in ab:
	data[i[0]].add(i[1])
	data[i[1]].add(i[0])
for j in px:
	cnt[j[0]]+=j[1]

def plus(now,value):
	for i in data[now]:
		if not visited[i]:
			cnt[i]+=value
			visited[i]=1
			# print(cnt)	
			plus(i,cnt[i])
		
		
cnt[1]+=0
visited[1]=1
plus(1,cnt[1])
# print(cnt)

ans=sorted(cnt.items())
print(*[i[1] for i in ans])



### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
input = lambda: sys.stdin.readline()[:-1]
n,q=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n-1)]
px=[tuple(map(int,input().split())) for i in range(q)]
# ab.sort(key=lambda tup:(tup[0],tup[1]))
visited=[0]*(n+1)
cnt=[0]*(n+1)
data=[[] for i in range(n+1)]

for i in ab:
	data[i[0]].append(i[1])
	data[i[1]].append(i[0])
for j in px:
	cnt[j[0]]+=j[1]
	# print(cnt)
# count=0
def plus(now,value,parent):
	for i in data[now]:
		# global count
		# count+=1
		if i==parent:continue
			
		cnt[i]+=value
		visited[i]=1
		# print(cnt)	
		
		plus(i,cnt[i],now)
		
		
visited[1]=1
plus(1,cnt[1],0)
print(*cnt[1:])
# print(count)

# ans=sorted(cnt.items())
# print(*[i[1] for i in ans])
### BUGGY CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
L = [[0]*n for i in range(n)]
li = [i+1 for i in range(n)]
uf = UnionFind(n)

for i in range(m):
    a,b = map(int,input().split())
    L[a-1][b-1] = 1
    L[b-1][a-1] = 1
    uf.union(a-1,b-1)

ans = 0
for i in range(n):
    ans = max(ans,uf.size(i))
print(ans)

### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

uf = UnionFind(n)

for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)

ans = 0
for i in range(n):
    ans = max(ans,uf.size(i))
print(ans)