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

n=int(input())
li=list(map(int,input().split()))
li.sort()
if li[0]==0:
  print(0)
else:
  ans=1
  for i in li:
    ans*=i
    if ans>1000000000000000000:
        ans=-1
        exit
    else:
        continue
    
  if ans<1000000000000000001:
      print(ans)
  else:
      print(-1)


### FIXED CODE ###

import sys
n=int(input())
li=list(map(int,input().split()))
li.sort()
if li[0]==0:
  print(0)
  sys.exit()
else:
  ans=1
  for i in li:
    ans*=i
    if ans>1000000000000000000:
        print(-1)
        sys.exit()
    else:
        continue
    
  if ans>1000000000000000000:
      print(-1)
  else:
      print(ans)
### BUGGY CODE ###

n = int(input())
A = [int(num) for num in input().split()]

cont = False
if n % 2 == 1:
  if A.count(0) != 1:
    cont = True
  for i in range(2, n, 2):
    if A.count(i) != 2:
      cont = True
      break
else:
  for i in range(1, n, 2):
    if A.count(i) != 2:
      cont = True
      break

if cont == True:
  print(0)
else:
  print(2**(n//2) % (10**9 + 7))

### FIXED CODE ###

n = int(input())
A = [int(num) for num in input().split()]
import collections as cl
dic = cl.Counter(A)

cont = False
if n % 2 == 1:
  if dic[0] != 1:
    cont = True
  else:
    dic[0] = 2
    for num in dic.values():
      if num != 2:
        cont = True
        break
else:
  for num in dic.values():
    if num != 2:
      cont = True
      break

if cont == True:
  print(0)
else:
  print(2**(n//2) % (10**9 + 7))
### BUGGY CODE ###

import math
l = [int(input())]
c = 0

while l:
  
  if l[0] == 1:
    l.remove(1)
  else:
    x = math.floor(l[0] / 2)
    l.remove(l[0])
    l.append(x)
    l.append(x)
  c += 1
print(c)

### FIXED CODE ###

import math
H = int(input())

def f(x):
  if x == 1:
    return 1
  else:
    return 2 * f(x // 2) + 1
print(f(H))
### BUGGY CODE ###

import collections

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
#print(a)

n=len(a)-1
T=list()

for i in range(n+1):
    T.append(a[n-i]*10**i)
    
#print(T)
for i in range(1,n+1):
    T[i]+=T[i-1]
    
#print(T)
L=list()
for i in range(n+1):
    L.append(T[i]%2019)
   

#print(L)
c = collections.Counter(L)

#出現回数が2回以上のものの出現数 + 0の出現回数
print(int(len([i[0] for i in c.items() if i[1] >= 2])) + int(len([i for i in L if i==0])))

### FIXED CODE ###

S = list(input())
a=[int(x) for x in S] #int型のリストに変換
a.reverse()
#print(a)
l=[0]*2019
l[0]=1
T=0
d=1

for i in a:
    T+=(int(i)*d)
    T%=2019
    l[T]+=1
    d*=10
    d%=2019
result=0
for n in l:
    result+=n*(n-1)/2
print(int(result))
### BUGGY CODE ###

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

a_ol = {}
def_count = 0
for i in a_uni:
    a_co = a.count(i)
    a_ol[i] = a_co
    def_count += a_co * (a_co - 1)

def_count //= 2

for k in range(n):
    print(def_count - a_ol[a[k]] + 1)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))


a_ol = Counter(a)
def_count = 0
for item in a_ol.items():
    a_co = item[1]
    def_count += a_co * (a_co - 1)

def_count //= 2

for k in a:
    print(def_count - a_ol[k] + 1)
### BUGGY CODE ###

import itertools
import sys

N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]
r.sort()
a = [[sys.maxsize] * N for i in range(N)]
for i in range(M):
	A, B, C = map(int, input().split())
	a[A - 1][B - 1] = C
	a[B - 1][A - 1] = C
for i in range(N):
	a[i][i] = 0
for i in range(N):
	for j in range(N):
		if a[j][i] == sys.maxsize:
			continue
		for k in range(N):
			if a[i][k] == sys.maxsize:
				continue
			a[j][k] = min(a[i][k] + a[j][i], a[j][k])
ans = sys.maxsize
for i in itertools.permutations(r):
	b, j = 0, 1
	while j < R:
		b += a[i[j - 1] - 1][i[j] - 1]
		j += 1
	ans = min(b, ans)
print(ans)

### FIXED CODE ###

import itertools
import sys

N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]
a = [[sys.maxsize for i in range(N)] for i in range(N)]
for i in range(N):
	a[i][i] = 0
for i in range(M):
	A, B, C = map(int, input().split())
	a[A - 1][B - 1] = C
	a[B - 1][A - 1] = C
for i in range(N):
	for j in range(N):
		if a[j][i] == sys.maxsize:
			continue
		for k in range(N):
			if a[i][k] == sys.maxsize:
				continue
			a[j][k] = min(a[i][k] + a[j][i], a[j][k])
r.sort()
ans = sys.maxsize
for i in itertools.permutations(r):
	b = 0
	j = 1
	while j < R:
		b += a[i[j - 1] - 1][i[j] - 1]
		j += 1
	ans = min(b, ans)
print(ans)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(1, Q+1)]
for i in range(1,N+1):
    if A.count(i) > (Q-K):
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

