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

import sys
import numpy as np
def main():
    n = int(input())
    a = np.array(list(map(int, input().split())))
    q = int(input())
    for x in sys.stdin.readlines():
        b, c = map(int, x.split())
        a = [c if i == b else i for i in a]
        print(np.sum(a))

main()

### FIXED CODE ###

import sys
import collections
def main():
    n = int(input())
    a = collections.Counter(list(map(int, input().split())))
    s = [0 for i in range(10**5+1)]
    sa = 0
    for i in a:
        s[i] += a[i]
        sa += i*a[i]
    q = int(input())
    for x in sys.stdin.readlines():
        b, c = map(int, x.split())
        s[c] += s[b]
        sa = sa + c*s[b] - b*s[b]
        s[b] = 0
        print(sa)

main()
### BUGGY CODE ###

n = int(input())
aN = list(map(int, input().split()))
sum_board = 0
for i in range(1,n):
    if aN[i] < max(aN[:i]):
        sum_board +=  max(aN[:i]) - aN[i]

print(sum_board)

### FIXED CODE ###

n = int(input())
aN = list(map(int, input().split()))
sum_board = 0
aN_max = aN[0]
for i in range(1,n):
    if aN[i] < aN_max:
        sum_board +=  aN_max - aN[i]
    else:
        aN_max = aN[i]

print(sum_board)
### BUGGY CODE ###

mod = 10**9+7

def combi(m,n):
    child = 1
    mom = 1
    while n != 0:
        child *= m
        child %= mod
        mom *= n
        mom %= mod
        m -= 1
        n -= 1
    return (child*modpow(mom,mod-2))%mod

def bi(x):
    o = []
    while x != 0:
        o.append(x%2)
        x //= 2
    return o

def modpow(m,n):
    o = bi(n)
    p = [m]
    leo = len(o)
    while leo > len(p):
        a = p[-1]
        p.append(a*a%mod)
    b = 1
    for i in range(leo):
        if o[i] == 1:
            b *= p[i]
            b %= mod
    return b

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

A = (-1) * X +   2  * Y
B =   2  * X + (-1) * Y

if A % 3 or B % 3:
    print(0)
    exit()

A //= 3
B //= 3

print(combi(A+B,min(A,B)))

### FIXED CODE ###

mod = 10**9+7

FRAC_RANGE = 2000000
frac = [1] * FRAC_RANGE

for i in range(2,FRAC_RANGE):
    frac[i] = frac[i-1] * i % mod

def combi(n,k):
    a = frac[n]
    b = modpow(frac[k],mod-2)
    c = modpow(frac[n-k],mod-2)
    return a*b*c%mod

def bi(x):
    o = []
    while x != 0:
        o.append(x%2)
        x //= 2
    return o

def modpow(m,n):
    o = bi(n)
    p = [m]
    leo = len(o)
    while leo > len(p):
        a = p[-1]
        p.append(a*a%mod)
    b = 1
    for i in range(leo):
        if o[i] == 1:
            b *= p[i]
            b %= mod
    return b

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

A = (-1) * X +   2  * Y
B =   2  * X + (-1) * Y

if A % 3 or B % 3 or A < 0 or B < 0:
    print(0)
    exit()

A //= 3
B //= 3

print(combi(A+B,min(A,B)))
### BUGGY CODE ###

n = int(input())
ans=1
for i in range(1,n+1):
  ans*=i
print(ans%(10**9+7))

### FIXED CODE ###

n = int(input())
ans=1
for i in range(1,n+1):
  ans*=i
  ans=ans%(10**9+7)
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3

