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

n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
f=list(map(int,input().split()))
g=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
for b in range(64):
  e=1<<b
  u=[a&e for a in f]
  v=[a&e for a in g]
  l=[0]*n
  m=[0]*n
  for i in range(n):
    for j in range(n):
      if(u[i]&v[j])|((s[i]^1)*u[i])|((t[j]^1)*v[j]):ans[i][j]|=e;l[i]+=1;m[j]+=1
  for i in range(n):
    for j in range(n):
      if s[i]*u[i]*(l[i]==0)*(t[j]^1)*(n-m[j]>1):ans[i][j]|=e;l[i]+=1;m[j]+=1
      if t[j]*v[j]*(m[j]==0)*(s[i]^1)*(n-l[i]>1):ans[i][j]|=e;l[i]+=1;m[j]+=1
h=ans[0][:]
w=[i[0]for i in ans]
for i in range(n):
  for j in range(n):
    if s[i]:w[i]|=ans[i][j]
    else:w[i]&=ans[i][j]
    if t[j]:h[j]|=ans[i][j]
    else:h[j]&=ans[i][j]
if(g!=h)|(f!=w):print(-1);exit() 
for i in ans:print(*i)

### FIXED CODE ###

n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
ss=[u[i]if s[i]==0 else 0 for i in range(n)]
tt=[v[i]if t[i]==0 else 0 for i in range(n)]
son=[[]for _ in range(n)]
ton=[[]for _ in range(n)]
sno=[[n-1]*64 for _ in range(n)]
tno=[[n-1]*64 for _ in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=u[i]&v[j]
    if s[i]==0:
      ans[i][j]|=u[i]
      ss[i]&=ans[i][j]
    else:
      ss[i]|=ans[i][j]
    if t[j]==0:
      ans[i][j]|=v[j]
      tt[j]&=ans[i][j]
    else:
      tt[j]|=ans[i][j]
    if s[i]==0 or t[i]==0:
      for k in range(64):
        if ans[i][j]&1<<k:
          if s[i]==0:sno[i][k]-=1
          if t[j]==0:tno[j][k]-=1
    if j==n-1:
      if s[i]==1:
        if ss[i]|u[i]>u[i]:print(-1);exit()
        if ss[i]!=u[i]:
          for k in range(64):
            if u[i]&1<<k:
              if (ss[i]&1<<k)==0:
                son[i].append(k)
          ss[i]=1
        else:ss[i]=0
      else:
        if ss[i]!=u[i]:print(-1);exit()
        else:ss[i]=2
    if i==n-1:
      if t[j]==1:
        if tt[j]|v[j]>v[j]:print(-1);exit()
        if tt[j]!=v[j]:
          for k in range(64):
            if v[j]&1<<k:
              if (tt[j]&1<<k)==0:
                ton[j].append(k)
          tt[j]=1
        else:tt[j]=0
      else:
        if tt[j]!=v[j]:print(-1);exit()
        else:tt[j]=2
for i in range(n):
  for k in son[i]:
    for j in range(n):
      if t[j]==0:
        if tno[j][k]>0:
          ans[i][j]|=1<<k
          tno[j][k]-=1
          break
      if j==n-1:print(-1);exit()
for j in range(n):
  for k in ton[j]:
    for i in range(n):
      if s[i]==0:
        if sno[i][k]>0:
          ans[i][j]|=1<<k
          sno[i][k]-=1
          break
      if i==n-1:print(-1);exit()
for i in range(n):
  if s[i]==0:uu=ans[i][0]
  else:uu=0
  for j in range(n):
    if s[i]==0:uu&=ans[i][j]
    else:uu|=ans[i][j]
  if uu!=u[i]:print(-1);exit()
for j in range(n):
  if t[j]==0:vv=ans[0][j]
  else:vv=0
  for i in range(n):
    if t[j]==0:vv&=ans[i][j]
    else:vv|=ans[i][j]
  if vv!=v[j]:print(-1);exit()
for i in ans:print(*i)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
o=[0]*61
z=[0]*61
mod=10**9+7
ans=0
for i in range(n):
  x=a[i]
  for j in range(61):
    if x&1:o[j]+=1
    else:z[j]+=1
    x>>=1
x=1
for i in range(61):
  ans=(ans+(x*o[i]*z[i])%mod)%mod
  x=(x*2%mod)
print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
ans=0
x=1
for i in range(60):
  z=o=0
  for j in range(n):
    if a[j]%2:o+=1
    else:z+=1
    a[j]//=2
  ans+=(x*o*z)%mod
  ans%=mod
  x=(x*2)%mod
print(ans)
### BUGGY CODE ###

n = int(input())
answer = 0
for i in range(1, n):
	answer += i
print(answer)

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int):
    answer = (N-1)*N//2
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

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

