Harryxun/stf_run huggingface dataset:
import sys

icase=0
if icase==0:
    n,m=map(int,input().split())
#    ab=[[0]*2 for i in range(n)]
    ab=[]
    for i in range(n):
        ai,bi=map(int,input().split())
        if m-ai>=0:
            ab.append([m-ai,-bi])
#        ab[i][0]=m-ai
#        ab[i][1]=-bi
elif icase==1:
    n,m=3,4
    ab=[[2, -2], [0, -1], [0, -3]]    
elif icase==2:
    n,m=5,3
    ab=[[1, -3], [1, -1], [2, -4], [2, -3], [2, -2]]
elif icase==3:
    n,m=1,1
    ab=[]

from heapq import heappop,heappush
#heappush(H,l) 
#print(heappop(H)) #2

#ab.sort(reverse=True)
if len(ab)==0:
    print(0)
    sys.exit()
ab.sort()

a0=ab[0][0]
h=[]
asum=0
idx=0
for i in range(m):
    while ab[idx][0]<m-i:
        heappush(h,ab[idx][1])
#        print("i:",i,"idx:",idx,h)
        idx+=1
        if idx>=n:
            asum+=heappop(h)
#            print("1:",idx,asum,h)
            break
    if idx>=n:
        asum+=heappop(h)
#        print("2:",idx,asum,h)
        break

if idx>=n:
    asum+=heappop(h)
#    print("3:",idx,asum,h)

print(-asum)
    

### FIXED CODE ###

import sys

icase=0
if icase==0:
    n,m=map(int,input().split())
    ab=[[] for i in range(m)]
    for i in range(n):
        ai,bi=map(int,input().split())
        if m-ai>=0:
            ab[m-ai].append(-bi)
elif icase==1:
    n,m=3,4
    ab=[[-3, -1], [], [-2], []]    
elif icase==2:
    n,m=5,3
    ab=[[], [-1, -3], [-2, -3, -4]]
elif icase==3:
    n,m=1,1
    ab=[[]]

from heapq import heappop,heappush

if len(ab)==0:
    print(0)
    sys.exit()

n=len(ab)
h=[]
asum=0
for i in range(m-1,-1,-1):
    if len(ab[i])>0:
        for abi in ab[i]:
            heappush(h,abi)
#    print(i,h,asum)
    if len(h)>0:
        asum+=heappop(h)

print(-asum)
import collections

n = int(input())

a = list(map(int,input().split()))

a.sort()

for i in range(len(a)):
    if dp[i] == True:
        for j, x in enumerate(a[i+1:], 1):
            if dp[i + j] == True:
                if a[i + j] % a[i] == 0:
                    dp[i + j] = False

num_dict = dict(collections.Counter(a))

result = [x for x, y in zip(a, dp) if (y == True) and (num_dict[x] == 1)]

print(len(result))


### FIXED CODE ###

n = int(input())

a = list(map(int,input().split()))

a.sort()

dp = [True] * (a[-1] + 1)

ans = 0

m = a[-1]

for i, x in enumerate(a[:-1]):
    if not a[i+1] == x and dp[x]:
        ans += 1
    for b in range(x, m + 1, x):
        dp[b] = False

if dp[a[-1]]:
    ans += 1

print(ans)
n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))

### FIXED CODE ###

n,k=map(int,input().split())
s=str(input())
s=list(s)
s[k-1]=str.lower(s[k-1])
print("".join(s))
n = list(map(int,input().split()))
if 5 in n :
    n.remove(5)
    if 5 in n and if 7 in n :
        print("YES")
    else:
        print("NO")
else :
    print("NO")

### FIXED CODE ###

n = list(map(int,input().split()))
if 5 in n:
    n.remove(5)
    if 5 in n and 7 in n :
        print("YES")
    else:
        print("NO")
else:
    print("NO")
n,m=map(int,input().split())
g=[[] for x in range(n)]
for c in range(M):
    a,b= map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ans_list=[-1]*n

queue=[0]

while queue:
    qi=queue.pop(0)
    for gi in g[qi]:
        if ans_list[gi]==-1:
            queue.append(gi)
            ans_list[gi]=qi