def main():
    import sys
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    A_temp=[0]*N
    for k in range(K):
        for i in range(N):
            for j in range(max(0,i-A[i]),min(N,i+A[i]+1)):
                A_temp[j]+=1
        A=A_temp
        A_temp=[0]*N
    print(' '.join(map(str,A)))
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    for k in range(K):
        A_temp=[0]*(N+1)
        for i in range(N):
            A_temp[max(0,i-A[i])]+=1
            if i+A[i]+1<=N-1:
                A_temp[i+A[i]+1]-=1
            
        A[0]=A_temp[0]
        for j in range(1,N):
            A_temp[j]+=A_temp[j-1]
            A[j]=A_temp[j]
        for ai in A:
            if ai != N:
                break
        else:
            break
                
    print(' '.join([str(a) for a in A]))
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
A = [1]+list(map(int,input().split()))

for i in range(1,N+1):
  A[i] = A[i-1]*A[i]

for i in range(K+1, N+1):
  prev = A[i-1] // A[i-K-1]
  now = A[i] // A[i-K]
  if now > prev:
    print('Yes')
  else:
    print("No")

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))

for i in range(K, N):
  if A[i] > A[i-K]:
    print('Yes')
  else:
    print("No")
### BUGGY CODE ###

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()
A.sort()

def check(m):
    C = [0] * N
    for i in range(N):
        C[i] = m // B[i]
    C.sort()
    res = 0
    for i in range(N):
        res += max(A[i] - C[i], 0)
    return res <= K

res = bisearch_min(-1, INF, check)
print(res)


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

N, K = MAP()
A = LIST()
B = LIST()

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

def check(m):
    k = 0
    for i, a in enumerate(A):
        b = B[i]
        k += max(ceil(a - m/b), 0)
        if k > K:
            return False
    return True

print(bisearch_min(-1, INF, check))
### BUGGY CODE ###

K, S = map(int,input().split())
cnt = 0
for X in range(0, K + 1):
    for Y in range(0, K + 1):
        for Z in range(0, K + 1):
            if X + Y + Z == S:
                cnt += 1
print(cnt)

### FIXED CODE ###

K, S = map(int,input().split())
cnt = 0
for X in range(0, K + 1):
    for Y in range(0, K + 1):
        if 0 <= S - X - Y <= K:
            cnt += 1
print(cnt)
### BUGGY CODE ###


def solve():
    i = L//2019
    ans = 0
    is_ok = False
    if 2019*i < L and R < 2019*i:
        is_ok = True
#    print(i)
    if is_ok:
        print(ans)
    else:
        ans = 2020
        for n in range(L,R):
            for m in range(n+1,R+1):
                ans = min(ans, (n*m)%2019)
            if ans == 0:
                break
        print(ans)

if __name__ == "__main__":
    L,R = list(map(int, input().split()))
    solve()


### FIXED CODE ###


