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

import sys
import numpy as np

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(n):
        ans += (np.sum(A[i + 1:]) * A[i]) % mod
        ans %= mod
    print(int(ans))


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    A = nl()
    mod = 10 ** 9 + 7
    s = sum(A)
    q = sum([a ** 2 for a in A])
    ans = (((s * s) - q)) // 2
    print(int(ans % mod))


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

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

value = 1

ac = [P[i] for i in range(1, N) if P[i] <= min(P[:i])]

value += len(ac)

print(value)


### FIXED CODE ###

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

value = 10 ** 9
ans = 0
for v in P:
    if v < value:
        ans += 1
        value = v
print(ans)
### BUGGY CODE ###

from collections import Counter
N = int(input())
S =[]
for i in range(N):
    S.append(sorted(list(Counter(str(input())).items()),reverse = False))
#print(S)

cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i] == S[j]:
            cnt += 1
print(cnt)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = [list((map(str,input().split()))) for _ in range(N)]

A = []
for i in S:
    ew_str = ''.join(sorted(i[-1]))
    A.append(ew_str)

cnt = Counter(A)
cnt = list(cnt.values())
#print(cou)

ans = 0
for i in cnt:
    ans +=i*(i-1)//2
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3 ## -*- python -*-

s = input()
q = int(input())

for i in range(q):
    d = input()
    if d[:1] == "1":
        s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)

### FIXED CODE ###

#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()
### BUGGY CODE ###

n=int(input())
c=1
f=1
a=list(map(int,input().split()))
for i in range(0,n):
  if a[i]==0:
    f=1
    c=0
    break
  if c*a[i]>1e18 or f==0:
    c*=a[i]
    f=0
    continue
  c*=a[i]
if f==0: print(-1)
else: print(c)

### FIXED CODE ###

n=int(input())
c=1
f=1
a=list(map(int,input().split()))
for i in range(0,n):
  if a[i]==0:
    f=1
    c=0
    break
  if f==0: continue
  if c*a[i]>1e18:
    c*=a[i]
    f=0
    continue
  c*=a[i]
if f==0: print(-1)
else: print(c)
### BUGGY CODE ###

a = int(input())
array = list(map(int, input().strip().split()))
out = 0
for i in range(a):
    out = out + 1 if array[i] == min(array[0:i+1]) else out
print(out)

### FIXED CODE ###

a = int(input())
array = list(map(int, input().strip().split()))
out = 0
min_num = array[0]
for i in array:
    min_num = min(min_num, i)
    out = out + 1 if i == min_num else out
print(out)
### BUGGY CODE ###

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

for i in range(N):
    for j in range(i+1,N):
        if A[i] == A[j]:
            print("NO")
            exit()
print("YES")

### FIXED CODE ###

from collections import Counter
N = int(input())
A = list(map(int,input().split()))

count = Counter(A)
memo = []

for v in count.values():
  if v >= 2:
    print("NO")
    exit()
else:
  print("YES")
### BUGGY CODE ###

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

for i in range(N):
    print(A.count(i+1))

### FIXED CODE ###

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

count = 0
buka = [0 for _ in range(N)]

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

for k in range(N):
    print(buka[k])
### BUGGY CODE ###

n,k,*h=map(int,open(0).read().split())
dp = [0]*n
for i in range(1,n):
  lst = [dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i)]
  dp[i] = min(lst)
print(dp[-1])

### FIXED CODE ###

N,K = map(int,input().split())
H = [int(x) for x in input().split()]
 
def main(N,K,H):
    dp = [0]*N
    for i in range(1,N):
        L = [dp[j]+abs(H[i]-H[j]) for j in range(max(0,i-K),i)]
        dp[i] = min(L)
    print(dp[-1])
main(N,K,H)
#自分のコードがTLEになるので、他の人が書いたコードでAC出来るのか確認。
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
end = A[-1] * F[0] + 1
start = -1


def decision(n):
    k = K
    for a, f in zip(A, F):
        while a * f > n:
            a -= 1
            k -= 1
            if k < 0:
                return False
    return True

def calc():
    e = end
    s = start
    while e - s > 1:
        mid = (e + s)//2
        if decision(mid):
            e = mid
        else:
            s = mid
    return e


print(calc())




### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)
end = A[-1] * F[0] + 1
start = -1


def decision(n):
    k = K
    for a, f in zip(A, F):
        if a * f > n:
            k -= a - n // f
        if k < 0:
            return False
    return True

def calc():
    e = end
    s = start
    while e - s > 1:
        mid = (e + s)//2
        if decision(mid):
            e = mid
        else:
            s = mid
    return e


print(calc())
### 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())
uf = UnionFind(n)
for i in range(m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  uf.union(a,b)
  
ans = 0
for v in uf.all_group_members().values():
  ans = max(ans, len(v))

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())
  a -= 1
  b -= 1
  uf.union(a,b)
  
ans = 0
for i in range(n):
  ans = max(uf.size(i), ans)

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

import sys
import string
 
alphabets=list(string.ascii_lowercase)
 
s=input()
 
l=len(s)
 
hm = lambda a,string: sum([x==a for x in string])
 
for x in range(l-1):
  if s[x]==s[x+1]:
    print('{} {}'.format(x+1, x+2))
    sys.exit()
 
def func(r,s,n,m):
  if r==26:
    return
  else:
    if hm(alphabets[r],s[n:n+m])>m//2:
      print('{} {}'.format(n+1,n+m))
      sys.exit()
    return func(r+1,s,n,m)
 
for m in range(3,l,2):
  for n in range(l-m):
    func(0,s,n,m)
print('-1 -1')

### FIXED CODE ###

import sys
import string
 
alphabets=list(string.ascii_lowercase)
 
s=input()
 
l=len(s)
 
hm = lambda a,string: sum([x==a for x in string])
 
for x in range(l-1):
  if s[x]==s[x+1]:
    print('{} {}'.format(x+1, x+2))
    sys.exit()
 
 
for n in range(l-3):
  for a in alphabets:
    if hm(a,s[n:n+3])> 1:
      print('{} {}'.format(n+1,n+3))
      sys.exit()
print('-1 -1')
### BUGGY CODE ###

N = int(input())
Ps = list(map(int, input().split()))
count = 0
low = -1

for i in range(N):
    low = Ps[i]

    for j in range(i):
        if (low > Ps[j]):
            break
        if (low > Ps[i-1-j]):
            break
        if (j == i-1):
            count += 1

print(count+1)

### FIXED CODE ###

N = int(input())
Ps = list(map(int, input().split()))
count = 0
min = Ps[0]+1

for i in range(N):
    if (Ps[i] < min):
        min = Ps[i]
        count += 1

print(count)
### BUGGY CODE ###

from collections import defaultdict

S = tuple(map(int, list(input())))
MOD = 2019
dp = [defaultdict(int) for _ in range(len(S) + 1)]
for i in range(len(S)):
    dp[i + 1][S[i]] += 1
    for j in range(MOD):
        dp[i + 1][(j * 10 + S[i]) % MOD] += dp[i][j]

print(sum(dp[i][0] for i in range(len(S) + 1)))

### FIXED CODE ###

from collections import defaultdict

S = tuple(map(int, list(input())))
MOD = 2019

d = defaultdict(int)
d[0] = 1

tmp = 0
for i, s in enumerate(reversed(S)):
    tmp = (tmp + s * pow(10, i, MOD)) % MOD
    d[tmp] += 1