MAX = 1005
n = int(input())
dp = [[0 for j in range(MAX)] for i in range(MAX)]
for _ in range(n):
    X = input()
    Y = input()
    len_X = len(X)
    len_Y = len(Y)

    for i in range(len_X):
        for j in range(len_Y):
            dp[i + 1][j + 1] = dp[i][j] + 1 if X[i] == Y[j] else max(dp[i][j + 1], dp[i + 1][j])
    print(dp[len_X][len_Y])

### FIXED CODE ###

for _ in range(int(input())):
    a = input()
    b = input()
    if len(a) < len(b):
        a, b = b, a
    indices = []
    for cb in b:
        bgn_idx = 0
        for i, cur_idx in enumerate(indices):
            chr_idx = a.find(cb, bgn_idx) + 1
            if not chr_idx:
                break
            if chr_idx < cur_idx:
                indices[i] = chr_idx
            bgn_idx = cur_idx
        else:
            chr_idx = a.find(cb, bgn_idx) + 1
            if chr_idx:
                indices.append(chr_idx)
    print(len(indices))
### BUGGY CODE ###

from sys import stdin
input = stdin.readline
(H,W,M) = map(int, input().split())
hsum = [0]*H
wsum = [0]*W
bombs = set()
for _ in range(M):
    h,w = map(int, input().split())
    hsum[h-1] += 1
    wsum[w-1] += 1
    bombs.add((h-1,w-1))

hmax = max(hsum)
wmax = max(wsum)

cross_w_zero = False
for h in range(H):
    if hsum[h] == hmax:
        for w in range(W):
            if wsum[w] == wmax and (h,w) not in bombs:
                cross_w_zero = True
                break
    if cross_w_zero:
        break
if cross_w_zero:
    print(hmax + wmax)
else:
    print(hmax + wmax - 1)

### FIXED CODE ###

# from sys import stdin
# input = stdin.readline
(H,W,M) = map(int, input().split())
hsum = [0]*H
wsum = [0]*W
bombs = set()
for _ in range(M):
    h,w = map(int, input().split())
    hsum[h-1] += 1
    wsum[w-1] += 1
    bombs.add((h-1,w-1))

hmax = max(hsum)
wmax = max(wsum)

cross_w_zero = False
hargmax = sum(1 for x in hsum if x == hmax)
wargmax = sum(1 for x in wsum if x == wmax)
cnt = sum(1 for h,w in bombs if hsum[h] == hmax and wsum[w] == wmax)
if hargmax * wargmax == cnt:
    print(hmax + wmax - 1)
else:
    print(hmax + wmax)
### BUGGY CODE ###

import itertools as it

def f(c):
    x = abs(sum([i[0] for i in c]))
    y = abs(sum([i[1] for i in c]))
    z = abs(sum([i[2] for i in c]))
    return x + y + z

N, M = tuple(map(int, input().split()))
v = [[int(x) for x in input().split()] for j in range(N)]
c = list(it.combinations(v, M))
print(max(f(x) for x in c))

### FIXED CODE ###

N, M = tuple(map(int, input().split()))
v = [[int(x) for x in input().split()] for j in range(N)]
v2 = [[v[i][0]*p + v[i][1]*q + v[i][2]*r for i in range(N)] for p in [1, -1] for q in [1, -1] for r in [1, -1]]
v3 = [sorted(v2[i], reverse=True) for i in range(8)]
m = 0
for i in range(8):
    n = sum(v3[i][:M])
    if n > m:
        m = n

print(m)
### BUGGY CODE ###