N, K, Q = map(int, input().split())
A = [int(input()) for i in range(Q)]
Point = [K-Q] * N
for c in A:
    Point[c-1] += 1
for p in Point:
    if p > 0:
        print('Yes')
    else:
        print('No')
    #if A.count(i) > (Q-K):
    #    print('Yes')
    #else:
    #    print('No')
### BUGGY CODE ###

import heapq

N = int(input())
que = []
tmp = []
A1 = int(input())
heapq.heappush(que, A1*-1)
for _ in range(N-1):
    a = int(input())
    while True:
        if len(que) == 0:
            heapq.heappush(que, a*-1)
            break
        A = heapq.heappop(que)*-1
        if A < a:
            heapq.heappush(que, a*-1)
            break
        else:
            tmp.append(A)

    for val in tmp:
        heapq.heappush(que, val*-1)
    tmp = []

print(len(que))

### FIXED CODE ###

import bisect

N = int(input())
A = [-1]*N

for _ in range(N):
    val = int(input())
    n = bisect.bisect_left(A, val)
    A[n-1] = val

print(N-A.count(-1))
### BUGGY CODE ###

x, y, z, k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
taste = []
for i in set(range(x - k if x - k > 0 else 0, x)):
    for j in set(range(y - k if y - k > 0 else 0, y)):
        for l in set(range(z - k if z - k > 0 else 0, z)):
            taste.append(a[i] + b[j] + c[l])
taste.sort()
for i in range(k):
    print(taste[-1-i])

### FIXED CODE ###

x,y,z,K=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans=[]
for i in range(x):
  for j in range(y):
    for k in range(z):
      if (i+1)*(j+1)*(k+1)<=K:
        ans.append(a[i]+b[j]+c[k])
      else:
        break
ans.sort(reverse=True)
for i in range(K):
  print(ans[i])
### BUGGY CODE ###

K = int(input())
firsta = 7 % K
seconda = 77 % K
if firsta == 0:
    print(1)
elif firsta == seconda:
    print(-1)
else:
    ans = 2
    preva = seconda
    while preva != firsta and preva != 0:
        preva = ((preva*10)+7) % K
        ans += 1
        if preva == firsta:
            ans = -1
    print(ans)

### FIXED CODE ###

K = int(input())
def check(k):
    aaa = 0
    prev = 7%k
    for i in range(0,k):
        aaa+=1
        if prev == 0:
            return(aaa)
        prev = (prev*10+7)%k
    return(-1)
print(check(K))
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
l = list()
r = list()
for i in range(q):
    l_i, r_i = map(int, input().split())
    l.append(l_i)
    r.append(r_i)

for i in range(q):
    s_i = s[l[i]-1:r[i]]
    print(s_i.count('AC'))


### FIXED CODE ###

def main():
    # n, q = map(int, input().split())
    # s = input()
    # # l = list()
    # # r = list()
    # s_list = list()
    # # s_tuple = tuple()
    # for _ in range(q):
    #     l_i, r_i = map(int, input().split())
    #     # l.append(l_i)
    #     # r.append(r_i)
    #     s_list.append(s[l_i - 1:r_i])
    #     # s_tuple = s_tuple + tuple(s[l_i - 1:r_i])
    # 
    # s_tuple = tuple(s_list)
    # 
    # for i in s_tuple:
    #     print(i.count('AC'))
    N, Q = map(int, input().split())
    S = input()
    cnt = [0] * (N + 1)
    for i in range(N):
        cnt[i + 1] = cnt[i] + (1 if S[i:i+2] == 'AC' else 0)
    for i in range(Q):
        l, r = map(int, input().split())
        print(cnt[r - 1] - cnt[l - 1])


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

