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

import sys
input = sys.stdin.readline
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0]*(w+1)
for i in range(n):
    for j in range(w,wv[i][0]-1,-1):
        dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1])

print(max(dp))

### FIXED CODE ###

N,W=map(int,input().split())
L = [list(map(int, input().split())) for i in range(N)]
dp = [[0 for j in range(110000)] for i in range(110)]
for i in range(1,N+1):
  for j in range(W+1):
    dp[i][j]=dp[i-1][j]
    if j-L[i-1][0]>=0:
      dp[i][j]=max(dp[i][j],dp[i-1][j-L[i-1][0]]+L[i-1][1])
ans=dp[N][W]
print(ans)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from itertools import permutations

def main():
	n,m,R=MI()
	r=LI()

	G=[[10**9]*(n+1) for _ in range(n+1)]
	for i in range(n+1):
		G[i][i]=0



	for _ in range(m):
		a,b,c=MI()
		G[a][b]=min(G[a][b],c)
		G[b][a]=min(G[b][a],c)
	#print(G)

	for k in range(n+1):
		for i in range(n+1):
			for j in range(n+1):
				G[i][j]=min(G[i][j],G[i][k]+G[k][j])
	#print(G)

	ans=10**9
	for i in permutations(r,R):
		#print(i)
		ret=0
		for j in range(R-1):
			ret+=G[i[j]][i[j+1]]
		#print(ret)
		ans=min(ans,ret)
	print(ans)





if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

from itertools import permutations

def main():
	n,m,R=MI()
	r=LI()

	G=[[10**9]*(n+1) for _ in range(n+1)]
	for i in range(n+1):
		G[i][i]=0



	for _ in range(m):
		a,b,c=MI()
		G[a][b]=min(G[a][b],c)
		G[b][a]=min(G[b][a],c)
	#print(G)

	for k in range(n+1):
		for i in range(n+1):
			for j in range(n+1):
				G[i][j]=min(G[i][j],G[i][k]+G[k][j])
	#print(G)

	ans=10**9
	for i in permutations(r,R):
		#print(i)
		ret=0
		for j in range(R-1):
			ret+=G[i[j]][i[j+1]]
		#print(ret)
		ans=min(ans,ret)
	print(ans)





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

n,k=map(int,input().split())
A=[0]*k
mod=10**9+7

def power(a,x): #a**xの計算
    T=[a]
    while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
        T.append(T[-1]**2%mod)
    b=bin(x) #xを2進数表記にする
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

for i in range(k):
    cnt=power(k//(k-i),n)
    now=(k-i)*2
    while now<=k:
        cnt-=A[now-1]
        now+=k-i
    A[k-i-1]=cnt

ans=0
for i in range(k):
    ans+=(i+1)*A[i]%mod
    ans%=mod
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
A=[0]*k
mod=10**9+7

def power(a,x): #a**xの計算
    T=[a]
    while 2**(len(T))<mod: #a**1,a**2.a**4,a**8,...を計算しておく
        T.append(T[-1]**2%mod)
    b=bin(x) #xを2進数表記にする
    ans=1
    for i in range(len(b)-2):
        if int(b[-i-1])==1:
            ans=ans*T[i]%mod
    return ans

for i in range(k):
    cnt=power(k//(k-i),n)
    now=(k-i)*2
    while now<=k:
        cnt-=A[now-1]
        now+=k-i
    A[k-i-1]=cnt

ans=0
for i in range(k):
    ans+=(i+1)*A[i]%mod
    ans%=mod
print(ans)
### BUGGY CODE ###

import heapq
H, W = map(int, input().split())
edges = [[] for _ in range(10)]
for i in range(10):
    e_list = list(map(int, input().split()))
    for j in range(10):
        if j == i:
            continue
        edges[i].append([j, e_list[j]])
A = []
for i in range(H):
    A.append(list(map(int, input().split())))

def dijkstra(edges, num_v, start):
    dist = [float('inf')] * num_v
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])

    while len(q) > 0:
        _, u = heapq.heappop(q)
        for edge in edges[u]:
            if dist[edge[0]] > dist[u] + edge[1]:
                dist[edge[0]] = dist[u] + edge[1]
                heapq.heappush(q, [dist[u] + edge[1], edge[0]])
    return dist
ans = 0
for a_line in A:
    for a in a_line:
        if a == -1 or a == 1:
            continue
        ans += dijkstra(edges, 10, a)[1]

print(ans)

### FIXED CODE ###