def solve():
    i = (L//2019) + 1
    ans = 0
    if L <= 2019*i <= R:
        print(ans)
    else:
        ans = 2020
        for n in range(L,R):
            for m in range(n+1,R+1):
                ans = min(ans, (n*m)%2019)
            if ans == 0:
                break
        print(ans)

if __name__ == "__main__":
    L,R = list(map(int, input().split()))
    solve()
### BUGGY CODE ###

import os
import math

def main():
	n,m = map(int, input().split())
	a_list = list(map(int, input().split()))
	a_list.sort(reverse=True)
	
	for i in range(m):
		max_num = a_list[0]
		a_list[0] = math.floor(max_num/(2))
		a_list.sort(reverse=True)
	print(sum(a_list))
		

if __name__ == "__main__":
	main()


### FIXED CODE ###

import os
import math
import heapq

def main():
	n,m = map(int, input().split())
	a_list = list(map(lambda x: int(x)*(-1), input().split()))
	heapq.heapify(a_list)
	
	for i in range(m):
		max_num = heapq.heappop(a_list)*(-1)
		heapq.heappush(a_list, (max_num//2)*(-1))

	print((-1)*sum(a_list))

		

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

N = int(input())
A = tuple(map(int,input().split()))
L = [[int(A[i]^A[i+j] == A[i]+A[i+j]) for i in range(N-j)] for j in range(1,N)]
R = N
for i in range(N-1):
    if not L[0][i]:
        try:
            for k in range(1,N-1):
                L[k][i] = 0
        except:
            pass
        else:
            break

    for j in range(1,N-1):
        try:
            L[j][i] = L[j][i] and L[j-1][i+1]
            if not L[j][i]:
                for k in range(j,N-1):
                    L[k][i] = 0
                break
        except IndexError:
            break
for i in L:
    a = sum(i)
    if a == 0:
        break
    R += a
print(R)

### FIXED CODE ###

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

result = 0
Right = 0
tmp = 0
for left in range(N):
    for right in range(Right,N):
        if not (tmp & A[right]):
            tmp += A[right]
            Right = right + 1
        else:
            break
    tmp -= A[left]
    result += Right - left
print(result)
### BUGGY CODE ###

N = int(input())
List = []
A = ''
for i in range(0,N):
    A = input()
    if A not in List:
        List += [A]
print(len(List))

### FIXED CODE ###

N = int(input())
List = []
for i in range(0,N):
    List += [input()]
print(len(set(List)))
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
count=0
for i in range(a,b+1):
    if i%c!=0 and i%d !=0:
            count+=1
print(count)

### FIXED CODE ###

import fractions
a,b,c,d=map(int,input().split())
cd=int(c*d/(fractions.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
X = int(input())

sumX = []
sum = 0
for i in range(1,X+1):
    sum += i
    sumX.append(sum)

# print(sumX)

for i in range(X):
    j = X - i 
    if X > sumX[j-1]:
        print(j+1)
        exit()

print(1)


### FIXED CODE ###

# -*- coding: utf-8 -*-
X = int(input())

# sumX = []
sum = 0
for i in range(1,X+1):
    sum += i
    # print("sum=",sum)
    if sum >= X:
        print(i)
        # print("i=", i)
        break
### BUGGY CODE ###

import copy
n =int(input())
a=[]
b=[]
c=[]
a =list(map(int,input().split()))
a.sort()
b =list(map(int,input().split()))
b.sort()
c =list(map(int,input().split()))

c.sort()
c2 = copy.copy(c)
b_limit = 0
c_limit =0
count =0
c_count =0
b_score =[0]*n
for i in a:
    c_count =0
    c = copy.copy(c2)
    if b_limit == 1:
        break
    for j in  reversed(range(len(b))):
        if b[j] <= i:
            if b[j] == max(b):
                b_limit +=1
            break
        else:
            if not b_score[j] == 0:
                count += b_score
                continue
            if len(c) ==0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] == c_count
                continue
        for k in reversed(range(len(c))):
            if c[k] <= b[j]:
                count += c_count
                if b_score[j] ==0:
                    b_score[j] == c_count
                break
            c.pop(k)
            c_count +=1
            if k == 0:
                count +=c_count
                if b_score[j] ==0:
                    b_score[j] == c_count


print(count)



### FIXED CODE ###

import bisect

ans =0

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

for i in b:
    s = bisect.bisect_right(c,i)
    s_num = n-s

    t = bisect.bisect_left(a,i)
    t_num = t

    ans += s_num * t_num

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

import copy
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    ls.append(a) 
    
for i in range(len(ls)):
    ls2 = copy.copy(ls)
    del ls2[i]
    print(max(ls2))
    

### FIXED CODE ###

import copy
n = int(input())
ls = []
for i in range(n):
    a = int(input())
    ls.append(a) 
ls2 = copy.copy(ls)
ls.sort()
max1 = ls[-1]
max2 = ls[-2]


for i in ls2:
    if i != max1:
        print(max1)
    else:
        print(max2)
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split(" ")))
s = 1
for i in range(1,N):
    P_S = sorted(P[:i], reverse=True)
    if P_S[i-1] >= P[i]:
        s+=1
    else:
        continue

print(s)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split(" ")))
cnt = 0
S = P[0]
for i in range(N):
    if S >= P[i]:
        cnt += 1
    S = min(S, P[i])

