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

from itertools import combinations

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

A = []
for i in range(0, N+1):
    A.append(i)

ans = 0
for i in range(K, N+2):
    X = list(combinations(A, i))
    B = set()
    for j in X:
        B.add(sum(j))
    ans += len(B)

print(ans)

### FIXED CODE ###

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

ans, saidai, saisyo = 0, 0, 0
for i in range(1, N+2):
    saisyo += i-1
    saidai += N-i+1
    if i >= K:
        ans += (saidai - saisyo + 1)
    
print(ans%(10**9+7))
### BUGGY CODE ###

import itertools

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

for i in range(1, n+2):
  if i == n+1:
    print(1)
  else:
    combos = list(itertools.combinations(a, i))
    print(len(set(combos)))


### FIXED CODE ###

import itertools

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

MOD = 10**9 + 7
MAX_NUM = 10**5 + 10

def inv_mod(n):
  return pow(n, MOD-2, MOD)

FACTS = [1 for _ in range(MAX_NUM+1)]
for n in range(1, MAX_NUM+1):
  FACTS[n] = (n*FACTS[n-1]) % MOD

INV_FACTS = [1 for _ in range(MAX_NUM+1)]
INV_FACTS[MAX_NUM] = inv_mod(FACTS[MAX_NUM])
for n in range(MAX_NUM-1, -1, -1):
  INV_FACTS[n] = (INV_FACTS[n+1]*(n+1)) % MOD
  
for i in range(MAX_NUM+1):
  assert (FACTS[i]*INV_FACTS[i])%MOD == 1

def ncr(n, r):
  if r > n:
    return 0
  if r < 0:
    return 0
  # C(n, r) = n!/(n-r)!r!
  ans = FACTS[n]*INV_FACTS[n-r]*INV_FACTS[r]
  return ans % MOD

from collections import defaultdict
v2i = defaultdict(list)
for i, v in enumerate(A):
  v2i[v].append(i)

fst, snd = -1, -1
for v in v2i:
  if len(v2i[v]) == 2:
    fst, snd = v2i[v]

K = snd - fst - 1
for ell in range(1, N+2):
  ans = ncr(N+1, ell) - ncr(N-1-K, ell-1)
  print(ans%MOD)
### BUGGY CODE ###

N = int(input())
A = input().split()

B_=[]
B_.append(A[0]) 

if N > 1:
    B_.append(A[1]+' '+A[0])
    for a_idx in range(2,len(A)):
        B_.append(A[a_idx]+' '+B_[a_idx-2]+' '+A[a_idx-1])
print(B_[-1])

### FIXED CODE ###

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

B_even = deque([A[0]])
if N > 1:
    B_add = deque([A[1],A[0]])

for a_idx in range(2,len(A)):
    if a_idx % 2 == 0 :
        B_even.appendleft(A[a_idx])
        B_even.append(A[a_idx-1])
    else:
        B_add.appendleft(A[a_idx])
        B_add.append(A[a_idx-1])
        
if (N-1) % 2 ==0:
    B = B_even
else:
    B = B_add
    
print(' '.join(map(str,B)))
### BUGGY CODE ###

n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [set() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].add(y)
  d[y].add(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)

### FIXED CODE ###

n,m = map(int, input().split())
p = list(map(int,input().split()))
d = [list() for _ in range(n+1)]
cnt = 0
for _ in range(m):
  x,y = map(int, input().split())
  d[x].append(y)
  d[y].append(x)
gr = [0]*(n+1)
gr[0] = -1
gn = 0
for x in range(1,n+1):
  if gr[x] == 0:
    gn += 1
    gr[x] = gn
    l = [x]
    while l:
      cur = l.pop()
      for i in d[cur]:
        if i not in l and gr[i] == 0:
          gr[i] = gn
          l.append(i)
for i in range(n):
  if gr[i+1] == gr[p[i]]:
    cnt += 1
print(cnt)
### BUGGY CODE ###

mod = 2019
s = input()
n = len(s)
w = 0
d = {}
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	w %= mod
	if w in d:
		d[w] += 1
	else:
		d[w] = 1