import heapq
H, W = map(int, input().split())
edges = [[] for _ in range(10)]
for i in range(10):
    e_list = list(map(int, input().split()))
    for j in range(10):
        if j == i:
            continue
        edges[i].append([j, e_list[j]])
A = []
for i in range(H):
    A.append(list(map(int, input().split())))

def dijkstra(edges, num_v, start):
    dist = [float('inf')] * num_v
    dist[start] = 0
    q = []
    heapq.heappush(q, [0, start])

    while len(q) > 0:
        _, u = heapq.heappop(q)
        for edge in edges[u]:
            if dist[edge[0]] > dist[u] + edge[1]:
                dist[edge[0]] = dist[u] + edge[1]
                heapq.heappush(q, [dist[u] + edge[1], edge[0]])
    return dist
ans = 0
root_list = [0] * 10
for i in range(10):
    if i == 1:
        continue
    root_list[i] = dijkstra(edges, 10, i)[1]
for a_line in A:
    for a in a_line:
        if a == -1 or a == 1:
            continue
        ans += root_list[a]

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

def BIT_query(BIT,idx):
  res_sum=0
  if idx==0:
    return 0
  while idx>0:
    res_sum+=BIT[idx]
    idx-=idx&(-idx)
  return res_sum

def BIT_update(BIT,idx,x,n):
  while idx<=n:
    BIT[idx]+=x
    idx+=idx&(-idx)
  return

def main():
  N,Q=map( int, input().split())
  C=list( map( int, input().split()))
  LRI=[]
  for i in range(Q):
    l,r=map( int, input().split())
    LRI.append((r,l,i))
  LRI.sort(key=lambda x:x[0])
  lastAppend=[-1]*(N+1)
  BIT=[0]*(N+1)
  ANS=[0]*Q
  now=1
  for r,l,i in LRI:
    while now <= r:
      c=C[now-1]
      if lastAppend[c]== -1:
        BIT_update(BIT,now,1,N)
      else:
        BIT_update(BIT,now,1,N)
        BIT_update(BIT,lastAppend[c],-1,N)
      lastAppend[c]=now                
      now+=1
    ANS[i] = BIT_query(BIT,r) - BIT_query(BIT,l-1)
  for ans in ANS:
    print(ans)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline

def BIT_query(BIT,idx):
  res_sum=0
  if idx==0:
    return 0
  while idx>0:
    res_sum+=BIT[idx]
    idx-=idx&(-idx)
  return res_sum

def BIT_update(BIT,idx,x,n):
  while idx<=n:
    BIT[idx]+=x
    idx+=idx&(-idx)
  return

def main():
  N,Q=map( int, input().split())
  C=list( map( int, input().split()))
  LRI=[]
  for i in range(Q):
    l,r=map( int, input().split())
    LRI.append((r,l,i))
  LRI.sort(key=lambda x:x[0])
  lastAppend=[-1]*(N+1)
  BIT=[0]*(N+1)
  ANS=[0]*Q
  now=1
  for r,l,i in LRI:
    while now <= r:
      c=C[now-1]
      if lastAppend[c]== -1:
        BIT_update(BIT,now,1,N)
      else:
        BIT_update(BIT,now,1,N)
        BIT_update(BIT,lastAppend[c],-1,N)
      lastAppend[c]=now                
      now+=1
    ANS[i] = BIT_query(BIT,r) - BIT_query(BIT,l-1)
  for ans in ANS:
    print(ans)
    
if __name__ == '__main__':
    main()
### BUGGY CODE ###

def solve():
    
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=a[i]^a[j]
            if ans>=10**9+7:
                ans=ans%(10**9+7)
    print(ans%(10**9+7))
    
n=int(input())
a=list(map(int,input().split()))
solve()

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
a=tuple(map(int,input().split()))
mod=10**9+7
cnt=[0]*60

for temp in a:
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(digit):
        if (temp>>j)&1:
            cnt[j]=cnt[j]+1

#print(cnt)
ans=0
for i in range(60):
    if cnt[i]==0:continue
    ans=(ans+pow(2,i)*cnt[i]*(n-cnt[i]))%mod
print(ans%mod)
### BUGGY CODE ###

N=int(input())
n=N
p=2
dcmp={}
while n>1:
    if n%p==0:
        dcmp[p]=1+(dcmp[p] if p in dcmp else 0)
    else:
        p+=1
cnt=0
for k,v in dcmp.items():
    i=1
    while True:
        dcmp[k]-=i
        if dcmp[k]<0:
            break
        i+=1
        cnt+=1

print(cnt)