def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    if 10%p == 0:
        for i in range(n):
            if int(s[i])%p == 0:
                ans += i+1
        print(ans)
        return
    for i in range(n):
        v = int(s[i:])%p
        mu[i] = v
        c[v] += 1
    c[0] += 1
    for i in mu:
        c[i] -= 1
        ans += c[i]
        
    print(ans)
    

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    n, p = map(int, input().split())
    s = input()
    mu = [None]*n
    ans = 0
    c = [0]*p
    if 10%p == 0:
        ss = map(int, s)
        ss = list(ss)
        for i in range(n):
            if ss[i]%p == 0:
                ans += i+1
        print(ans)
        return
    sr = s[::-1]
    ssr = map(int, sr)
    tens = 1
    v = 0
    for i, si in enumerate(ssr):
        v = (v + (si%p)*tens)%p
        mu[i] = v
        c[v] += 1
        tens *= 10
        tens %= p
    c[0] += 1
    for i in c:
        if i:
            ans += ((i-1)*i)//2
        
    print(ans)
    

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

n=int(input())
l=[]
while(n!=0):
    l.append(n%10)
    n=n//10
    
if sum(l)%9==0:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

n=int(input())
if n%9==0:
  print("Yes")
else:
  print("No")
### BUGGY CODE ###

#解説AC
n=int(input())
a=list(map(int,input().split()))
dp=[[[-1]*(301) for i in range(301)] for j in range(301)]
# dp[a][b][c]=(1個の皿がa枚,2個の皿がb枚,3個の皿がc枚ある時, 全て食べ終わるまでの操作回数の期待値)
# dp[a][b][c]の遷移
#               確率          行先
# 1枚が引かれる  a/N　　　    dp[a-1][b][c]
# 2枚が引かれる  b/N　　　    dp[a+1][b-1][c]
# 3枚が引かれる  c/N　　　    dp[a][b+1][c-1]
# 0枚が引かれる  (N-a-b-c)/N　dp[a][b][c]

#dp[a][b][c]=dp[a-1][b][c]*a/n+dp[a+1][b-1][c]*b/n+dp[a][b+1][c-1]*c/n+dp[a][b][c]*(n-a-b-c)/n+1
#dp[a][b][c]=(dp[a-1][b][c]*a+dp[a+1][b-1][c]*b+dp[a][b+1][c-1]*c+n)/(a+b+c)

def memo(i,j,k):
    if dp[i][j][k]+1:
        return dp[i][j][k]
    ans=n
    if i>0:
        ans+=memo(i-1,j,k)*i
    if j>0:
        ans+=memo(i+1,j-1,k)*j
    if k>0:
        ans+=memo(i,j+1,k-1)*k
    dp[i][j][k]=ans/(i+j+k)
    return ans/(i+j+k)
dp[0][0][0]=0
x,y,z=0,0,0
for i in a:
    if i==1:
        x+=1
    elif i==2:
        y+=1
    else:
        z+=1
print(memo(x,y,z))

### FIXED CODE ###

#解説AC
n=int(input())
a=list(map(int,input().split()))
dp=[[[-1]*(301) for i in range(301)] for j in range(301)]
# dp[a][b][c]=(1個の皿がa枚,2個の皿がb枚,3個の皿がc枚ある時, 全て食べ終わるまでの操作回数の期待値)
# dp[a][b][c]の遷移
#               確率          行先
# 1枚が引かれる  a/N　　　    dp[a-1][b][c]
# 2枚が引かれる  b/N　　　    dp[a+1][b-1][c]
# 3枚が引かれる  c/N　　　    dp[a][b+1][c-1]
# 0枚が引かれる  (N-a-b-c)/N　dp[a][b][c]

#dp[a][b][c]=dp[a-1][b][c]*a/n+dp[a+1][b-1][c]*b/n+dp[a][b+1][c-1]*c/n+dp[a][b][c]*(n-a-b-c)/n+1
#dp[a][b][c]=(dp[a-1][b][c]*a+dp[a+1][b-1][c]*b+dp[a][b+1][c-1]*c+n)/(a+b+c)

def memo(i,j,k):
    if dp[i][j][k]+1:
        return dp[i][j][k]
    ans=n
    if i>0:
        ans+=memo(i-1,j,k)*i
    if j>0:
        ans+=memo(i+1,j-1,k)*j
    if k>0:
        ans+=memo(i,j+1,k-1)*k
    dp[i][j][k]=ans/(i+j+k)
    return ans/(i+j+k)
dp[0][0][0]=0
x,y,z=0,0,0
for i in a:
    if i==1:
        x+=1
    elif i==2:
        y+=1
    else:
        z+=1
print(memo(x,y,z))
### BUGGY CODE ###