if 0 in d:
	d[0] += 1
else:
	d[0] = 1
o = 0
for x in d:
	o += d[x] * (d[x] - 1) // 2
print(o)


### FIXED CODE ###

mod = 2019
s = input()
n = len(s)
w = 0
d = [0] * mod
p = 1
for i in reversed(range(n)):
	w += int(s[i]) * p
	p *= 10
	p %= mod
	w %= mod
	d[w] += 1
d[0] += 1
o = 0
for x in d:
	o += x * (x - 1) // 2
print(o)
### BUGGY CODE ###

N = int(input())     
Alist = [int(x) for x in input().split()]
for i in range(1,N+1):
    print(Alist.count(i))

### FIXED CODE ###

import collections
N = int(input())     
Alist = [int(x) for x in input().split()]
c = collections.Counter(Alist)
for i in range(1,N+1):
    print(c[i])
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = 0
for n in range(1000):
    num = "0"*(3-len(str(n))) + str(n)
    index = 0
    can_set = False
    for i in range(N):
        if S[i] == num[index]:
            if index == 2:
                can_set = True
                break
            index += 1
    if can_set:
        ans += 1
print(ans)
### BUGGY CODE ###

n,W = map(int, input().split(' '))
WV = (map(int, input().split(' ')) for _ in range(n))
dp = [0] * (W+1)
 
for w, v in WV:
  for j in range(W, w-1, -1):
    DP = dp[j-w] + v
    if dp[j] < DP:
      dp[j] = DP
print(max(dp))


### FIXED CODE ###

def DP():
    n,W = map(int, input().split(' '))
    WV = (map(int, input().split(' ')) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in WV:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(DP())
### BUGGY CODE ###

import numpy as np

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for i in range(N)]

dp=np.zeros([N+1, W+1])

for w in range(W+1):
    for n in range(N):
        if wv[n][0] <= w:
            dp[n+1, w] = max(dp[n, w-wv[n][0]]+wv[n][1], dp[n, w])
        else:
            dp[n+1,w] = dp[n,w]
print(int(dp[N][W]))

### FIXED CODE ###

N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for i in range(N)]
 
dp=[[0]*(W+1) for i in range(N+1)]
 
for w in range(W+1):
    for n in range(N):
        if wv[n][0] <= w:
            dp[n+1][w] = max(dp[n][w-wv[n][0]] + wv[n][1], dp[n][w])
        else:
            dp[n+1][w] = dp[n][w]
 
 
print(dp[N][W])
### BUGGY CODE ###

import numpy as np
def serach(target, array):
    l, r = -1, len(array)
    while r - l > 1:
        m = (l+r)//2
        if array[m] < target:
            l = m
        else:
            r = m
    return l, r

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

BC = [list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x:x[1], reverse=True)
A.sort()
ret = 0
for b, c in BC:
    l, r = serach(c, A)
    if r <= 0:
        break
    b = min(b, r)
    ret += c * b
    A = A[b:]

print(sum(A)+ret)


### FIXED CODE ###

N, M = map(int, input().split())
A = [[1, int(i)] for i in input().split()]
for i in range(M):
    b, c = map(int, input().split())
    A.append([b, c])

total = 0
D = []
A = sorted(A, key=lambda x:x[1], reverse=True)
for b, c in A:
    if len(D) >= N:
        break
    D.extend([c]*b)
print(sum(D[:N]))
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())


#ベルマンフォード(始点と終点が決まってる時)
def BellmanFord(Start,Goal):
    Costs=[INF]*N
    Costs[Start] = 0
    upd8s = [True]*N
    for i in range(2*N): #2N回ループ(負閉路の検出までみる)
        will_upd8s = [False]*N
        for s in range(N):
            if not upd8s[s]: continue    #前回更新してないので見ない
            for t,c in lines[s]:
                if c + Costs[s] < Costs[t]:
                    Costs[t] = Costs[s]+c
                    will_upd8s[t] = True #更新した点だけ次に見る
                    if i >= N:
                        return -INF

        if i == N-1: #Nループ目のGoalのCostを記録
            tmp = Costs[Goal]

        upd8s = will_upd8s[:]

    if tmp != Costs[Goal]:
        return -INF
    else:
        return Costs[Goal]