print(cnt)
### BUGGY CODE ###

N=int(input())

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

ans=1
for a in A:
    ans=ans*a
    if ans > 10**18:
        ans=-1
        
if ans<0:
    ans=-1
        
print(ans)

### FIXED CODE ###

N=int(input())

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

ans=1
if 0 in A:
    ans=0
else:
    for a in A:
        ans=ans*a
        if ans > 10**18:
            ans=-1
            break

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

n = int(input())
inp = list(map(int,input().split()))
d = {}
for x in inp:
    d[x] = d.get(x, 0) + 1
v = [0 for _ in range(n+1)]
for x, y in d.items():
    v[x] = (y)*(y-1)//2
for i in range(n):
    print(sum(v)-v[inp[i]]+((d[inp[i]]-1)*(d[inp[i]]-2)//2))

### FIXED CODE ###

n = int(input())
inp = list(map(int,input().split()))
d = {}
for x in inp:
    d[x] = d.get(x, 0) + 1
v = [0 for _ in range(n+1)]
for x, y in d.items():
    v[x] = (y)*(y-1)//2
tot = sum(v)
for i in range(n):
    print(tot-v[inp[i]]+((d[inp[i]]-1)*(d[inp[i]]-2)//2))
### BUGGY CODE ###

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

def main():
    for i in range(N+1):
        for j in range(N+1):
            for k in range(N+1):
                if i*10000+j*5000+k*1000==Y:
                    if i+j+k==N:
                        return i,j,k
    return -1,-1,-1
ans=main()
print(ans[0],ans[1],ans[2])

### FIXED CODE ###

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

for i in range(N+1):
    for j in range(N-i+1):
        k=N-i-j
        if i*10000+j*5000+k*1000==Y:
            print(i,j,k)
            exit()
print(-1,-1,-1)
### BUGGY CODE ###

import sys
from itertools import combinations

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split(" ")))

    mod = 10**9+7
    res = 0
    before = 0
    for i, j in combinations(A, 2):
        res += i * j
    print(res % mod)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
 
def main():
    def input():return sys.stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split(" ")))
 
    mod = 10**9+7
    res = 0

    S = sum(A)
    S2 = sum(map(lambda x: x**2, A))
    print((S**2-S2) // 2 % mod)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

N = int(input())
A = [0]*N
for i in range(N):
    A[i] = int(input())

for i in range(N):
    B = A[:i] + A[i+1:]
    print(max(B))


### FIXED CODE ###

N = int(input())
A = [0]*N

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

B = sorted(A,reverse=True)

for i in range(N):
    if A[i]==B[0]:
        print(B[1])
    else:
        print(B[0])
### BUGGY CODE ###

x = raw_input()

w,h = [int(i) for i in x.split()]

p = []
for i in range(w):
    p.append(input())

q = []
for i in range(h):
    q.append(input())


cost = 0
p.sort()
q.sort()

iter = w+h


for i in range(iter):

    if(len(p)==0):
        cost += q[0]*(w+1)
        h -= 0
        q.pop(0)

    elif(len(q)==0):
        cost += p[0]*(h+1)
        w -= 0
        p.pop(0)

    elif(p[0]==q[0] and h>w):
        cost += p[0]*(h+1)
#        print cost,w,h
        w -= 1
        p.pop(0)

    elif(p[0]<q[0]):
        cost += p[0]*(h+1)
 #       print cost,w,h
        w -= 1
        p.pop(0)
    
    else:
        cost += q[0]*(w+1)
  #      print cost,w,h
        h -= 1
        q.pop(0)
    

print cost

### FIXED CODE ###

x = raw_input()
w,h = [int(i) for i in x.split()]
p = []
for i in range(w):
    p.append(input())
q = []
for i in range(h):
    q.append(input())
cost = 0
p.sort()
q.sort()
iter = w+h

p_iter = 0
q_iter = 0
for i in range(iter):
    if(w==0):
        cost += q[q_iter]*(w+1)
        h -= 0
        q_iter += 1

    elif(h==0):
        cost += p[p_iter]*(h+1)
        w -= 0
        p_iter += 1

    elif(p[p_iter]==q[q_iter] and h>w):
        cost += p[p_iter]*(h+1)
        w -= 1
        p_iter += 1

    elif(p[p_iter]<q[q_iter]):
        cost += p[p_iter]*(h+1)
        w -= 1
        p_iter += 1
    
    else:
        cost += q[q_iter]*(w+1)
        h -= 1
        q_iter += 1
    
print cost
### BUGGY CODE ###

MOD = 998244353

n, s = map(int, input().split())
As = list(map(int, input().split()))

dp = [0] * (s+2)

dp[0] = 1

for a in As:
    for i in range(s+1, -1, -1):
        if i - a < 0:continue
        dp[i] += dp[i-a] * (MOD+1) // 2
        dp[i] %= MOD

print(dp[s] * pow(2, n, MOD) % MOD)

### FIXED CODE ###

MOD = 998244353

n, s = map(int, input().split())
As = list(map(int, input().split()))

dp = [0] * (s+2)

dp[0] = 1

for a in As:
    for i in range(s+1, -1, -1):
        if i - a < 0:continue
        dp[i] += dp[i-a] * (MOD+1) // 2
        dp[i] %= MOD

print(dp[s] * pow(2, n, MOD) % MOD)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import math
def print_ans(N,H):
    """Test Case
    >>> print_ans(5, "10 4 8 7 3")
    2
    >>> print_ans(7, "4 4 5 6 6 5 5")
    3
    >>> print_ans(4, "1 2 3 4")
    0
    """
    h_arr = list(map(int,H.split()))
    ans_arr = []
    for i in range(N):
        tmp = h_arr[i]
        tmp_ans = 0
        for k in range(i + 1, N):
            if tmp >= h_arr[k]:
               tmp_ans += 1
               tmp = h_arr[k]
            else:
                break
        ans_arr.append(tmp_ans)
    print(max(ans_arr))
            


if __name__ == '__main__':
    N = int(input().rstrip())
    H = input().rstrip()
    print_ans(N,H)

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math
def print_ans(N,H):
    """Test Case
    >>> print_ans(5, "10 4 8 7 3")
    2
    >>> print_ans(7, "4 4 5 6 6 5 5")
    3
    >>> print_ans(4, "1 2 3 4")
    0
    """
    h_arr = list(map(int,H.split()))
    ans = 0
    ofs = 0
    for i in range(N):
        if ofs == i:
            tmp = h_arr[i]
            tmp_ans = 0
            for k in range(i + 1, N):
                ofs += 1
                if tmp >= h_arr[k]:
                    tmp_ans += 1
                    tmp = h_arr[k]
                else:
                    break
            ans = max(ans,tmp_ans)
    print(ans)
            


if __name__ == '__main__':
    N = int(input().rstrip())
    H = input().rstrip()
    print_ans(N,H)
### BUGGY CODE ###

import math

a,b,n=map(int,input().split(' '))
ans=0
for x in range(1,n+1):
    q=math.trunc(a*x/b)-a*math.trunc(x/b)
    if ans<q:
        ans=q
print(int(ans))

### FIXED CODE ###

import math

a,b,n=map(int,input().split(' '))
ans=0
x=min(n,b-1)
q=math.trunc(a*x/b)-a*math.trunc(x/b)
if ans<q:
    ans=q
print(int(ans))
### BUGGY CODE ###

n = int(input())
P = list(map(int,input().split()))
ans = 0
P = [float('inf')]+P
for i in range(1,n+1):
    if min(P[0:i]) >= P[i]:
        ans += 1
        #print(P[0:i])
print(ans)


### FIXED CODE ###

n = int(input())
l = list(map(int,input().split()))
ans = 0
tmpmin = l[0]
for i in range(n):
    if l[i] <= tmpmin:
        ans += 1
    tmpmin = min(tmpmin,l[i])
print(ans)
### BUGGY CODE ###

from collections import deque
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

    def get_nodes(self):
        return self.graph.keys()

G = Graph()

N, Q = getlist()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a, b)
	G.add_edge(b, a)