import sys
N, M = map(int, input().split())
xs = list(map(int, input().split()))
G = [set() for _ in range(N+1)]
es = []
for i in range(M):
    u, v = sorted(map(int, input().split()))
    if xs[u-1] == xs[v-1]:
        G[v].add(u)
        G[u].add(v)
    elif xs[u-1] > xs[v-1]:
        G[u].add(v)
    else:
        G[v].add(u)
    es.append((u,v))
xs,d,cc = sorted([(x,i+1) for i, x in enumerate(xs)]),{},{}
for i in range(N):
    if not G[i+1]:
        print(-1)
        sys.exit()
for x, u in xs:
    if u in cc:
        continue
    cc[u] = 1
    for c in G[u]:
        if c in cc:
            cc[u] = 1-cc[c]
    stack = [u]
    while stack:
        q = stack.pop()
        for c in G[q]:
            e = tuple(sorted([q,c]))
            d[e] = x
            if c in cc:
                continue
            stack.append(c)
            cc[c] = 1-cc[q]
print("".join("BW"[cc[i]] for i in range(1,N+1)))
for i in range(M):
    print(d[es[i]])


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
bxs = list(map(int, input().split()))
xs = bxs[:]
dd = defaultdict(set)
for i, x in enumerate(xs):
    dd[x].add(i+1)
xs = list(set(xs))
xs.sort()

#for x, i in xs:
G = [set() for _ in range(N+1)]
G2 = [set() for _ in range(N+1)]
es = []
for i in range(M):
    u, v = map(int, input().split())
    if bxs[u-1] == bxs[v-1]:
        G[v].add(u)
        G[u].add(v)
    elif bxs[u-1] > bxs[v-1]:
        G[u].add(v)
    else:
        G[v].add(u)
    e = (min(u,v), max(u,v))
    es.append(e)

r = True
d = dict()
cc = [-1 for _ in range(N+1)]
for i in range(N):
    if len(G[i+1]) == 0:
        print(-1)
        sys.exit()
for x in xs:
    for u in dd[x]:
        if cc[u] != -1:
            continue
        for c in G[u]:
            if cc[c] == -1:
                cc[u] = 1
                break
            else:
                cc[u] = 1-cc[c]
        stack = [u]
        while stack:
            q = stack.pop()
            for c in G[q]:
                e = (min(q,c), max(q,c))
                if e in d:
                    continue
                d[e] = x
                if cc[c] != -1:
                    continue
                stack.append(c)
                cc[c] = 1 - cc[q]
for i in range(1, N+1):
    if cc[i] == -1:
        print(-1)
        sys.exit()
for i in range(1, N+1):
    print("B"if cc[i] else "W", end="")
print()
for i in range(M):
    print(d[es[i]])
### BUGGY CODE ###

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

d = {}
def kitaichi(n):
	if n in d.keys(): return d[n]
	else:
		sum = 0
		for i in range(n+1):
			sum += i
		sum = n * (n+1) / 2
		d[n] = sum / n
		return d[n]

ans = 0
for i in range(len(p)):
	pp = p[i:i+k]
	if len(pp) != k: break
	tmp = 0
	for j in pp:
		tmp += kitaichi(j)
	ans = max(ans, tmp)


print(ans)

### FIXED CODE ###

from itertools import accumulate
n, k = map(int, input().split())
p = [-~int(i)/2 for i in input().split()]
a = [0] + list(accumulate(p))
print(max(j-i for i, j in zip(a, a[k:])))
### BUGGY CODE ###

from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
ans = min([abs(sum(A)-2*a) for a in tmp])
print(ans)

### FIXED CODE ###

from itertools import accumulate
N = int(input())
A = [int(i) for i in input().split()]
tmp = list(accumulate(A))[:len(A)-1]
total  = sum(A)

    
ans = min([abs(total-2*a) for a in tmp])
print(ans)
### BUGGY CODE ###

import itertools

N, K = map(int, input().split())
menu = {}

for i in range(N):
    t, d = map(int, input().split())
    menu[i] = (t, d)

def manzoku(s):
    manzoku = sum([menu[i][1] for i in s]) + len(set([menu[i][0] for i in s]))**2
    return manzoku

#K sushi
shushi = itertools.combinations(menu, K)
print(max([manzoku(c) for c in shushi]))


### FIXED CODE ###

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

for i in range(N):
    t, d = map(int, input().split())
    menu_.append((t, d))

menu = sorted(menu_, key = lambda x:x[1], reverse=True)
neta = set()
duplicates = []

for m in menu[:K]:
    if m[0] in neta:
        duplicates.append(m[1])
    else:
        neta.add(m[0])