### FIXED CODE ###

import math
N=int(input())
n=N
p=2
dp=1
thrP=math.sqrt(N)
dcmp={}
while n>1:
    if n%p==0:
        dcmp[p]=1+(dcmp[p] if p in dcmp else 0)
        n//=p
    else:
        p+=dp
        dp=2
    if p>thrP:
        if n>1:
            dcmp[n]=1
        break
cnt=0
for k,v in dcmp.items():
    i=1
    while True:
        dcmp[k]-=i
        if dcmp[k]<0:
            break
        i+=1
        cnt+=1

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

n = int(input())
cnt =[0]*(n+1)
ans = 0

for i in range(1,n):
    m = (n-1)//i
    for j in range(1,m+1):
        cnt[i*j] += 1
        
for i in range(1,n+1):
    ans += cnt[i]
    
print(ans)

### FIXED CODE ###

n = int(input())
cnt =[0]*(n+1)
ans = 0

for i in range(1,n):
    m = (n-1)//i
    for j in range(1,m+1):
        ans += 1
        
print(ans)
### BUGGY CODE ###

n=int(input())

for i in range(1,n+1):
  count = 0
  for x in range(1,99):
    for y in range(1,99):
      for z in range(1,99):
        fn = (x+y)**2 + (y+z)**2 + (z+x)**2
        if fn > 2*i:
          break
        if fn == 2*i:
          count += 1
  print(count)


### FIXED CODE ###

n=int(input())

result = [0] * (n+1)
for x in range(1,99):
  for y in range(1,99):
    for z in range(1,99):
      fn = x*x + y*y + z*z + x*y + y*z + z*x
      if fn > n:
        break
      result[fn] += 1

for i in range(1,n+1):
  print(result[i])
### BUGGY CODE ###


# ABC055
N = int(input())
power = 1
for n in range(1, N+1):
    power *= n
print(power % (10**9+7))


### FIXED CODE ###

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

N,K = map(int, input().split())
S = []
for i in range(K):
    L,R = map(int, input().split())
    S += [ j for j in range(L,R+1)]
S = set(S)

step = [0]*(N+1)
step[1] = 1

for j in range(1,N):
    for s in S:
        if j + s > N or step[j] == 0:
            continue
        step[j+s] += (step[j]%998244353)
        step[j+s] %= 998244353
print(step[N])


### FIXED CODE ###

mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
for i in range(k):
    lr[i][1] += 1

dp = [0]*n
dp[0] = 1
for i in range(1,n):
    dp[i] = dp[i-1]
    if i == 1:
        dp[1] = 0
    for l,r in lr:
        if i - l >= 0:
            dp[i] += dp[i-l]
        if i - r >= 0:
            dp[i] -= dp[i-r]
        dp[i] %= mod
print(dp[n-1])
### BUGGY CODE ###

import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
T=np.zeros((H,W))
B=np.zeros((H,W))
L=np.zeros((H,W))
R=np.zeros((H,W))

for j in range(W):
    nt=0
    for i in range(1,H):  
        if S[i-1,j]:
            nt+=1          
        else:
            nt=0
        T[i,j]=nt

for j in range(W):
    nt=0
    for i in reversed(range(H-1)):
        if S[i+1,j]:
            nt+=1          
        else:
            nt=0
        B[i,j]=nt

for i in range(H):
    nt=0
    for j in range(1,W):
        if S[i,j-1]:
            nt+=1          
        else:
            nt=0
        L[i,j]=nt

for i in range(H):
    nt=0
    for j in reversed(range(W-1)):
        if S[i,j+1]:
            nt+=1          
        else:
            nt=0
        R[i,j]=nt

na=0
for i in range(H):
    for j in range(W):
        if S[i,j]:
            nat=int(T[i,j]+B[i,j]+L[i,j]+R[i,j]+1)
            na=max(nat,na)

print(na)
#print(T)



### FIXED CODE ###

import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
T=np.zeros((H,W),dtype=int)
B=np.zeros((H,W),dtype=int)
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)

for i in range(1,H):  
    T[i,:]=(T[i-1,:]+1)*S[i-1,:]

for i in reversed(range(H-1)):
    B[i,:]=(B[i+1,:]+1)*S[i+1,:]

for j in range(1,W):
    L[:,j]=(L[:,j-1]+1)*S[:,j-1]        

for j in reversed(range(W-1)):
    R[:,j]=(R[:,j+1]+1)*S[:,j+1]
        

na=((T+B+L+R)*S).max()+1

print(na)
### BUGGY CODE ###