print("Yes")
for ans in ans_list[1:]:
    print(ans+1)

### FIXED CODE ###

n,m=map(int,input().split())
g=[[] for x in range(n)]
for c in range(m):
    a,b= map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ans_list=[-1]*n

queue=[0]

while queue:
    qi=queue.pop(0)
    for gi in g[qi]:
        if ans_list[gi]==-1:
            queue.append(gi)
            ans_list[gi]=qi

print("Yes")
for ans in ans_list[1:]:
    print(ans+1)
def main():
    n, m = map(int, input().split())
    
    ans = []
    check = []
    check_once = []
    false_flg = 0
    for i in range(n):
        ans.append('0')
        check.append(0)
        check_once.append(0)

    for j in range(m):
        s, c = input().split()

        if int(s) == 1 and int(c) == 0:
            false_flg = 1

        if check[int(s)-1] == 0:
            ans[int(s)-1] = c
            check[int(s)-1] = 1

        elif check[int(s)-1] == 1 and ans[int(s)-1] == c:
            ans[int(s)-1] == c:

        else:
            false_flg = 1
    
    tmp = int("".join(ans))
   
    if tmp // 10**(n-1) > 0 and false_flg != 1:
        print(tmp)
    elif false_flg != 1:
        tmp_ = 10**(n-1) + int(tmp)
        print(tmp_)
    else:
        print(-1)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    n, m = map(int, input().split())
    
    ans = []
    check = []
    check_once = []
    false_flg = 0
    for i in range(n):
        ans.append('0')
        check.append(0)
        check_once.append(0)

    for j in range(m):
        s, c = input().split()

        if int(s) == 1 and int(c) == 0 and n != 1:
            false_flg = 1

        if check[int(s)-1] == 0:
            ans[int(s)-1] = c
            check[int(s)-1] = 1

        elif check[int(s)-1] == 1 and ans[int(s)-1] == c:
            ans[int(s)-1] = c

        else:
            false_flg = 1
    
    tmp = int("".join(ans))
    
    if tmp // 10**(n-1) > 0 and false_flg != 1:
        print(tmp)

    elif false_flg != 1:
        if tmp == 0 and n == 1:
            print(0)
        else:
            tmp_ = 10**(n-1) + int(tmp)
            print(tmp_)
    else:
        print(-1)


if __name__ == '__main__':
    main()
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
data = stdin.readline().rstrip().split()
a = float(data[0])
b = float(data[1])
x = float(data[2])
if (b * a * a >= 2 * x):
    print(90.0 - math.degrees(math.atan(2 * x / (a * b * b))))
else:
    print(90.0 - math.degrees(math.atan(a*a*a/(2 * a*a*b-2 * x))))