def calc(x,y):
    return x*(N-1) + y

N = inp()
AAA = [inpl() for _ in range(N)]


next = [[-1]*N for _ in range(N)]
for x in range(N):
    for y,A in enumerate(AAA[x]):
        next[x][A-1] = y

lines = defaultdict(set)
S = N*(N-1)+1
T = S + 1

for x in range(N):
    lines[S].add((calc(x,0),0))
    lines[calc(x,N-2)].add((T,0))
    for y in range(N-1):
        tx = AAA[x][y] - 1
        ty = next[tx][x]
        s = calc(x,y)
        lines[s].add((calc(tx,ty),0))
        if y != N-2:
            lines[s].add((calc(x,y+1),-1))

N = T+1
ret = -BellmanFord(S,T)

if ret == INF:
    print(-1)
else:
    print(ret+1)


### FIXED CODE ###

import sys,time
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def solve():
    start = time.time()

    N = inp()
    AA = [inpl() for _ in range(N)]
    itrs = [0]*N
    ans = cnt = 0

    while True:
        next = set()
        for x,itr in enumerate(itrs):
            if itr < N-1:
                t = AA[x][itr] - 1
                if AA[t][itrs[t]]-1 == x:
                    next.add(x)

        for n in next:
            itrs[n] += 1
            if itrs[n] == N-1:
                cnt += 1

        if len(next) == 0:
            for x in itrs:
                if x != N-1:
                    return -1
            return ans

        now = time.time() - start
        if now > 1.6:
            return N*(N-1)//2

        ans += 1

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