Matches = {str(num): c for num, c in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 5, 5, 4, 5, 6, 3, 7, 6])}


def solve(N, M, As):
    Ms = {num: c for num, c in Matches.items() if int(num) in As}
    dp = ["-1" for _ in range(N + 1)]
    dp[0] = "0"
    for n in range(N + 1):
        for num, c in Ms.items():
            if n - c >= 0:
                if dp[n - c] == "-1":
                    continue
                if dp[n - c] == "0":
                    dp[n] = str(max(int(num), int(dp[n])))
                else:
                    dp[n] = str(max(int(dp[n - c] + num),
                                int(num + dp[n - c]),
                                int(dp[n])))
    return int(dp[N])


if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, M, As))


### FIXED CODE ###

Matches = {num: c for num, c in zip([1, 2, 3, 4, 5, 6, 7, 8, 9], [2, 5, 5, 4, 5, 6, 3, 7, 6])}


def solve(N, M, As):
    dp = [-1 for _ in range(N + 1)]
    dp[0] = 0
    for a in sorted(As, reverse=True):
        c = Matches[a]
        for i in range(N - c + 1):
            if dp[i] == -1:
                continue
            dp[i + c] = max(dp[i+c],
                            dp[i] * 10 + a)
    return dp[N]

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    As = list(map(int, input().split(" ")))
    print(solve(N, M, As))
### BUGGY CODE ###

n = int(input())
line = input().split(' ')
t_list =[]
for i in range(0,n):
   t = i + int(line[i])
   t_list.append(t)
a = 0
for i in range(n *2 -1):
    if t_list.count(i) == 2:
        a += 1
print(a)

### FIXED CODE ###

n = int(input())
a = input().split(' ')
t = 0
for o in range(n):
    i = o + 1
    b = int(a[o]) - i
    if i == int(a[o + b]):
      t += 1
print(int(t / 2))
### BUGGY CODE ###

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

output='Yes'
for i in range(N-1):
  if H[i]-min(H[i+1:])>1:
    output='No'
    
print(output)

### FIXED CODE ###

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

index=N-1
output='Yes'
while index>0:
  if h[index-1]-h[index]>1:
    output='No'
    break
  elif h[index-1]-h[index]==1:
    h[index-1]-=1
  else:
    pass
  index-=1
  
print(output)
### BUGGY CODE ###

n=int(input())
A=list(map(int,input().split()))+[0]
ans=0

while 1:
  for i in range(n):
    if A[i]>0:
      A[i]-=1
      if A[i+1]==0:
        ans+=1
  if A==[0 for i in range(n)]:
    break
print(ans)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))+[0]
ans=0

while 1:
  for i in range(n):
    if A[i]>0:
      A[i]-=1
      if A[i+1]==0:
        ans+=1
  if not A==[0 for i in range(n+1)]:
    continue
  break
print(ans)
### BUGGY CODE ###

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
    b, c = map(int, input().split())
    for _ in range(b):
        L.append(c)
L.sort(reverse=True)

idx = 0
for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx]):
        A[i] = L[idx]
        idx += 1
    else:
        break

print(sum(A))


### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
L = []
for _ in range(M):
    b, c = map(int, input().split())
    L.append([b, c])
L.sort(key=lambda x: x[1], reverse=True)
# 変更前のカードの枚数
# 変更後のカードの枚数
# をそれぞれ保存しておく

idx = 0
for i in range(N):
    if (idx > len(L) - 1):
        break
    if (A[i] < L[idx][1]):
        A[i] = L[idx][1]
        L[idx][0] -= 1
        if (L[idx][0] != 0):
            continue
        else:
            idx += 1
    else:
        break
print(sum(A))
### BUGGY CODE ###

import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

R,C,K = LI()
r,c,v = LIR(K,3)

a = [[0]*C for _ in range(R)]
for i in range(K):
    a[r[i]-1][c[i]-1] = v[i]

dp = [[[0]*4 for _ in range(C)] for _ in range(R)]
if a[0][0]:
    dp[0][0][1] = a[0][0]

for i in range(R):
    for j in range(C):
        for k in range(4):
            if i == j == 0:
                continue
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            upper_max = max(dp[i-1][j]) if i >= 1 else 0
            if j >= 1:
                val1 = dp[i][j-1][k]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[i][j-1][k-1] + a[i][j]
            dp[i][j][k] = max(val1,val2,val3,val4)

print(max(dp[R-1][C-1]))

### FIXED CODE ###

import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

R,C,K = LI()
r,c,v = LIR(K,3)