plus = [0 for i in range(N + 1)]
for i in range(Q):
	p, x = getlist()
	plus[p] += x

#幅優先
q = deque([]) 
val = 0
ans = [0 for i in range(N + 1)]
visit = [-1 for i in range(N + 1)]
visit[1] = 1
q.append(1)
while q:
	m = q.pop()
	ans[m] += plus[m]
	visit[m] = 1
	for i in G.graph[m]:
		if visit[i] == -1:
			q.append(i)
			ans[i] += ans[m]

ans2 = []
for i in range(N):
	ans2.append(ans[i + 1])

print(" ".join(list(map(str, ans2))))

### FIXED CODE ###

from collections import deque
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, a, b):
        self.graph[a].append(b)

G = Graph()

N, Q = getlist()
for i in range(N - 1):
	a, b = getlist()
	G.add_edge(a, b)
	G.add_edge(b, a)

plus = [0] * (N + 1)
for i in range(Q):
	p, x = getlist()
	plus[p] += x

q = deque([]) 
ans = [0] * N
visit = [-1] * (N + 1)
visit[1] = 1
q.append(1)
while q:
	m = q.pop()
	visit[m] = 1
	ans[m - 1] += plus[m]
	x = ans[m - 1]
	for i in G.graph[m]:
		if visit[i] == -1:
			q.append(i)
			ans[i - 1] += x