print(sum(v * (v - 1) // 2 for v in d.values()))
### BUGGY CODE ###

n=int(input())
P=list(map(int,input().split()))
ans=n

for i in range(n):
    for j in range(i):
        if P[i]>P[j]:
            ans-=1
            break
print(ans)

### FIXED CODE ###

n=int(input())
P=list(map(int,input().split()))
ans=0
M=P[0]
for i in range(n):
    if M>=P[i]:
        ans+=1
        M=P[i]
print(ans)
### BUGGY CODE ###

N = int(input())
a = [int(input()) for x in range(N)]

cnt = 0
for i in range(N) :
    cnt += 1
    if a[i] == 2 :
        continue
    else :
        for j in range(2, a[i]) :
            if a[i] % j == 0:
                cnt -= 1
                break
            
print(cnt)


### FIXED CODE ###

N = int(input())
a = [int(input()) for x in range(N)]

import math

cnt = 0
for i in range(N) :
    cnt += 1
    if a[i] == 2 :
        continue
    else :
        for j in range(2, int(math.sqrt(a[i])) + 1) :
            if a[i] % 2 == 0 :
                cnt -= 1
                break
            if a[i] % j == 0 :
                cnt -= 1
                break
            
print(cnt)
### BUGGY CODE ###

N = int(input())
P = list(map(int,input().split()))
List = []
ans = 0
for i in range(N):
  if(i == 0):
    ans += 1
  else:
    tmp = P[i-1]
    List.append(tmp)
    if(P[i] <= min(List)):
      ans += 1
print(str(ans))

### FIXED CODE ###

N = int(input())
P = list(map(int,input().split()))
mi = P[0]
ans = 0
for i in range(N):
  if(i == 0):
    ans += 1
  else:
    if(P[i] <= mi):
      ans += 1
      mi = P[i]
print(str(ans))
### BUGGY CODE ###

N, K = map(int,input().split())
moves = []

mod = 998244353

for _ in range(K):
    L, R = map(int,input().split())
    for d in range(L, R+1):
        moves.append(d)
    # moves.add((L, R))
moves.sort()

dp = [0] * (N + 1)
dp[1] = 1
# for dis in moves:
#     dp[dis] = 1
# print(moves)

for n in range(1, N+1):
    for dis in moves:
        if n - dis >= 1:
            dp[n] += dp[n - dis]
        else:
            break

# print(dp)
print(dp[N] % mod)


### FIXED CODE ###

n, k = map(int, input().split())
sec = [list(map(int, input().split())) for _ in range(k)]
sec.sort()
    
mod = 998244353
    
dp = [0] * n
dp[0] = 1
sum_dp = [0, 1]
for i in range(1, n):
    for l, r in sec:
        if i - l < 0:
            break
        elif i - r > 0:
            dp[i] = ((dp[i] + sum_dp[i-l+1]) % mod - sum_dp[i-r]) % mod
        else:
            dp[i] = (dp[i] + sum_dp[i-l+1]) % mod
    
    sum_dp.append((sum_dp[-1] + dp[i]) % mod)
    
print(dp[n-1])
### BUGGY CODE ###

K,S = map(int, input().split())

ans = 0
for x in range(K+1):
  for y in range(K+1):
    for z in range(K+1):
      if x+y+z == S:
        ans +=1
      elif x+y+z >S:
        break
    if x+y >S:
      break

print(ans)

### FIXED CODE ###

K,S = map(int, input().split())

ans = 0
if K*3<S:
  print(0)
  exit()

for x in range(K, -1, -1):
  if x >S:
    continue
  for y in range(min(S-x, K), -1, -1):
    if x+y >S:
      continue
    for z in range(min(S-x-y, K), -1, -1):
      if x+y+z==S:
        ans+=1
      elif x+y+z<S:
        break

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

import numpy as np
N = int(input())
A = list(map(int,input().split()))

mi = min(A)

def mak(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
    
P = mak(mi)[1:][::-1]
lenp = len(P)

Q = np.array(A)

an = 1
for i in range(lenp):
    R = Q % P[i]
    if any(R) == 0:
        an = P[i]
        break
    else:
        Q = R

print(an)

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int,input().split()))
flag = 0
#mi = min(A)
Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return flag, an, R1
    else:
        flag = 0
        an = 1
        ind = np.argmin(Q)
        R1[ind] = mi
        R = R1[R1!=0]
        return flag, an, R

while flag == 0:
    flag,an,PP = toku(Q)
    Q = PP

print(an)
### BUGGY CODE ###

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
a = primes(100000)
resemble = []
for i in a:
    if i == 2 or (i+1)//2 not in a:
        pass
    else:
        resemble.append(i)
n = int(input())
ans = [0]*100000
q =[]
for i in range(1,100001):
    if i in resemble:
        ans[i-1] = ans[i-2] + 1
    elif i>1:
        ans[i-1] = ans[i-2]
#print(ans[:30])
for i in range(n):
    l,r = map(int,input().split())
    if l>1:
        q.append(ans[r-1]-ans[l-2])
    elif r>1:
        q.append(ans[r-1])
    else:
        q.append(0)
for i in range(n):
    print(q[i])

### FIXED CODE ###

import sys
input = sys.stdin.readline

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime
a = primes(100000)
resemble = []
for i in range(len(a)):
    if a[i]:
        if a[(i+1)//2]:
            resemble.append(i)
n = int(input())
ans = [0]*100000
q =[]
for i in range(1,100001):
    if i in resemble:
        ans[i-1] = ans[i-2] + 1
    elif i>1:
        ans[i-1] = ans[i-2]
#print(ans[:30])
for i in range(n):
    l,r = map(int,input().split())
    if l>1:
        q.append(ans[r-1]-ans[l-2])
    elif r>1:
        q.append(ans[r-1])
    else:
        q.append(0)
for i in range(n):
    print(q[i])
### BUGGY CODE ###

N = int(input())
S = [s for s in input()]

array = []
for s in set(S):
    array.append(S.count(s))

len_array = len(array)

def recall(cur,t=1,total=0):
    if cur==len_array:
        return t
    for i in [array[cur],1]:
        total += recall(cur+1,t*i)
    return total

print((recall(0)-1)%(10**9+7))

### FIXED CODE ###

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

mod = 10**9 + 7
alphabet = [chr(i) for i in range(97,97+26)]

ans = 1
for letter in alphabet:
    ans *= S.count(letter) + 1
    ans =  ans%mod
ans -= 1

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

L,R = (int(x) for x in input().split())
if R-L > 2019:
  L,R = L-L//2019*2019 , R-L//2019*2019
ans = 2019
for i in range(L,R):
  for j in range(i+1,R+1):
    ans = min(ans,(i*j)%2019)
print(ans)

### FIXED CODE ###

L,R = (int(x) for x in input().split())
if R-L > 2019*2:
  R -= ((R-L)//2019-1)*2019
ans = 2019
for i in range(L,R):
  for j in range(i+1,R+1):
    ans = min(ans,(i*j)%2019)
print(ans)
### BUGGY CODE ###

N,Q=map(int,input().split())
S=input()
s_cnt=[]
for i in range(N):
    s_cnt.append(S[:i+1].count("AC"))
#print(s_cnt)    
for i in range(Q):
    l,r=map(int,input().split())
    if l-2 < 0:
        print(s_cnt[r-1])
    else:    
        print(s_cnt[r-1] - s_cnt[l-1])

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
s_cnt=[]
cnt=0
for i in range(N-1):
    if S[i]=="A" and S[i+1]=="C":
        cnt+=1
        s_cnt.append(cnt)
    else:
        s_cnt.append(cnt)
for i in range(Q):
    l,r=map(int,input().split())
    l-=2
    r-=2
    if l<0:
        print(s_cnt[r])
    else:    
        print(s_cnt[r] - s_cnt[l])
### BUGGY CODE ###

#!/usr/bin/env python3
import collections

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

# calc
s2 = sorted(set(s))
times = []

for word in s2: 
    times.append(s.count(word)) 

maxtimes = max(times)
answords = []

for i in range(len(s2)):
    if maxtimes == times[i]:
        answords.append(s2[i])

answords = sorted(answords)
for word in answords:
    print(word)


### FIXED CODE ###

#!/usr/bin/env python3

n = int(input())
s = [input() for _ in range(n)]

d = {}
for i in s:
    if i in d.keys():
        d[i] += 1
    else:
        d[i] = 1 
ans = []
m = max(d.values())
for k, v in d.items():
    if v == m:
        ans.append(k)

for s in sorted(ans):
    print(s)
### BUGGY CODE ###

N, M =map(int, input().split())
Ps =[]
Ys =[]
dic = {}
for i in range(M):
    p, y = map(int, input().split())
    Ps.append(p)
    Ys.append(y)
    ls = dic.get(p, [])
    ls.append(y)
    ls.sort()
    dic[p] = ls
for i in range(M):
    p = Ps[i]
    y = Ys[i]
    number = dic[p].index(y) + 1
    strp = str(p)
    strn = str(number)
    print(strp.zfill(6) + strn.zfill(6))


### FIXED CODE ###

N, M =map(int, input().split())
ls = []
pcount =[]
for i in range(N):
    pcount.append(0)
for i in range(M):
    p, y = map(int, input().split())
    ls.append([i, p, y])
ls.sort(key = lambda x:x[2])

for l in ls:
    pcount[l[1]-1] += 1
    l.append(pcount[l[1]-1])
ls.sort(key = lambda x:x[0])
for l in ls:
    print(str(l[1]).zfill(6) + str(l[3]).zfill(6))
### BUGGY CODE ###

MOD = 10**9+7

def main():
    n = int(input())

    dp = [0] * (1 << n)
    for i in [i >> 1 for i, x in enumerate(input()) if x == '1']:
        dp[1 << i] = 1

    npow = 1 << n

    for i in range(n - 1):
        _dp = [0] * npow
        for j in [i >> 1 for i, x in enumerate(input()) if x == '1']:
            jpow = 1 << j
            for mask,val in enumerate(dp):
                if not mask & jpow:
                    _dp[mask + jpow] += val
        for mask in range(npow):
            _dp[mask] %= MOD
        dp = _dp

    print(sum(dp) % MOD)

main()

### FIXED CODE ###

range = xrange
input = raw_input
MOD = 10**9+7
 
n = int(input())

dp = [0] * (1 << n)
for i in [i for i, x in enumerate(input().split()) if x == '1']:
    dp[1 << i] = 1

npow = 1 << n

for i in range(n - 1):
    _dp = [0] * npow
    for j in [i for i, x in enumerate(input().split()) if x == '1']:
        jpow = 1 << j
        mask = 0
        while mask < npow:
            _dp[mask + jpow] += dp[mask]
            mask += 1 + ((mask+1) & jpow)
    for mask in range(npow):
        _dp[mask] %= MOD
    dp = _dp
 
print(sum(dp) % MOD)
### BUGGY CODE ###

s=input()
place=[]
for i in range(1,len(s)):
  if s[i]!=s[i-1]:
    place.append(i)
ans=[0 for i in range(len(s))]
cur_p=place[0]
cur_p_i=0
is_l=False
for i in range(len(s)):
  if i in place:
    if is_l:
      cur_p_i+=2
      cur_p=place[cur_p_i]
    is_l=not is_l
  if (i-cur_p)%2==0:
    ans[cur_p]+=1
  else:
    ans[cur_p-1]+=1
print(" ".join(map(str,ans)))


### FIXED CODE ###

s=input()
place=[]
for i in range(1,len(s)):
  if s[i]!=s[i-1]:
    place.append(i)
ans=[0 for i in range(len(s))]
cur_p=place[0]
cur_p_i=0
is_l=False
set_place=set(place)
for i in range(len(s)):
  if i in set_place:
    if is_l:
      cur_p_i+=2
      cur_p=place[cur_p_i]
    is_l=not is_l
  if (i-cur_p)%2==0:
    ans[cur_p]+=1
  else:
    ans[cur_p-1]+=1
print(" ".join(map(str,ans)))
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
    
K = int(input())

sum = 0
for a in range(K):
	for b in range(K):
		for c in range(K):
			sum += gcd(a+1, b+1, c+1)
print(sum)

### FIXED CODE ###

import math
    
K = int(input())

sum = 0
dict = {}
for a in range(K):
	for b in range(K):
		ab = math.gcd(a+1, b+1)
		if ab in dict:
			dict[ab] = dict[ab]+1 
		else:
			dict[ab] = 1
for c in range(K):
	for ab in dict:
		sum += math.gcd(ab, c+1)*dict[ab]
print(sum)
### BUGGY CODE ###

N, Q = map(int, input().split())
 
tree = [[i] for i in range(N+1)]
tree_parent = [[0] for i in range(N+1)]
points = [0] * N
 
for i in range(1, N):
  a, b = map(int, input().split())
  tree[a].append(b)
  tree_parent[b].append(a)  
  tree[tree_parent[a][-1]].append(b)
    
for i in range(Q):
  p, x = map(int, input().split())
  for node in tree[p]:
    points[node-1] += x
    
for point in points:
  print(point, end=" ")

### FIXED CODE ###

n,q = map(int,input().split())
rl = [0] * n
scores = [0] * n
for i in range(n-1):
    a,b = map(int,input().split())
    rl[b-1] = a-1
for j in range(q):
    p,x = map(int,input().split())
    scores[p-1] += x
for k in range(1,n):
    scores[k] += scores[rl[k]]
print(*scores)