### FIXED CODE ###

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.extend(要素)
.insert(場所,要素)
del 配列名[場所]
-1で末尾で末尾から一つ前
'''
'''
間に空白追加
' '.join(lis)
'''
'''
copy.copy(配列名)
'''
'''
sort()50
sorted(reverse=true)
'''
'''
2分探索
bisect.bisect_left(リスト, 要素)
'''
data = stdin.readline().rstrip().split()
a = float(data[0])
b = float(data[1])
x = float(data[2])
if (b * a * a >= 2 * x):
    print(90.0 - math.degrees(math.atan(2 * x / (a * b * b))))
elif (not a * a * b == x):
    print(90.0 - math.degrees(math.atan(a * a * a / (2 * a * a * b - 2 * x))))
else:
    print(0.0)
n=int(input())
ans=1
for i in range(32):
  j=i
  while(j<x):
    j*=i
  ans=max(ans,j//i)
print(ans)

### FIXED CODE ###

import math
n=int(input())
ans=1
for i in range(2,int(math.sqrt(n))+1):
  x=1
  while(x<n+1):
    x=i*x
  ans=max(ans,x//i)
print(ans)
# PrimeNumber
# エラトステネスの篩

import math

if __name__ == "__main__":
    while True:
        try:
            # 数値の入力があった
            n = int(input())
            nlist = []
            nlist2 = []
            plist = []

            # for i in range(2, n + 1):
            #    nlist.append(i)  # [2,3,4,5,6,...,n]
            nlist = range(3, n + 1, 2)

            while True:
                #print(nlist, " ", math.sqrt(n))
                sqrtn = math.sqrt(n)
                if nlist[0] > sqrtn:  # 終了条件
                    #plist.append(map(int,nlist))
                    plist.extend(nlist)
                    break
                else:
                    plist.append(nlist[0])

                    #i = 0
                    for j in nlist:
                        if j % nlist[0] != 0:
                            #nlist.pop(i)
                            #nlist.remove(j)
                            nlist2.append(j)
                            #i += 1
                    nlist = nlist2
                    nlist2 = []
            #print("fin: {}".format(plist))
            print(len(plist)+1) # 2の分を追加

        except EOFError:
            break  # escape from while loop

pass
#

### FIXED CODE ###

if __name__ == "__main__":
	maxn = 1000000
	plist = [False if i%2==0 or i%3==0 or i%5==0 else True for i in range(maxn)]

	plist[0] = plist[1] = False
	plist[2] = plist[3] = plist[5] = True

	for chki in range(3, maxn, 2):
		for j in range(chki**2, maxn, chki):
			plist[j] = False

	while True:
		try:
			#start = time.time()
			inn = int(raw_input())
			print plist[0:inn+1].count(True)
			#print plist
			#print plist.count(True)
			#print plist[0:10].count(True)
			#print plist[0:100000].count(True)
			#print plist[0:1000000].count(True)

			#elapsedTime = time.time() -start
			#print elapsedTime
		except:
			break
a = input().split()
l = a[0]
n = a[1]
s = []
for i in range(int(n)):
    s.append(input())

s.sort()
ret = ""
for i in range(int(n)):
    ret = ret + s[i]

print(ret)

### FIXED CODE ###

a = input().split()
n= a[0]
l = a[1]
s = []
for i in range(int(n)):
    s.append(input())

s.sort()
ret = ""
for i in range(int(n)):
    ret = ret + s[i]

print(ret)
from collections import gcd
#from math import gcd
N,X =map(int,input().split())
x = list(map(int,input().split()))
dif = [x[0]-X]+[x[i+1]-x[i] for i in range(N-1)]
ans = dif[0]
for i in range(1,N):
    ans = gcd(ans,dif[i])
print(ans)


### FIXED CODE ###

from fractions import gcd
#from math import gcd
N,X = map(int,input().split())
x = list(map(int,input().split()))
dif = [abs(x[i+1]-x[i]) for i in range(N-1)]
ans = abs(x[0]-X)
for i in range(N-1):
    ans = gcd(ans,dif[i])
print(ans)
N=int(input())
num=map(int,input().split(" "))
oparation=10^8

for i in range(N):
    temp=0
    while(1):
        if(num[i]%2 or num[i]=0):
            break:
        else:
            num[i]/=2
            temp+=1
    if(oparation>temp):
        oparation=temp

print(oparation)
        

### FIXED CODE ###

a=input().split('1')
b=len(a)-1
print(b)
def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    A.sort()
    A_set = set(A)
    count = 0
    last_num = 0
    flag = True
    now_num = 0
    half_num = 0
    count_flag = False
    
    if A.count(1) == 1:
        print(1)
        exit()
    for i in range(N):
        count_flag = True
        now_num = A[i]
        half_num = A[i]/2
        if now_num == last_num:
            if flag:
                count -= 1
                flag = False
        else:
            for j in range(0, i):
                if A[j] > half_num:
                    break
                if now_num % A[j] == 0:
                    count_flag = False
                    break
            if count_flag:
                if not flag:
                    flag = True
                count += 1
            last_num = A[i]
    print(count)

if __name__ == '__main__':
    main()

### FIXED CODE ###

x = list(map(int, input().split()))
print(x.index(0)+1)
import math
a = input()
s = list(map(int,input().split()))
ans =float("inf")
for i in s:
  ans = min(ans,len(bin(i))-bin(i).rfind("1")-1)
print(round(ans))

### FIXED CODE ###

a = str(input())
s = a.count("1")
print(s)
a = int(input())
s = input()
if a >= '3200':
    print(s)
else:
    print('red')

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print('red')
n = input()

def change(d):
  if d == '1':
    return '9'
  elif d == '9':
   	return '1'
  else
  	return d

print(''.join([change(d) for d in n]))

### FIXED CODE ###

n = input()

def change(d):
  if d == '1':
    return '9'
  elif d == '9':
    return '1'
  else:
    return d

print(''.join([change(d) for d in n]))
a, b = [int(i) in input().split(" ")]
c = a/b
print(int(a/b), a%b, "{0:.6f}".format(c), sep = " ")

### FIXED CODE ###

a, b = [int(i) for i in input().split(" ")]
num1 = a // b
num2 = a % b
num3 = "{:.8f}".format(a / b)

print(num1, num2, num3)
S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    p = 0
    q,r = -1,-1
    for i in range(n):
        j = S[i]
        if ord(j) > p:
            q = i
            T = []
        else:
            if len(T) == 0:
                r = i
            T.append(j)
        p = ord(j)
    if q < r:
        if S[r-1] == 'z':
            if r == 1:
                ans = -1
            else:
                ans = S[0]
                for i in range(1,r-2):
                    ans += S[i]
                ans += T[-1]
    else:
        ans = S[0]
        for i in range(1,n-2):
            ans += S[i]
        ans += S[n-1]
print(ans)

### FIXED CODE ###

S = input()
L = [i for i in range(97,123)]
n = len(S)
for i in range(n):
    L.remove(ord(S[i]))
if n <= 25:
    X = L[0]
    ans = S + chr(X)
else:
    T = []
    x = S[-1]
    T.append(x)
    for i in range(2,27):
        y = S[-i]
        if y > x:
            x = y
            T.append(y)
        else:
            break
    m = 26 - len(T)
    if m > 1:
        ans = S[0]
        for i in range(1,m-1):
            ans += S[i]
        for t in T:
            if t > S[m-1]:
                ans += t
                break
    elif m == 0:
        ans = -1
    else:
        for t in T:
            if t > S[m-1]:
                ans = t
                break
print(ans)
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
minabs = 10**10

for i in range(n):
  if abs(a-(t-h[i]*0.006)) < minabs:
    minabs = abs(a-(t-h[i]*0.006))
    j = i

print(j+1)

### FIXED CODE ###

x,y = map(int,input().split())
print(int(x + y/2))
N = input()
a = []
answer_list = []

for i in range(N):
    a.append(map(int, input().strip().split()))

for j in range(len(a)):
    number_1 = a[j][0]
    number_2 = a[j][1]
    number_3 = a[j][2]

    number_1 = number_1 * 2
    number_2 = number_2 * 2
    number_3 = number_3 * 2

    if number_1 == number_2 + number_3:
        print("YES")
    if number_2 == number_3 + number_1:
        print("YES")
    if number_3 == number_1 + number_2:
        print("YES")

    else:
        print("NO")

### FIXED CODE ###

N = input()
a = []
for i in range(N):
    a.append(map(int, raw_input().split()))

for j in range(N):

    x = a[j][0] ** 2
    y = a[j][1] ** 2
    z = a[j][2] ** 2

    if x == y + z:
        print "YES"
    elif y == x + z:
        print "YES"
    elif z == x + y:
        print "YES"
    else:
        print "NO"
# -*- coding: utf-8 -*-
# Input#
n = int(input())
# n, k = map(int, input().split())
h = list(map(int, input().split()))

h = [-1] + h

ans = 0

memo = [-1] * (n + 1)
memo[1] = 0
memo[2] = abs(h[2] - h[1])


def dp(i):
    if memo[i] != -1:
        return memo[i]
    else:
        hop1 = dp(i - 1) + abs(h[i] - h[i - 1])
        hop2 = dp(i - 2) + abs(h[i] - h[i - 2])
        memo[i] = min(hop1, hop2)
        return memo[i]


ans = dp(n)
print("{}".format(ans))


### FIXED CODE ###

# -*- coding: utf-8 -*-
# Input#
n = int(input())
# n, k = map(int, input().split())
h = list(map(int, input().split()))

h = [-1] + h

ans = 0

memo = [-1] * (n + 1)
memo[1] = 0
memo[2] = abs(h[2] - h[1])


def dp(i):
    if memo[i] != -1:
        return memo[i]
    else:
        hop1 = dp(i - 1) + abs(h[i] - h[i - 1])
        hop2 = dp(i - 2) + abs(h[i] - h[i - 2])
        memo[i] = min(hop1, hop2)
        return memo[i]


for i in range(n):
    if i == 0 or i == 1 or i == 2:
        continue
    hop1 = memo[i - 1] + abs(h[i] - h[i - 1])
    hop2 = memo[i - 2] + abs(h[i] - h[i - 2])
    memo[i] = min(hop1, hop2)

ans = dp(n)

print("{}".format(ans))
N, K, X, Y = [int(input() for _ in range(4))]
print(min(N, K) * X + max(0, N - K) * Y)

### FIXED CODE ###

N, K, X, Y = [int(input()) for _ in range(4)]
print(min(N, K) * X + max(0, N - K) * Y)
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
mod = 1000000000 + 7
def func(n):
    r = 1
    for i in range(1, n+1):
        r *= i
        r %= mod
    return r

N, M = map(int, input().1split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    res = func(A)
    print(int(res**2/A)%mod)
else:
    print(int(2*func(N)**2)%mod)




### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Fri Sep 14 01:10:44 2018

@author: Yuki
"""
mod = 1000000000 + 7
def func(n):
    r = 1
    for i in range(1, n+1):
        r *= i
        r %= mod

    return r
N, M = map(int, input().split())
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    A = max(N, M)
    print(int((func(A)*func(A-1))%mod))
else:
    print(int(2*func(N)*func(N))%mod)
n = int(raw_input())
a = []

for i in range(n):
    inp = raw_input()
    if "-1" in inp:
        inp = inp.replace("-1","10000")
    a.append(list(map(int, inp.split())))

w = 0
v = set()
v.add(0)

while len(v) < n:
    min_w   = 10000
    min_idx = 0
    i = 0
    for node in v:
        if min_w > min(a[node]):
            min_w = min(a[node])
            i = node
            min_idx = a[i].index(min_w)
    if min_idx in v:
        a[i][min_idx] = 10000
        continue
    else:
        w += min_w
        v.add(min_idx)

print(w)

### FIXED CODE ###

n = int(input())
a = []

for i in range(n):
    inp = input()
    if "-1" in inp:
        inp = inp.replace("-1","10000")
    a.append(list(map(int, inp.split())))

w = 0
v = set()
v.add(0)

while len(v) < n:
    min_w   = 10000
    min_idx = 0
    i = 0
    for node in v:
        if min_w > min(a[node]):
            min_w = min(a[node])
            i = node
            min_idx = a[i].index(min_w)
    if min_idx in v:
        a[i][min_idx] = 10000
        continue
    else:
        w += min_w
        v.add(min_idx)

print(w)
a,b = map(int,input())

print(max(a+b,a-b,a*b))

### FIXED CODE ###

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

print(max(a+b,a-b,a*b))
n = int(input())
x = input()
flg = [0] * n
for i in range(n):
    if x[i] == '1':
        flg[i] = 1
x = int(x, 2)
cnt = sum(flg)
x_a = x % (cnt - 1)
x_b = x % (cnt + 1)


for i in range(n):
    if flg[i] == 1:
        if cnt == 1:
            print(0)
            continue
        t = (x_a - pow(2, n-i-1, cnt-1)) % (cnt - 1)
    else:
        t = (x_b + pow(2, n-i-1, cnt+1)) % (cnt + 1)

    if t == 0:
        print(1)
    else:
        tmp = 1
        while t > 0:
            pop = bin(t).count('1')
            t = t % pop
            tmp += 1

        print(tmp)


### FIXED CODE ###

n = int(input())
x = input()
flg = [0] * n
for i in range(n):
    if x[i] == '1':
        flg[i] = 1
x = int(x, 2)
cnt = sum(flg)
if cnt == 1:
    x_a = 0
else:
    x_a = x % (cnt - 1)
x_b = x % (cnt + 1)


for i in range(n):
    if flg[i] == 1:
        if cnt == 1:
            print(0)
            continue
        t = (x_a - pow(2, n-i-1, cnt-1)) % (cnt - 1)
    else:
        t = (x_b + pow(2, n-i-1, cnt+1)) % (cnt + 1)

    if t == 0:
        print(1)
    else:
        tmp = 1
        while t > 0:
            pop = bin(t).count('1')
            t = t % pop
            tmp += 1

        print(tmp)
for x in product((0,1),repeat=H-1):
    cur = 0
    cnt = 0
    h = sum(x)+1
    A = [0 for _ in range(h)]
    flag = 0
    for j in range(W):
        ind = 0
        A0 = [0 for _ in range(h)]
        for i in range(H):
            if i<H-1 and x[i]==1:
                A0[ind] += S[i][j]
                ind += 1
            else:
                A0[ind] += S[i][j]
        B = [A[i]+A0[i] for i in range(h)]
        if j==0 and max(B)>K:
            flag = 1
            break
        if max(B)>K:
            cur = j
            cnt += 1
            A = A0[:]
        else:
            A = B[:]
    if flag ==0:
        cmin = min(cmin,cnt+sum(x))
print(cmin)  

### FIXED CODE ###

from itertools import product
INFTY = 10**4
H,W,K = map(int,input().split())
S = [list(map(int,list(input()))) for _ in range(H)]
cmin = INFTY
for x in product((0,1),repeat=H-1):
    cur = 0
    cnt = 0
    h = sum(x)+1
    A = [0 for _ in range(h)]
    for j in range(W):
        ind = 0
        A0 = [0 for _ in range(h)]
        for i in range(H):
            if i<H-1 and x[i]==1:
                A0[ind] += S[i][j]
                ind += 1
            else:
                A0[ind] += S[i][j]
        B = [A[i]+A0[i] for i in range(h)]
        if max(A0)>K:
            cnt = INFTY
            break
        if max(B)>K:
            cur = j
            cnt += 1
            A = A0[:]
        else:
            A = B[:]
    cmin = min(cmin,cnt+sum(x))
print(cmin)
s = str(input())
a = []

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

print(''.join(a))

### FIXED CODE ###

s = str(input())
a = []

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

print(''.join(a))
def d():
    N = int(input())
    a = {}
    count = 0

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        a[l, r] = a.get((l, r), 0) + 1

    # print(a)

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l,
                                                                         r, a.get((l, r), 0) * a.get((r, l), 0)))
        count += a.get((r, l), 0)

    print(count)


##########
d()


### FIXED CODE ###

def d():
    N = int(input())
    a = {}
    count = 0

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        a[l, r] = a.get((l, r), 0) + 1

    # print(a)

    for i in range(1, N+1):
        l, r = str(i)[0], str(i)[-1]
        # print('a.get(({0}, {1}), 0) * a.get(({1}, {0}), 0) = {2}'.format(l, r, a.get((l, r), 0) * a.get((r, l), 0)))
        count += a.get((r, l), 0)

    print(count)


##########
d()
def addc(p,ko,c,total):
  c[p] += total
  total = c[p]
  if(len(ko[p]) == 0):
    return 0

  else:
    for i in ko[p]:
      addc(i,ko,c,total)

  return 0

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

ko = [ [] for i in range(n + 1)] # 各頂点に紐づく子
c = [0 for i in range(n + 1)] # 各頂点のCの値

for i in range(n-1):
  a,b = map(int,input().split())
  ko[a].append(b) # 親a -> 子bに向かう辺がある

for i in range(q):
  p,x = map(int,input().split())
  c[p] += x # 操作により指定されている頂点にxを加える

_ = addc(1,ko,c,0)

c.pop(0)

print(*c)

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

def addc(p,b):
  for i in e[p]:
    if(i == b):
      continue
    c[i] += c[p]
    addc(i,p)

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

e = [ [] for i in range(n + 1)]
c = [0]*(n+1)

for i in range(n-1):
  a,b = map(int,input().split())
  e[a].append(b)
  e[b].append(a)

for i in range(q):
  p,x = map(int,input().split())
  c[p] += x

addc(1,-1)

print(*c[1:])