n = int(input())
p = list(map(int,input().split()))
miss = 0
for i in range(n):
    s = p[0:i]
    sorted(s,reverse=True)
    for j in range(i):
        if p[i] > s[j]:
            miss += 1
            break

print(n-miss)

### FIXED CODE ###

n = int(input())
p = list(map(int,input().split()))
cnt = 0
t = p[0]

for i in range(n):
    if t >= p[i]:
        cnt += 1
        t = p[i]


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

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

def dd_cost(L):
    c = 0
    M = L[:]
    for i in range(len(L)):
        if L[i] < 0:
            L[i] = -1
        elif L[i] > 0:
            L[i] = 1
        else:
            L[i] = 0
    L = np.array(L)
    L = L[1:]-L[:-1]
    for i in range(len(L)):
        if L[i] < 0 or L[i] > 0:
            c += abs(M[i]) * 2
    c += abs(M[-1]) * 2
    print(c)

for i in range(len(A)):
    dd_cost(A[:i]+A[i+1:])


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
a = 0
cost = 0
for i in A:
    b = i
    cost += abs(a-b)
    a = b
cost += abs(A[-1])

ori = cost
for i in range(1, len(A)-1):
    cost += abs(A[i-1]-A[i+1])
    cost -= abs(A[i-1]-A[i])+abs(A[i+1]-A[i])
    print(cost)
    cost  = ori
### BUGGY CODE ###

n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
L=len(format(max(a),"b"))
s=[0]*L
for i in range(n):
  c=format(a[i], 'b').zfill(L)
  for j in range(len(c))[::-1]:
    s[j]+=int(c[j])
ans=0
for i in range(len(s))[::-1]:
  ans+=2**(i)*(s[L-i-1])*(n-s[L-i-1])
  ans%=mod
print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
s=[0]*61
for i in range(n):
  c=format(a[i], 'b')
  L=len(c)
  for j in range(L)[::-1]:
    s[L-j-1]+=int(c[j])
ans=0
for i in range(61):
  ans+=2**(i)*(s[i])*(n-s[i])
  ans%=mod
print(ans)
### BUGGY CODE ###

r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
from scipy.special import comb
ans=0
for i in range(r1,r2+1):
  for j in range(c1,c2+1):
    ans+=comb(i+j,i,exact=True)%mod
print(ans%mod)


### FIXED CODE ###

r1,c1,r2,c2=map(int,input().split())
mod=10**9+7
def comb(n,k,mod):
  if n<k:
    return 0
  if n-k<k:
    k=n-k
  c=1
  for x in range(n-k+1,n+1):
    c=(c*x)%mod
  d=1
  for x in range(1,k+1):
    d=(d*x)%mod
  c=c*pow(d,mod-2,mod)
  return c%mod
def f(i,j):
  return comb(i+j,i,mod)
ans=f(r2+1,c2+1)-f(r2+1,c1)-f(r1,c2+1)+f(r1,c1)
ans%=mod
print(ans)
### BUGGY CODE ###

a, b, k = (int(v) for v in input().split(" "))
for _ in range(k):
  if a > 0:
    a -= 1
  elif b > 0:
    b -= 1
  else:
    break
print(a, b)

### FIXED CODE ###

a, b, k = map(int, input().split(" "))
 
if a >= k:
  a -= k
else:
  a -= k
  b += a
  if b < 0:
    b = 0
  a = 0
 
print(a, b)
### BUGGY CODE ###

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

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

mod = 10**9+7
fact = [1]
for n in range(1, N+1):
    fact.append( fact[-1] * n % mod)
from copy import deepcopy as dcpy

def solve(S, X):
    n = len(S)

    if all( X < s for s in S):
        return fact[n] * X % mod
    if n == 1:
        return X % S[0] % mod

    ans = 0

    def popi(S,i):
        return S[:i] + S[i+1:]
    # s_holder = [ dcpy(S) for _ in range(n)]
    for i,s in enumerate(S):
        new_x = X % s
        # s_holder[i].pop(i)
        # ans = (ans + solve(s_holder[i], new_x)) % mod
        ans = (ans + solve(popi(S,i), new_x)) % mod
    return ans % mod

print( solve(S, X) % mod )
        




### FIXED CODE ###

N,X = map(int, input().split())
S = list(map(int,input().split()))