p = sum([d for (t, d) in menu[:K]]) + len(neta)**2
ans = p

for m in menu[K:]:
    if m[0] not in neta and duplicates:
        neta.add(m[0])
        duplicate = duplicates.pop()
        
        p += (m[1] - duplicate) + 2 * len(neta) - 1 
        #print(ans, p)
        ans = max(ans, p)

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

H,W,M = map(int, input().split())

squares = []
for i in range(H):
    arr = []
    for j in range(W):
        arr.append(0)
    squares.append(arr)

boms = []
for i in range(M):
    hi, wi = map(int, input().split())
    squares[hi-1][wi-1] = 1
    boms.append([hi-1, wi-1])

row_sums = []
for i in range(H):
    row_sums.append(sum(squares[i]))

col_sums = []
for j in range(W):
    sum = 0
    for i in range(H):
        sum += squares[i][j]
    col_sums.append(sum)

row_max = max(row_sums)
col_max = max(col_sums)

row_indexes = []
for i in range(H):
    if row_sums[i] == row_max:
        row_indexes.append(i)

col_indexes = []
for j in range(W):
    if col_sums[j] == col_max:
        col_indexes.append(j)

hits = 0
for bom in boms:
    if bom[0] in row_indexes and bom[1] in col_indexes:
        hits += 1

if hits == len(row_indexes) * len(col_indexes):
    print(row_max + col_max - 1)
else:
    print(row_max + col_max)


### FIXED CODE ###

import sys
input = sys.stdin.readline

H,W,M=map(int,input().split())
nh=[0]*H
nw=[0]*W
boms=set()
for _ in range(M):
    h,w=map(int,input().split())
    nh[h-1] += 1
    nw[w-1] += 1
    boms.add((h-1, w-1))

maxh = max(nh)
maxw = max(nw)

i_indexes=[]
for i in range(H):
    if nh[i] == maxh:
        i_indexes.append(i)
j_indexes=[]
for j in range(W):
    if nw[j] == maxw:
        j_indexes.append(j)

for i in i_indexes:
    for j in j_indexes:
        if (i,j) in boms:
            continue
        print(maxh + maxw)
        exit()
print(maxh + maxw - 1)
### BUGGY CODE ###

def countDivisors(num):
    cnt = 0
    sqrt = int(num ** 0.5)
    for x in range(1, sqrt + 1):
        if num % x == 0:
            cnt += 1
    return cnt * 2 - (sqrt ** 2 == num)

N = int(input())

sum = 0
for n in range(1,N+1):
    l = countDivisors(n)
    sum += l*n
print(sum)

### FIXED CODE ###

N = int(input())
 
sum = 0
ro = 1
for n in range(1,N+1):
    num = int(N/n)
    if num == 1:
        record = n
        break
    s = int(((1+num)*num)/2)
    sum += ro*s
    ro += 1


sum += int(((record+N)*(N-record+1))/2)
print(sum)
### BUGGY CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

res = ['No'] * n
for i in range(n):
  if k - q + a.count(i+1) > 0:
    res[i] = 'Yes'
print('\n'.join(map(str, res)))

### FIXED CODE ###

n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]

if k - q > 0:
  res = ['Yes'] * n
else:
  res = ['No'] * n
  ans = [0] * n
  for i in range(len(a)):
    ans[a[i]-1] += 1
  for i in range(n):
    if k - q + ans[i] > 0:
      res[i] = 'Yes'
print('\n'.join(map(str, res)))
### BUGGY CODE ###

N = int(input())
A = [int(i) for i in input().split(' ')]

A.sort(reverse=True)
max_value = A.pop(0)
diff = [max_value]
ans = 0
for i in A:
    ans = ans + max(diff)
    n = diff.index(max(diff))
    diff[n] = i
    diff.insert(n + 1, i)

print(ans)

### FIXED CODE ###

import sys
from collections import deque

N = int(sys.stdin.readline())
A = [int(i) for i in sys.stdin.readline().split(' ')]

A.sort(reverse=True)
max_value = A.pop(0)
diff = deque([max_value])
ans = 0
for i in A:
    ans = ans + diff.popleft()
    diff.append(i)
    diff.append(i)

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

import sys
sys.setrecursionlimit(500*500) # default 1000
N, Q = map(int, input().strip().split())
visited = [False for _ in range(N)]
def dfs(v): # vertices & parent idx
    visited[v]=True
    for child in to[v]:
        if visited[child]==True:
            continue
        ans[child]+=ans[v]
        dfs(child)