def index(i,j,k):
    return k*C*R + i*C + j

a = [[0]*C for _ in range(R)]
for i in range(K):
    a[r[i]-1][c[i]-1] = v[i]

dp = [0]*(4*C*R)
dp[index(0,0,1)] = a[0][0]

for i in range(R):
    for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4)

ans = 0
for k in range(4):
    ans = max(ans,dp[index(R-1,C-1,k)])

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

import sys
def input():
    return sys.stdin.readline()[:-1]
 
N, K, Q = map(int, input().split())
 
points = [K for _ in range(N)]
 
for q in range(Q):
    A = int(input()) - 1
    points = [p if i == A else p-1 for i, p in enumerate(points)]
for p in points:
    if p < 1:
        print('No')
    else:
        print('Yes')

### FIXED CODE ###

import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]

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

points = np.array([K - Q for _ in range(N)])

for q in range(Q):
    A = int(input()) - 1
    points[A] +=1

for p in points:
    if p < 1:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

num = int(input())
data = []
for _ in range(num):
    data.append(sorted(input()))
count = 0
for i in range(num):
    for j in range(i+1,num):
        if data[i] == data[j]:
            count+=1
print(count)

### FIXED CODE ###

"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()
inf = float("inf") # 無限

n = int(input())

data = {}
for _ in range(n):
    temp = "".join(sorted(input()))
    # print(temp)
    if temp in data.keys():
        data[temp] += 1
    else:
        data[temp] = 1
# print(data)

answer = 0
for num in data.values():
    answer += (num*(num-1))//2
print(answer)
### BUGGY CODE ###

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

m = n + 1

for i in range(1,m):
    c = a.count(i)
    print(c)


### FIXED CODE ###

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

s = [0]*(n)

for i in range(n-1):
    s[a[i]-1] = s[a[i]-1] + 1
    
for j in range(n):
    print(s[j])
### BUGGY CODE ###

#!/usr/bin/env python3

from copy import copy


def min_max_try(n, dams):
    mt_min = [0] * n
    mt_max = copy(dams)

    for _ in range(1000):
        # max -> min
        update = False
        for i in range(n):
            tmp_min = dams[i] - mt_max[i]
            if tmp_min > mt_min[(i+1) % n]:
                mt_min[(i+1) % n] = tmp_min
                update = True
            tmp_min = dams[i] - mt_max[(i+1) % n]
            if tmp_min > mt_min[i]:
                mt_min[i] = tmp_min
                update = True
        if not update:
            return mt_min, mt_max

        # min -> max
        update = False
        for i in range(n):
            tmp_max = dams[i] - mt_min[i]
            if tmp_max < mt_max[(i+1) % n]:
                mt_max[(i+1) % n] = tmp_max
                update = True
            tmp_max = dams[i] - mt_min[(i+1) % n]
            if tmp_max < mt_max[i]:
                mt_max[i] = tmp_max
                update = True
        if not update:
            return mt_min, mt_max

    return mt_min, mt_max


def check_answer(pos, val, n, dams):
    mt = [val] * n
    for i in range(n-1):
        mt[(pos+i+1) % n] = dams[(pos+i) % n] - mt[(pos+i) % n]
    ok = mt[pos] + mt[(pos+n-1) % n] == dams[(pos+n-1) % n]
    return ok, mt


def solv(n, dams):
    # print(dams)
    mt_min, mt_max = min_max_try(n, dams)
    # print(mt_min, mt_max)

    for i in range(n):
        ok, mt = check_answer(i, mt_min[i], n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    idx = 0
    diff = mt_max[0] - mt_min[0]
    for i in range(1, n):
        if mt_max[i] - mt_min[i] < diff:
            diff = mt_max[i] - mt_min[i]
            idx = i

    for val in range(mt_min[idx], mt_max[idx]+1):
        ok, mt = check_answer(idx, val, n, dams)
        if ok:
            return ' '.join([str(m*2) for m in mt])

    return 'Error'


if __name__ == '__main__':

    n = int(input())

    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)
    print(ans)


### FIXED CODE ###

#!/usr/bin/env python3


def solv(n, dams):
    m = (sum(dams[::2]) - sum(dams[1::2])) // 2
    ans = [m*2]
    for i in range(n-1):
        m = dams[i] - m
        ans.append(m*2)
    return ans


if __name__ == '__main__':

    n = int(input())
    dams = [int(a) for a in input().split()]

    ans = solv(n, dams)

    print(' '.join([str(a) for a in ans]))