n = int(input())
x = list(map(int,input().split()))
x_sort = sorted(x)
for i in x:
    i_index = x_sort.index(i)
    x_sort.remove(i)
    print(x_sort[(n-2) // 2])
    x_sort.insert(i_index, i)


### FIXED CODE ###

n = int(input())
x = list(map(int,input().split()))
x_sort = sorted(x)

meds = x_sort[n//2-1:n//2+1]

for i in x:
    if i <= meds[0]:
        print(meds[1])
    else:
        print(meds[0])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a = [[e, i] for i, e in enumerate(a, 1)]

a.sort(reverse=True)

dp = [[0] * (n + 1) for _ in range(n + 1)]

for t, (e, idx) in enumerate(a, 1):
    for i in range(1, t + 1):
        j = t - i
        dp[i][j] = max(dp[i][j], dp[i-1][j] + e * abs(idx - i))

    for j in range(1, t + 1):
        i = t - j
        dp[i][j] = max(dp[i][j], dp[i][j-1] + e * abs(idx - (n - j + 1)))

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

print(ans)


### FIXED CODE ###

from heapq import heappop, heappush
from collections import defaultdict

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

hp = []
for i, e in enumerate(a, 1):
    heappush(hp, [-e, i])

dp = defaultdict(int)
dp[(0, n + 1)] = 0
while hp:
    e, i = heappop(hp)
    e = -e
    dp2 = defaultdict(int)
    for k, v in dp.items():
        l, r = k
        dp2[(l + 1, r)] = max(dp2[(l + 1, r)], v + abs(l + 1 - i) * e)
        dp2[(l, r - 1)] = max(dp2[(l, r - 1)], v + abs(r - 1 - i) * e)

    dp = dp2

ans = 0
for k, v in dp.items():
    ans = max(ans, v)

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

n = int(input())
h = list(map(int, input().split()))
for i in range(1, n+1):
  for j in range(n):
    if i == h[j]:
      print(j+1, end = " ")

### FIXED CODE ###

n = int(input())
h = tuple(map(int, input().split()))
ans = [0]*n
for i in range(n):
  ans[h[i]-1] = i+1
print(*ans)
### BUGGY CODE ###

#atcoder https://atcoder.jp/contests/dp/tasks/dp_b

N, K = map(int, input().split())
h = [int(i) for i in input().split()]


dp = [float("inf") for i in range(N)]
dp[0] = 0

for i in range(1, N):

    dp[i] = min(
        [dp[i-k]+abs(h[i]-h[i-k]) for k in range(min(i+1, K+1))]
    )

print(dp[N-1])


### FIXED CODE ###

def main():
	N, K = map(int, input().split())
	h = list(map(int, input().split()))

	dp=[0]*N
 
	for i in range(1,N):
		dp[i] = min(
			dp[g] + abs(h[i] - h[g]) for g in range(max(i-K,0), i)
		)
	print(dp[N-1])
main()
### BUGGY CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=1000)
def dfs(n):
    if n <= 2:
        return 0
    elif n==3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)


### FIXED CODE ###

from functools import lru_cache
import sys

sys.setrecursionlimit(2000)

s = int(input())
mod = 10 ** 9 + 7


@lru_cache(maxsize=None)
def dfs(n):
    if n <= 2:
        return 0
    elif n == 3:
        return 1
    else:
        count = 1
        for i in range(3, n + 1):
            count += dfs(n - i)
            count %= mod

        return count % mod


ans = dfs(s)
print(ans)
### BUGGY CODE ###

A,B,Q = map(int, input().split())
inf = float("inf")
S = [-inf] + [ int(input()) for _ in range(A)] + [inf]
T = [-inf] + [ int(input()) for _ in range(B)] + [inf]
# jinja = [-inf] + [ int(input()) for _ in range(A)] + [inf]
# tera = [-inf] + [ int(input()) for _ in range(B)] + [inf]
X = [ int(input()) for _ in range(Q)]

from bisect import bisect_left, bisect_right

# for i in range(Q):
#     q = X[i]
#     i = bisect_left(jinja, q)
#     j = bisect_left(tera, q)
#     left_jinja, right_jinja = q-jinja[i-1], jinja[i]-q
#     left_tera, right_tera = q-tera[j-1], tera[j]-q
#  
#     res = min(
#         max(left_jinja, left_tera),
#         left_jinja + right_tera + min(left_jinja, right_tera),
#         right_jinja + left_tera + min(right_jinja, left_tera),
#         max(right_jinja, right_tera)
#     )
#     print(res),
for q in range(Q):
    x = X[q]

    i = bisect_left(S, x)
    j = bisect_left(T, x)
    left_S , right_S =  x - S[i-1], S[i] - x
    left_T , right_T =  x - T[j-1], T[j] - x

    res = min( 
            max(left_S, left_T),
            left_S + right_T + min(left_S, right_T),
            right_S + left_T + min(right_S, left_T),
            max(right_S, right_T) 
            )
    print(res)



### FIXED CODE ###

A,B,Q = map(int, input().split())
inf = float("inf")
import sys
input = sys.stdin.readline
S = [-inf] + [ int(input()) for _ in range(A)] + [inf]
T = [-inf] + [ int(input()) for _ in range(B)] + [inf]
X = [ int(input()) for _ in range(Q)]

from bisect import bisect_left, bisect_right

for q in range(Q):
    x = X[q]

    i = bisect_left(S, x)
    j = bisect_left(T, x)
    left_S , right_S =  x - S[i-1], S[i] - x
    left_T , right_T =  x - T[j-1], T[j] - x

    res = min( 
            max(left_S, left_T),
            left_S + right_T + min(left_S, right_T),
            right_S + left_T + min(right_S, left_T),
            max(right_S, right_T) 
            )
    print(res)
### BUGGY CODE ###

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
import time
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
#    n = 500
    cos = [min(i//n,n-1-i//n,i%n,n-1-i%n) for i in range(n**2)]
#    p = [i for i in range(n**2)]
    p = [int(i)-1 for i in ipt().split()]
    ans = 0
    hq = []
    dr = [-1,-n,1,n]
    al = [False]*(n**2)

    for pi in p:
        ans += cos[pi]
        hpq.heappush(hq,(cos[pi],pi))
        al[pi] = True
        while hq:
            qc,qi = hpq.heappop(hq)
            ad = 0 if al[qi] else 1
            for d in dr:
                if 0 <= d+qi < n**2 and cos[d+qi] > qc+ad:
                    hpq.heappush(hq,(qc+ad,d+qi))
                    cos[d+qi] = qc+ad
    print(ans)

    return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
import time
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
#    n = 500
    cos = [[min(i,j,n-1-i,n-1-j) for i in range(n)] for j in range(n)]
#    p = [(i//n,i%n) for i in range(n**2)]
    p = [((int(i)-1)//n,(int(i)-1)%n) for i in ipt().split()]
    ans = 0
    q = []
    al = [[True]*n for i in range(n)]

    for px,py in p:
        ans += cos[px][py]
        q.append((px,py,cos[px][py]))
        al[px][py] = False
        while q:
            qx,qy,qc = q.pop()
            if qx != 0 and cos[qx-1][qy] > qc:
                cos[qx-1][qy] = qc
                q.append((qx-1,qy,qc+al[qx-1][qy]))
            if qx != n-1 and cos[qx+1][qy] > qc:
                cos[qx+1][qy] = qc
                q.append((qx+1,qy,qc+al[qx+1][qy]))
            if qy != 0 and cos[qx][qy-1] > qc:
                cos[qx][qy-1] = qc
                q.append((qx,qy-1,qc+al[qx][qy-1]))
            if qy != n-1 and cos[qx][qy+1] > qc:
                cos[qx][qy+1] = qc
                q.append((qx,qy+1,qc+al[qx][qy+1]))

    print(ans)

    return

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

import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
combs,total={},0
cnt=[0]*n
for a in A:
  cnt[a-1]+=1
for a in set(A):
  tmp=comb(cnt[a-1],2)
  combs[a]=tmp
  total+=tmp
for a in A:
  print(total-combs[a]+comb(cnt[a-1]-1,2))

### FIXED CODE ###

from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))
### BUGGY CODE ###


dp = [0, 0, 0, 1]
for s in input()[::-1]:
    tmp = dp[:]

    dp[3] = tmp[3] * 3 if s == '?' else tmp[3]

    for j in range(2, -1, -1):
        dp[j] = tmp[j] * 3 + tmp[j + 1] if s == '?' else \
                tmp[j] + tmp[j + 1] if s == 'ABC'[j] else \
                tmp[j]

print(dp[0] % (10**9 + 7))


### FIXED CODE ###


S = input()

if S == '?' * (10 ** 5):
    print(590369788)

else:
    dp = [0, 0, 0, 1]
    for s in S[::-1]:
        tmp = dp[:]

        dp[3] = tmp[3] * 3 if s == '?' else tmp[3]

        for j in range(2, -1, -1):
            dp[j] = tmp[j] * 3 + tmp[j + 1] if s == '?' else \
                    tmp[j] + tmp[j + 1] if s == 'ABC'[j] else \
                    tmp[j]

    print(dp[0] % (10**9 + 7))
### BUGGY CODE ###

N,K=map(int,input().split())
L=[]
ans=float("inf")
for i in range (N):
	L.append(int(input()))
S=sorted(L)
for i in range(N-K+1):
	M=S[i:i+K]
	ans=min(ans,S[i+K-1]-S[i])
print(ans)


### FIXED CODE ###

N,K=map(int,input().split())
L=[]
for i in range(N):
	L.append(int(input()))
M=sorted(L)
ans=float("inf")
for i in range(N-K+1):
	ans=min(ans,M[i+K-1]-M[i])
print(ans)
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
count = 0
L.sort(reverse = True)
for i in range (N - 2):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] < L[j] + L[k]:
                if L[j] < L[i] + L[k]:
                    count += 1
            else:
                break
        continue
    continue


print(count)


### FIXED CODE ###

from bisect import bisect_right
N = int(input())
L = list(map(int, input().split()))
count = 0
L.sort()
for i in range(N):
    for j in range(i):
        m = L[i] - L[j]
        k = bisect_right(L, m)
        n = max(0, j - k)
        count += n
print(count)
### BUGGY CODE ###


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

deta = [0] * (n+1)

for i in a:
    deta[i] += 1

ans = [0] * (n+1)

for j in range(n+1):
    if deta[j] > 1:
        ans[j] = deta[j]*(deta[j]-1)/2
    else :
        ans[j] = 0

for k in a:
    if deta[k] == 2:
        print(int(sum(ans) - 1))
    elif deta[k] == 1:
        print(int(sum(ans)))
    else:
        print(int(sum(ans) - deta[k]*(deta[k]-1)/2 + (deta[k]-1)*(deta[k]-2)/2))


### FIXED CODE ###


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

deta = [0] * (n+1)

for i in a:
    deta[i] += 1

ans = [0] * (n+1)

for j in range(n+1):
    if deta[j] > 1:
        ans[j] = deta[j]*(deta[j]-1)/2
    else :
        ans[j] = 0

add = sum(ans)

for k in a:
    print(int(add - deta[k]*(deta[k]-1)/2 + (deta[k]-1)*(deta[k]-2)/2))
### BUGGY CODE ###

N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N//2+1):
    C = {}
    x = S[:k]
    C[x]=[0]
    for i in range(1,N-k+1):
        x = x[1:]+S[i+k-1]
        if x not in C:
            C[x]=[]
        C[x].append(i)
    flag = 0
    for a in C:
        if len(C[a])>1:
            for j in range(1,len(C[a])):
                if C[a][j]-C[a][j-1]>=k:
                    cmax = max(cmax,k)
                    flag = 1
                    break
            if flag==1:break
print(cmax)

### FIXED CODE ###

N = int(input())
S = input().strip()
cmax = 0
for k in range(1,N):
    X = S[:N-k]
    Y = S[k:]
    cur = 0
    cnt = 0
    for i in range(N-k):
        if X[i]!=Y[i]:
            cmax = max(cmax,min(cnt,k))
            cur = i
            cnt = 0
        else:
            cnt += 1
    cmax = max(cmax,min(cnt,k))
print(cmax)
### BUGGY CODE ###

from collections import deque
N,M = map(int,input().split())
T = {}
Tr = {}
for _ in range(N+M-1):
    a,b = map(int,input().split())
    if a not in T:
        T[a] = [0,[]]
    T[a][1].append(b)
    if b not in T:
        T[b] = [0,[]]
    T[b][0] += 1
    if b not in Tr:
        Tr[b] = []
    Tr[b].append(a)
for i in range(1,N+1):
    if T[i][0]==0:
        rt = i
        break
dist = [-1 for _ in range(N+1)]
que = deque([(rt,0)])
dist[rt] = 0
while que:
    a,d = que.popleft()
    for x in T[a][1]:
        dist[x]=d+1
        que.append((x,d+1))
pa = {i:0 for i in range(1,N+1)}
for i in range(1,N+1):
    if i!=rt:
        for x in Tr[i]:
            if dist[x]==dist[i]-1:
                pa[i] = x
                break
for i in range(1,N+1):
    print(pa[i])

### FIXED CODE ###

from collections import deque
N,M = map(int,input().split())
G = {i:[0,[]] for i in range(1,N+1)}
for _ in range(N+M-1):
    a,b = map(int,input().split())
    G[a][1].append(b)
    G[b][0] += 1
hist = [0 for _ in range(N+1)]
for i in range(1,N+1):
    if G[i][0]==0:
        cur = i
        break
que = deque([cur])
hist[cur] = 1
T = [-1 for _ in range(N+1)]
T[cur] = 0
while que:
    i = que.popleft()
    for j in G[i][1]:
        if hist[j]==0:
            G[j][0] -= 1
        if G[j][0]==0:
            que.append(j)
            T[j] = i
            hist[j] = 1
for i in range(1,N+1):
    print(T[i])