# def dfs(v,p=-1): # vertices & parent idx
#     for child in to[v]:
#         if child==p:
#             continue
#         ans[child]+=ans[v]
#         dfs(child,v)
        


to=[[] for j in range(N)] # N points
ans=[0]*N # N points

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

for i in range(Q):
    p,x=map(int, input().strip().split())
    p-=1
    ans[p]+=x

dfs(0)
for i in range(N):
    print(ans[i],end=' ')

### FIXED CODE ###

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

# visited = [False for _ in range(N)]
# def dfs(v): # vertices & parent idx
#     visited[v]=True
#     for child in to[v]:
#         if visited[child]==True:
#             continue
#         ans[child]+=ans[v]
#         dfs(child)
# def dfs(v,p=-1): # vertices & parent idx
#     for child in to[v]:
#         if child==p:
#             continue
#         ans[child]+=ans[v]
#         dfs(child,v)

to=[[] for j in range(N)] # N points
ans=[0]*N # N points

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

for i in range(Q):
    p,x=map(int, input().strip().split())
    p-=1
    ans[p]+=x

# dfs(0)
stack=[0]
visited=[False]*N
while stack:
    v=stack.pop()
    visited[v]=True
    for child in to[v]:
        if visited[child] ==False:
            # visited[v]=True
            ans[child]+=ans[v]
            stack.append(child)
for i in range(N):
    print(ans[i],end=' ')
# print(ans)
### BUGGY CODE ###

N = int(input())

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

sum_water = sum(A)
A = A[1:] + A[0:N-2]
for i in range(N):
    tmp=sum_water
    for j in range((N-1)//2):
        tmp-=A[i+j*2]*2
    print(tmp, end="")
    print(" ", end="")
# for i in range(len(X)-1):
#     print(X[i], end="")
#     print(" ", end="")
# print(X[-1])

### FIXED CODE ###

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

sum_water = sum(A)

tmp=sum_water
for j in range((N-1)//2):
    tmp-=A[j*2+1]*2
print(tmp, end="")
print(" ", end="")

for i in A[:-1]:
    tmp = 2*i - tmp
    print(tmp, end="")
    print(" ", end="")
### BUGGY CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)

ans = []
lines_dict =None
d=None
def main():
    global AB, PX, T
    if 'LOCAL' in os.environ:
        N = 2* 10** 5
        Q = 2 * 10 ** 5
        AB = [[i, i + 1] for i in range(1, N)]
        PX = [[i, 10] for i in range(Q)]
    else:
        N, Q = LI()
        AB = tuple()
        T = {}
        PX = {}
        for i in range(1, N+1):
            T[i] = []
            PX[i] = 0
        for i in range(N-1):
            a, b = LI()
            AB += (a, b)
            T[a] += [b]
            T[b] += [a]

        for i in range(Q):
            p, x = LI()
            PX[p] += x
        dfs(1, -1)
        for i in sorted(PX.keys()):
            print(PX[i], end=' ')
        #  ans = [0 for _ in range(N)]

def dfs(parent, parent_parent):
    for node in T[parent]:
        if node != parent_parent:
            PX[node] += PX[parent]
            dfs(node, parent)

if __name__ == '__main__':
    main()



### FIXED CODE ###

import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os, pdb
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def perr(s): return print(s, file=sys.stderr)

if 'LOCAL' in os.environ:
    N = 2* 10** 5
    Q = 2 * 10 ** 5
    AB = [[i, i + 1] for i in range(1, N)]
    PX = [[i, 10] for i in range(Q)]
else:
    N, Q = LI()
    AB = []
    PX = []
    for i in range(N-1):
        AB.append(LI())

    for i in range(Q):
        PX.append(LI())


"""
そもそも各頂点の部分木をdictに入れましょうか？
参照するような形で。
2には3
3には4,5
4,5はNoneだと、参照しやすいか？

カウントを若い順にやっていく
"""
AB = sorted(AB, key=lambda x: x[0])
perr('AB')
perr(AB)
d = {}
for p, x in PX:
    if p not in d.keys():
        d[p] = 0
    d[p] += x
for a, b in AB:
    if b not in d.keys():
        d[b] = 0
    if a not in d.keys():
        d[a] = 0
    d[b] += d[a]
for i in range(1, N+1):
    print(d[i], end=' ')