print(" ".join(list(map(str, ans))))
### BUGGY CODE ###

N = int(input())

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

X = [0]*N

for i in range(N):
    for j in range(N):
        if j+i < N:
            tmp_A = (-1)**(j+i)*A[j+i]
        else:
            tmp_A = (-1)**(j+i)*A[j+i-N]
        X[i] += tmp_A
    if i % 2 != 0:
        X[i] *= -1
print(" ".join(map(str, X)))

### FIXED CODE ###

N = int(input())

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

X = [0]*N

for i in range(N):
    X[0] += (-1)**(i)*A[i]

for j in range(0,N-1):
    X[j+1] = 2 * (A[j] - int(X[j]/2))

print(" ".join(map(str, X)))
### BUGGY CODE ###

n = int(input())
t = list(map(int, input().strip().split()))

r = 1
for tt in t:
    r *= tt

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

### FIXED CODE ###

def main():
    n = int(input())
    t = list(map(int, input().strip().split()))

    r = 1
    if 0 in t:
        print(0)
        return

    for tt in t:
        r *= tt
        if r > 10**18:
            print(-1)
            return

    print(r)

main()
### BUGGY CODE ###

import sys
import math
import numpy as np
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    s = L()
    cnt = 0
    def f(x):
        tgt = [x[0],x[1],x[2]]
        now = 0
        global n
        for i in range(n):
            if s[i] == tgt[now]:now += 1
            if now == 3:return True
        return False
    for i in range(1000):
        if len(str(i)) == 1:
            t = "00"+str(i)
        elif len(str(i)) == 2:
            t = "0"+str(i)
        else:t = str(i)
        if f(t):cnt += 1
    print(cnt)

### FIXED CODE ###

if __name__ == "__main__":
    n = int(input())
    s = list(input())
    cnt = 0
    def f(x):
        tgt = [x[0],x[1],x[2]]
        now = 0
        global n
        for i in range(n):
            if s[i] == tgt[now]:now += 1
            if now == 3:return True
        return False
    for i in range(1000):
        if len(str(i)) == 1:
            t = "00"+str(i)
        elif len(str(i)) == 2:
            t = "0"+str(i)
        else:t = str(i)
        if f(t):cnt += 1
    print(cnt)