S.sort(reverse=True)
mod = 10**9+7
dp = [ [0] * (10**5+1) for _ in range(N+1)]
dp[0][X] = 1
for i in range(N):
    for j in range(0,10**5+1):
        dp[i+1][j] += dp[i][j] * (N-1-i) % mod
        dp[i+1][j% S[i]] += dp[i][j] 

        dp[i+1][j] %= mod
        dp[i+1][j%S[i]] %= mod
ans = 0
for j in range(0,10**5+1):
    ans = (ans + dp[N][j] * j % mod ) % mod

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

s = input()
s_list = [o for o in s]
count = 0
flag = True
while True:
    for i in range(len(s_list)-1):
        if s_list[i] == 'B' and s_list[i+1] == 'W':
            s_list[i] = 'W'
            s_list[i+1] = 'B'
            flag = False
            count += 1
    if flag:
        print(count)
        exit()
    else:
        flag = True

### FIXED CODE ###

import math

def bitsum(bit,i):
    s = 0
    while i > 0:
        s += bit[i]
        i -= i&(-i)
    return s

def bitadd(bit,i,x):
    while i <= n:
        bit[i] += x
        i += i&(-i)
    return bit

s = input()
a = [2 if o == 'B' else 1 for o in s]
n = int(len(a))

n_ = int(math.log2(n)) + 1
bit = [0] * (2**n_)
bit.insert(0,0)

ass = 0
for j in range(n):
    ass += j-bitsum(bit,a[j])
    bit = bitadd(bit,a[j],1)
print(ass)
### BUGGY CODE ###

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

def main():
    N, Q = map(int, input().split())
    link = [[] for _ in range(N)]
    a = [None] * (N-1)
    b = [None] * (N-1)
    for i in range(N-1):
        a[i], b[i] = map(int, input().split())

    cost = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        cost[p-1] += x

    for i in range(N-1):
        link[a[i]-1].append([b[i]-1, cost[i]])
        link[b[i]-1].append([a[i]-1, cost[i]])

    def dfs(v, c, p):
        for nv in link[v]:
            if nv[0] == p:
                continue
            cost[nv[0]] = c + cost[nv[0]]
            dfs(nv[0], cost[nv[0]], v)
        return

    dfs(0, cost[0], -1)

    print(*cost)

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

def dfs(v, p):
    for u in link[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v)

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

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

dfs(0, -1)

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

import collections
s = input()
p = 0
dp = [0]
for i in range(len(s)):
    p = p + (int(s[-1 - i]) * (10 ** (i)))
    dp.append(p % 2019)
t = collections.Counter(dp)
ans = 0
for i in t.values():
    ans += i * (i - 1) / 2
print(int(ans))

### FIXED CODE ###

s = input()[::-1]
p = 0
dp = [0] * 2019
dp[0] = 1
d = 1
for i in s:    
    p = (int(i) * d + (p)) % 2019
    dp[p] += 1
    d *= 10
    d = d % 2019
ans = 0
for i in dp:
    ans += i * (i - 1) // 2
print(ans)
### BUGGY CODE ###

def main():
    S = list(input())
    Q = int(input())
    l = [list(input().split(' ')) for _ in range(Q)]

    for li in l:
        if int(li[0]) == 1: # 前後反転
            S = S[::-1]
        
        elif int(li[0]) == 2: # 追加, li[1] == 1 => li[2]を先頭に，li[1] == 2 => li[2]を末尾
            if int(li[1]) == 1:
                S.insert(0, li[2])
            elif int(li[1]) == 2:
                S.append(li[2])
        # print(S)
    print(''.join(S))

main()

### FIXED CODE ###

from collections import deque

def main():
    S = list(input())
    Q = int(input())
    l = [list(input().split(' ')) for _ in range(Q)]

    d = deque(S)

    FLAG = False

    for li in l:
        if int(li[0]) == 1: # 前後反転
            if FLAG == True:
                FLAG = False
            else:
                FLAG = True
        
        elif int(li[0]) == 2: # 追加, li[1] == 1 => li[2]を先頭に，li[1] == 2 => li[2]を末尾
            if int(li[1]) == 1:
                if FLAG == True:
                    d.append(li[2])
                else:
                    d.appendleft(li[2])
            elif int(li[1]) == 2:
                if FLAG == True:
                    d.appendleft(li[2])
                else:
                    d.append(li[2])

    S = ''.join(d)
    if FLAG:
        S = S[::-1]
    print(S)


main()
### BUGGY CODE ###

N, K = [int(x) for x in input().split()]
Array = list()
a = 0
b = 0
for i in range(N):
	a, b = [int(x) for x in input().split()]
	Array.extend([a]*b)
	if len(Array) > K:
		Array.sort()
		Array = Array[:K]
	
print(Array[K - 1])

### FIXED CODE ###

from operator import itemgetter

N, K = [int(x) for x in input().split()]
Array = list()
A = list()
count = 0
ans = 0
for i in range(N):
	A.append([int(x) for x in input().split()])

A.sort(key=itemgetter(0))
for i in range(N):
	count += A[i][1]
	if count >= K:
		ans = A[i][0]
		break
		
print(ans)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[[0]*(k+1) for _ in range(n+1)]
mod=10**9+7
#i人目までに0個配る方法は1通り
for i in range(n+1):
  dp[i][0]=1

for i in range(1,n+1):
  for j in range(1,k+1):
    tmp=dp[i - 1][j] + dp[i][j - 1]
    if tmp>=mod:
      tmp%=mod
    dp[i][j]=tmp
    if j-a[i-1]-1>=0:
      tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
  #print(dp)   
print(dp[n][k]%mod)


### FIXED CODE ###

import sys
from itertools import accumulate

def main():
  input=sys.stdin.readline
  n,k=map(int,input().split())
  A=list(map(int,input().split()))
  mod=10**9+7
  dp=[0]*(k+1)
  dp[0]=1
  for a in A:
    dp=list(accumulate(dp))
    #print("accumulated",dp)
    for j,d in enumerate(dp[:k-a],start=a+1):
      dp[j]-=d
    dp=[dpi%mod for dpi in dp]
    #print(dp)
  print(dp[k])
"""
def main():
  dp=[[0]*(k+1) for _ in range(n+1)]
  mod=1000000007
  #i人目までに0個配る方法は1通り
  #for i in range(n+1):
  #  dp[i][0]=1
  for i in range(0,n+1):
    for j in range(0,k+1):
      if i==0 and j==0:
        dp[i][j]=1
        break
      if j==0:
        dp[i][j]=1
        continue
      tmp=dp[i - 1][j] + dp[i][j - 1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
      if j-a[i-1]-1>=0:
        tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
        if tmp>=mod:
          tmp%=mod
        dp[i][j]=tmp
    #print(dp)   
  print(dp[n][k])"""
main()
### BUGGY CODE ###

# 解説AC
# 参考1: https://drken1215.hatenablog.com/entry/2019/09/29/103500
# 参考2: https://www.slideshare.net/chokudai/wap-atcoder4


n, m = map(int, input().split())
A, B, C = [], [], []
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    c = list(map(int, input().split()))
    now = 0
    for i in range(b-1, -1, -1):
        now += 2**(c[i]-1)
    C.append(now)

INF = 10**9
DP = [[INF for _ in range(2**n)] for _ in range(m+1)]
DP[0][0] = 0

for i in range(m):
    for j in range(2**n):
        c = C[i]
        # 鍵を使用しない
        DP[i+1][j] = min(DP[i][j], DP[i+1][j])
        # 鍵を使用する
        nex = j | c
        DP[i+1][nex] = min(DP[i+1][nex], DP[i][j]+A[i])

ans = 10**9
for i in range(m):
    ans = min(DP[i][-1], ans)

if ans == 10**9:
    ans = -1

print(ans)

### FIXED CODE ###

# 解説AC
# 参考1: https://drken1215.hatenablog.com/entry/2019/09/29/103500
# 参考2: https://www.slideshare.net/chokudai/wap-atcoder4


n, m = map(int, input().split())
A, B, C = [], [], []
for _ in range(m):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    c = list(map(int, input().split()))
    now = 0
    for i in range(b-1, -1, -1):
        now += 2**(c[i]-1)
    C.append(now)

INF = 10**9
DP = [[INF for _ in range(2**n)] for _ in range(m+1)]
DP[0][0] = 0

for i in range(m):
    for j in range(2**n):
        c = C[i]
        # 鍵を使用しない
        DP[i+1][j] = min(DP[i][j], DP[i+1][j])
        # 鍵を使用する
        nex = j | c
        DP[i+1][nex] = min(DP[i+1][nex], DP[i][j]+A[i])

ans = 10**9
for i in range(m):
    ans = min(DP[i][-1], ans)

if ans == 10**9:
    ans = -1

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

N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]

for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]

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

ans = [0 for i in range(N+1)]
vc = [1]
for i in range(N):
    vi = vc.pop(0)
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    vc += Ki_c[vi]

print(' '.join(map(str,ans[1:N+1])))

### FIXED CODE ###

N,Q = map(int,input().split())
Ki_p = [0 for i in range(N+1)]
Ki_c = [[] for i in range(N+1)]
Ki_co = [0 for i in range(N+1)]
 
for i in range(N-1):
    a,b = map(int,input().split())
    Ki_p[b] = a
    Ki_c[a] += [b]
 
for i in range(Q):
    p,x = map(int,input().split())
    Ki_co[p] += x
 
ans = [0 for i in range(N+1)]
q = {1}
for i in range(N):
    vi = q.pop()
    ans[vi] = Ki_co[vi] + ans[Ki_p[vi]]
    q |= set(Ki_c[vi])
    
print(' '.join(map(str,ans[1:N+1])))
### BUGGY CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()


S = input()

N = len(S) + 1

min_list = deque()
max_list = []
num = [-1]*N
if S[0] == "<":
	min_list.append(1)
	num[0] = 0
if S[-1] == ">":
	min_list.append(N - 2)
	num[N - 1] = 0
for i in range(1, N - 1):
	if S[i - 1] == ">" and S[i] == "<":
		min_list.append(i - 1)
		min_list.append(i + 1)
		num[i] = 0
	if S[i - 1] == "<" and S[i] == ">":
		max_list.append(i)

max_set = set(max_list)

while len(min_list) > 0:
	x = min_list.popleft()
	if x == 0:
		num[x] = num[x + 1] + 1
	elif x == N - 1:
		num[x] = num[x - 1] + 1
	elif not x in max_list:
		num[x] = max(num[x - 1], num[x + 1]) + 1
		if num[x - 1] == -1:
			min_list.append(x - 1)
		if num[x + 1] == -1:
			min_list.append(x + 1)

for x in max_list:
	num[x] = max(num[x - 1], num[x + 1]) + 1

print(sum(num))

### FIXED CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter

import sys
def input():
	return sys.stdin.readline().strip()


S = input()

N = len(S) + 1

min_list = deque()
max_list = []
num = [-1]*N
if S[0] == "<":
	min_list.append(1)
	num[0] = 0
if S[-1] == ">":
	min_list.append(N - 2)
	num[N - 1] = 0
for i in range(1, N - 1):
	if S[i - 1] == ">" and S[i] == "<":
		min_list.append(i - 1)
		min_list.append(i + 1)
		num[i] = 0
	if S[i - 1] == "<" and S[i] == ">":
		max_list.append(i)

while len(min_list) > 0:
	x = min_list.popleft()
	if x == 0:
		num[x] = num[x + 1] + 1
	elif x == N - 1:
		num[x] = num[x - 1] + 1
	elif not (S[x - 1] == "<" and S[x] == ">"):
		num[x] = max(num[x - 1], num[x + 1]) + 1
		if num[x - 1] == -1:
			min_list.append(x - 1)
		if num[x + 1] == -1:
			min_list.append(x + 1)

for x in max_list:
	num[x] = max(num[x - 1], num[x + 1]) + 1

print(sum(num))
### BUGGY CODE ###

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

ans = []
for i in range(n):
  ans.append(str(a.index(i + 1) + 1))
  
print(' '.join(ans))

### FIXED CODE ###

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

ans = [0] * n
for i in range(n):
  ans[a[i] - 1] = i + 1
  
print(' '.join(map(str, ans)))
### BUGGY CODE ###

import itertools
x = int(input())
l = [0,1,2,3,4,5]
k = x%100
n = x//100
ans = '0'
c = list(itertools.product(l,repeat = n))
for i in c:
    if sum(i)==k:
        ans = '1'
        break
print(ans)

### FIXED CODE ###

import itertools
x = int(input())
k = x%100
n = x//100
ans = 0
if n*5>=k and n!=0:
    ans = 1
print(ans)
### BUGGY CODE ###

import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0
ansx = []
ansy = []
ansy2 = []

for x, y in c.items():
    ansy.append((y*(y-1)//2))
    ansy2.append(y-1)
    ansx.append(x)
sumall = sum(ansy)

for i in A:
    print(sumall - ansy2[ansx.index(i)])


### FIXED CODE ###

import collections
import math

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
cnt = 0


sumall = 0
for x, y in c.items():
    sumall += (y*(y-1)//2)

for i in range(N):
    print(sumall - c[A[i]] + 1)