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

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
import numpy as np

def main():
	h,w=map(int,input().split())
	AB=np.array(read().split(), np.int64)
	
	
	A=AB[:h*w]
	B=AB[h*w:]
	
	A=np.reshape(A, (h,w))
	B = np.reshape(B, (h, w))
	
	G=abs(A-B)
	
	li=[[[]for i in range(w)] for j in range(h)]
	for i in range(h):
		for j in range(w):
			if i==j==0:
				li[i][j].append(G[i][j])
			elif i==0:
				for k in li[i][j-1]:
					li[i][j].append(abs(k-G[i][j]))
					li[i][j].append(abs(k + G[i][j]))
			elif j==0:
				for k in li[i-1][j]:
					li[i][j].append(abs(k-G[i][j]))
					li[i][j].append(abs(k + G[i][j]))
			else:
				for k in li[i-1][j]:
					li[i][j].append(abs(k-G[i][j]))
					li[i][j].append(abs(k + G[i][j]))
				for k in li[i][j-1]:
					li[i][j].append(abs(k-G[i][j]))
					li[i][j].append(abs(k + G[i][j]))
			s=set(li[i][j])
			li[i][j]=sorted(list(s))
			
	print(min(li[h-1][w-1]))
	
if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	h, w = map(int, input().split())
	
	G = [[0] * w for i in range(h)]
	A = [0]*h
	B = [0]*h
	
	for i in range(h):
		A[i] = list(map(int, input().split()))
	for i in range(h):
		B[i] = list(map(int, input().split()))
	
	for i in range(h):
		for j in range(w):
			G[i][j]=abs(A[i][j]-B[i][j])

	M = (h + w) * 80

	li = [[[0] * M for i in range(w)] for j in range(h)]
	
	li[0][0][G[0][0]] = 1
	for i in range(h):
		for j in range(w):
			for k in range(M):
				
				if li[i][j][k] == 1:
					if i < h - 1:
						li[i + 1][j][abs(k - G[i+1][j])] = 1
						li[i + 1][j][abs(k + G[i+1][j])] = 1
					if j < w - 1:
						li[i][j + 1][abs(k - G[i][j+1])] = 1
						li[i][j + 1][abs(k + G[i][j+1])] = 1

	for i in range(M):
		if li[h-1][w - 1][i] == 1:
			print(i)
			exit(0)


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

#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-Prison.py
#
n, m = map(int, input().split())
can_through = [True for _ in range(n)]
cnt = 0

for i in range(m):
    l, r = map(int, input().split())
    for j in range(1, n+1):
        if l <= j <= r:
            pass
        else:
            can_through[j-1] = False
    # print(can_through)

for j in range(n):
    if can_through[j]:
        cnt += 1

print(cnt)


### FIXED CODE ###

N, M = map(int, input().split())
ans = 0
L, R = 0, 100000

for i in range(M):
    Ltmp, Rtmp = map(int, input().split())
    L, R = max(L, Ltmp), min(R, Rtmp)

print(max(0, R - L + 1))
### BUGGY CODE ###

def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        _a = list(map(lambda x: int(x)-1, input().split()))
        A.append(_a)
    ptrs = [0 for _ in range(N)]
    day = 0
    while True:
        todays_players = set()
        matched = False
        if all(map(lambda x: x==N-1, ptrs)):
            break
        #print("------")
        for home in range(N):
            if ptrs[home] == N-1:
                continue
            away = A[home][ptrs[home]]
            if ptrs[away] == N-1:
                continue
            #print(home, away)
            away_opp = A[away][ptrs[away]]
            if home in todays_players or away in todays_players:
                continue
            if home == away_opp:
                ptrs[home] += 1
                ptrs[away] += 1
                todays_players.add(home)
                todays_players.add(away)
                matched = True
        #print(ptrs)
        if matched:
            day += 1
        else:
            day = -1
            break
    print(day)





if '__main__' == __name__:
    resolve()


### FIXED CODE ###

def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        _a = list(map(lambda x: int(x)-1, input().split()))
        A.append(_a)
    ptrs = [0 for _ in range(N)]
    day = 0
    players = set([i for i in range(N)])
    finished = set()
    yest_players = set([i for i in range(N)])
    while True:
        todays_players = set()
        matched = False
        if len(finished) == N:
            break
        #print("------")
        for home in yest_players:
            if home in finished:
                continue
            away = A[home][ptrs[home]]
            if away in finished:
                continue
            #print(home, away)
            away_opp = A[away][ptrs[away]]
            if home in todays_players or away in todays_players:
                continue
            if home == away_opp:
                ptrs[home] += 1
                ptrs[away] += 1
                todays_players.add(home)
                todays_players.add(away)
                matched = True
                if ptrs[home] == N-1:
                    finished.add(home)
                if ptrs[away] == N-1:
                    finished.add(away)
        yest_players = todays_players
        #print(ptrs)
        if matched:
            day += 1
        else:
            day = -1
            break
    print(day)





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

A,B,C,D = map(int, input().split())
STOP = ""
a = 0
while STOP != "STOP":
    A = A - B
    D = D - C
    if A <= 0:
        a = 1
    if D <= 0:
        a = 2
    else:
        continue
if a == 1:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

A,B,C,D = map(int, input().split())
S = 0
while S != 1:
    C = C - B
    A = A - D
    if C <= 0:
        S = 1
        print("Yes")
    elif A <= 0:
        S = 1
        print("No")
    else:
        continue
### BUGGY CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))

#print("c:",c)
#print(p)
#print("s:",s)

for x in s:
#    print(x)
    t = x * 2
#    print("t:",t)
    while t <= 10 ** 6:
        p[t] = False
        t += x
#        print("t_inner:",t)
ans = 0

#print("a:",a)
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    t = x * 2
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)
### BUGGY CODE ###

from collections import Counter
import copy

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

cnum = []
ans = 0

for k in range(1,n+1):
    cans = []
    dammy = copy.copy(a)
    del dammy[k-1]
    c = Counter(dammy)
    cnum = [c[i] for i in c if c[i] >=2]
    for j in cnum:
        cans.append(j*(j-1)//2)
    print(sum(cans))

### FIXED CODE ###

from collections import Counter

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

c = Counter(a)
total = sum([v*(v-1)//2 for v in c.values()])
for i in a:
    print(total-(c[i]-1))
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
i=0
for i in range(N):
    temp=A[i]
    del A[i]
    print(max(A))
    A.insert(i,temp)
    i += 1


### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
B=sorted(A,reverse=True)
maxA=B[0]
secondA=B[1]
i=0
for i in range(N):
    if A[i] == maxA:
        print(secondA)
    else:
        print(maxA)
    i += 1
### BUGGY CODE ###

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

from collections import defaultdict
E = defaultdict(list)

for _ in range(M):
  l,r,d = map(int,input().split())
  E[l-1].append((r-1,d))
  E[r-1].append((l-1,-d))

unvisited = set(range(N))
locations = [None]*N
while unvisited:
  s = next(iter(unvisited))
  locations[s] = 0
  stack = [s]

  while stack:
    v = stack.pop()
    unvisited.discard(v)
    p = locations[v]

    for u,d in E[v]:
      if locations[u] is None:
        locations[u] = p+d
        stack.append(u)
      elif locations[u] != p+d:
        print('No')
        exit()

print('Yes')


### FIXED CODE ###

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

from collections import defaultdict
E = [list() for _ in range(N)]

for _ in range(M):
  l,r,d = map(int,input().split())
  E[l-1].append((r-1,d))
  E[r-1].append((l-1,-d))

locations = [None]*N

for s in range(N):
  if locations[s] is None:
    locations[s] = 0
    stack = [s]

    while stack:
      v = stack.pop()
      p = locations[v]

      for u,d in E[v]:
        if locations[u] is None:
          locations[u] = p+d
          stack.append(u)
        elif locations[u] != p+d:
          print('No')
          exit()


print('Yes')
### BUGGY CODE ###

import sys
input = sys.stdin.readline
if __name__ == '__main__':
    n = int(input())
    lis = []
    for i in range(n):
        k = input().rstrip('\n')
        if k in lis :
            pass
        else:
            lis.append(k)
    print(len(lis))


### FIXED CODE ###

if __name__ == '__main__':
    n = int(input())
    print(len(set(input().rstrip('\n') for _ in range(n))))
### BUGGY CODE ###

N=int(input())#奇数
A=[int(x) for x in input().split()]
B=[0]*N
#B[0]はA[0]-A[1]+A[2]-  -A[N-1]+A[N]
A=A*2
for i in range(N):
  for j in range(i,i+N):
    B[i] +=A[j]*((-1)**(j-i))
print(*B)

### FIXED CODE ###

N=int(input())#奇数
D=[int(x) for x in input().split()]#ダムの貯水量
Ame=[0]
for i in range(N):
  Ame[0] +=D[i]*((-1)**i)
for i in range(1,N):
  Ame +=[2*D[i-1]-Ame[i-1]]
print(*Ame)
### BUGGY CODE ###

def main():
    MOD=10**9+7
    s="0"+input()
    dp=[[0]*len(s)for i in range(13)]
    dp[0][0]=1
    for k,j in enumerate(s[1:]):
        for i in range(13):
            if dp[i][k]:
                I=str(i)
                if j=="?":
                    for r in range(10):
                        dp[int(I+str(r))%13][k+1]+=dp[i][k]%MOD
                else:
                    dp[int(I+j)%13][k+1]+=dp[i][k]%MOD
    print(dp[5][-1]%MOD)
    
if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    MOD=10**9+7
    s="0"+input()
    dp=[[0]*len(s)for i in range(13)]
    dp[0][0]=1
    for k,j in enumerate(s[1:]):
        for i in range(13):
            if dp[i][k]:
                if j=="?":
                    for r in range(10):
                        dp[(10*i+r)%13][k+1]+=dp[i][k]%MOD
                else:
                    dp[int(str(i)+j)%13][k+1]+=dp[i][k]%MOD
    print(dp[5][-1]%MOD)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

import bisect
A.sort()
for i in range(M):
    b, c = map(int, input().split())
    idx = bisect.bisect_left(A, c)
    #print(A[:idx], A[idx:])
    if idx > b:
        A = A[b:idx] + [c] * b + A[idx:]
    else:
        #print("a", b, idx)
        A = [c] * idx + A[idx:]
    #print(A)
print(sum(A))

### FIXED CODE ###


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

A.sort()

CB = []
for i in range(M):
    B, C = map(int, input().split())
    CB.append([C, B])
    
CB.sort(reverse=True)

idx = 0
c = 0
for i in range(N):
    if A[i] < CB[idx][0]:
        A[i] = CB[idx][0]
        c += 1
    if CB[idx][1] <= c:
        idx += 1
        c = 0
    if idx >= M:
        break
    #print(A)
        
print(sum(A))
### BUGGY CODE ###

import sys
if sys.version_info.minor < 5:
    from fractions import gcd
else:
    from math import gcd
import math

DEBUG = False

A, B = map(int, input().split())
g = gcd(A, B)
if DEBUG:
    print("gcd(A, B): {}".format(g))

ans = [1]
i= 2
while g >= i:
    if DEBUG:
        print("i: {}, g: {}".format(i, g))

    if g % i == 0:
        if DEBUG:
            print("This is a cd of A and B.")
        ans.append(i)

    while g % i == 0:
        g //= i

    i += 1

if DEBUG:
    print(ans)

print(len(ans))


### FIXED CODE ###

import sys
if sys.version_info.minor < 5:
    from fractions import gcd
else:
    from math import gcd
import math

DEBUG = False

A, B = map(int, input().split())
g = gcd(A, B)
if DEBUG:
    print("gcd(A, B): {}".format(g))

ans = [1]
i= 2
temp = g
while i <= int(-(-g**0.5//1))+1:
    if DEBUG:
        print("i: {}, g: {}".format(i, g))

    if temp % i == 0:
        if DEBUG:
            print("This is a cd of A and B.")
        ans.append(i)

    while temp % i == 0:
        temp //= i

    i += 1

if temp != 1:
    ans.append(temp)

if DEBUG:
    print(ans)

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

from sys import stdin
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        if data[1] == "1":
            S = data[2] + S
        else:
            S = S + data[2]
    else:
        S = S[::-1]
print(S)

### FIXED CODE ###

from sys import stdin
from collections import deque
S = (stdin.readline().rstrip())
Q = int(stdin.readline().rstrip())
cnt = 0
ccnt = 0
s = deque(["@"])
for i in range(Q):
    data = [(x) for x in stdin.readline().rstrip().split()]
    if data[0] == "2":
        if data[1] == "1":
            if cnt % 2 == 0:
                s.appendleft(data[2])
            else:
                s.append(data[2])
        else:
            if cnt % 2 == 0:
                s.append(data[2])
            else:
                s.appendleft(data[2])
    else:
        cnt += 1
s = "".join(s)
if cnt % 2 != 0:
    s = s[::-1]
if cnt % 2 != 0:
    S = S[::-1]
ans = s.replace("@",S)
print(ans)
### BUGGY CODE ###

import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
factorials = [1] + list(accumulate(range(1,n + 1), mul))

combinations = dict()
def combination(i, j):
    j = min(j, i - j)
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, range(j, i+1))

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    t = factorials[lt] * combination(n, gt) * factorials[gt]
    s += t
    result += d * s

print(int(result % (pow(10,9) + 7)))

### FIXED CODE ###

import sys
from itertools import count, accumulate
from operator import mul
from functools import reduce
lines = sys.stdin.readlines()

positions = [int(i) for i in lines[1].split(' ')]

distances = [ j - i for i, j in zip(positions, positions[1:])]

n = len(distances)
p = pow(10,9) + 7

factorials = [1] + list(accumulate(range(1,n + 1), lambda x, y: (x * y) % p))

combinations = dict()
def combination(i, j):
    j = min(j, i - j)
    if (i, j) in combinations:
        return combinations((i, j))
    else:
        return factorials[i] // (factorials [j] * factorials[i - j])

permutations = dict()
def permutation(i, j):
    if (i, j) in permutations:
        return permutations((i, j))
    else:
        return reduce(mul, range(j, i+1))

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n = n >> 1
    return res

s = 0
result = 0
for d, i in zip(distances, count(1)):
    lt = i - 1
    gt = n - i
    i_inv = modpow(i, p-2, p)
    t = factorials[n] * i_inv
    s += t
    result += d * s

print(int(result % (pow(10,9) + 7)))
### BUGGY CODE ###

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

ans = 1
for item in a:
  ans = ans * item
if ans > 1000000000000000000:
  ans = -1

print(ans)


### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int, input().split()))
  
  if 0 in A:
    print(0)
    return
  
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
  
main()
### BUGGY CODE ###

N=int(input())
q=[]
for i in range(N):
    q+=[list(input())]
    q[i].sort()
s=0
for j in range(N-1):
    for k in range(j+1,N):
        if q[j]==q[k]:
            s+=1
print(s)

### FIXED CODE ###

N=int(input())
q=[]  
for i in range(N):
    q+=[list(input())]
    q[i].sort()
q.sort() 
i=0
s=0
z=0 #総得点
while i<N-1:
    if q[i]!=q[i+1]:
        z+=((s*(s+1))//2)
        s=0
    else:
        s+=1
    i+=1
z+=((s*(s+1))//2)
print(z)
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
dp = [[0] * (K+1) for i in range(K+1)]
for i in range(min(A)):
    dp[0][i] = 1 # 負け
ans = "Second"
for i in range(K):
    for k in range(K+1):
        for x in A:
            if k + x <= K:   
                if (i == 0 or (i + 1) % 2 == 0) and dp[i][k] > 0:
                    dp[i+1][k+x] += 1
                elif (i + 1) % 2 == 1 and dp[i][k] == N:
                    dp[i+1][k+x] += 1
    if (i + 1) % 2 == 1 and dp[i+1][k] > 0:
        ans = "First"
print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
# firstが負けの状態を押し付け続けることが可能ならば勝ち
dp = [False]*(K+1)
# dp[i](0,A[0]) = False 
for i in range(K):
    if not dp[i]:
        for a in A:
            if i+a <= K:
                dp[i+a] = 1
print("First" if dp[K] else "Second")
### BUGGY CODE ###

def C(m):
    if xsort[m] > x[i]: 
        return True
    return False


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

for i in range(n):
    mb = 0
    lb = n
    m = (mb+lb) // 2
    xsort = sorted(x)
    for j in range(1000):
        if C(m):
            lb = m
        else: 
            mb = m
    if mb < n//2:
        print(xsort[n//2])
    else:
        print(xsort[n//2-1])

### FIXED CODE ###

N = int(input())
X = list(map(int, input().split()))
Y = sorted(X)
m1 = Y[N//2]
m2 = Y[N//2-1]
 
for i in range(N):
    if m1 > X[i]:
        print(m1)  # left
    else:
        print(m2)  # right
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
count = 0
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] and (L[i] + L[k]) > L[j] and (L[k] + L[j]) >L[i]:
                count += 1
print(count)


### FIXED CODE ###


import bisect
N = int(input())
L = list(map(int,input().split()))
count = 0
L.sort()
for i in range(N-2):
    for j in range(i+1,N-1):
        count += bisect.bisect(L,L[i]+L[j]-1)-j-1
print(count)
### BUGGY CODE ###

import numpy as np
import math

n, m = map(int, input().split(' '))
prices = np.array(list(map(int, input().split(' '))))

for _ in range(m):
    max_i = prices.argmax()
    prices[max_i] = prices[max_i] / 2

total = 0
for price in prices:
    total += math.floor(price)
print(total)

### FIXED CODE ###

import math
from heapq import heapify, heappush, heappop

n, m = map(int, input().split(' '))

# invert sign of p to get max value
prices = [ -p for p in map(int, input().split(' ')) ]
heapify(prices)

for _ in range(m):
    p = heappop(prices)
    heappush(prices, p / 2)

total = 0
while prices:
    total += math.floor(-heappop(prices))
print(total)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0] * (n + 1)
  for i in range(n):
    left_edge = max(0, i-a[i])
    right_edge = min(i + a[i] + 1, n)
    b[left_edge] += 1
    b[right_edge] -= 1
  for i in range(1, n+1):
    b[i] = b[i] + b[i-1]
  b.pop(n)
  if a == b:
    break
  a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))

### FIXED CODE ###

# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(k):
  b = [0] * (n + 1)
  for i in range(n):
    left_edge = max(0, i-a[i])
    right_edge = min(i + a[i] + 1, n)
    b[left_edge] += 1
    b[right_edge] -= 1
  for i in range(1, n+1):
    b[i] = b[i] + b[i-1]
  b.pop(n)
  if a == b:
    break
  a = b.copy()
print(' '.join(str(b[i]) for i in range(n)))
### BUGGY CODE ###

n,*h=map(int,open(0).read().split())
while len(h)>1:
    kh=[]
    for i in range(len(h)):
        mn = min(h)
        md=h[i]%mn
        if md!=0:
            kh.append(md)
        kh.append(mn)
    h=list(set(kh))
print(mn)

### FIXED CODE ###

def gcd(a,b):
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

n,*h=map(int,open(0).read().split())

gh=gcd(h[0],h[1])
for i in range(2,n):
    gh=gcd(h[i],gh)

print(gh)
### BUGGY CODE ###

import math

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
ans = 0
for i in range(n):
    if ans < math.factorial(a[-1]) // (math.factorial(a[i]) * math.factorial(a[-1] - a[i])):
        keep = a[i]
        ans = math.factorial(a[-1]) // (math.factorial(a[i]) * math.factorial(a[-1] - a[i]))
print(a[-1], keep)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
check = a[-1] / 2
MIN = 10 ** 10

for i in range(n - 1):
    if abs(a[i] - check) < MIN:
        keep = i
        MIN = abs(a[i] - check)

print(a[-1], a[keep])
### BUGGY CODE ###

a = int(input())
b = list(map(int, input().split()))
c = []
for i in range(a):
    d = False
    for j in range(len(c)):
        if c[j][0] == b[i]:
            c[j][1] += 1
            d = True
            break
    if not d:
        c.append([b[i], 1])
c = sorted(c, key=lambda x: x[0], reverse=True)
if len(c) <= 1:
    print(a // 2)
else:
    e = [c[0][0], c[1][0]] + b
    f = [c[1][0], c[0][0]] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))


### FIXED CODE ###

a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if str(b[i]) in c:
        c[str(b[i])] += 1
    else:
        c[str(b[i])] = 1
c = sorted(c.items(), key=lambda x: x[1], reverse=True)
if len(c) <= 1:
    print(a // 2)
elif len(c) == 2:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    ec = 0
    fc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
    print(min(ec, fc))
elif len(c) >= 3:
    e = [int(c[0][0]), int(c[1][0])] + b
    f = [int(c[1][0]), int(c[0][0])] + b
    g = [int(c[0][0]), int(c[2][0])] + b
    h = [int(c[1][0]), int(c[2][0])] + b
    j = [int(c[2][0]), int(c[0][0])] + b
    k = [int(c[2][0]), int(c[1][0])] + b

    ec = 0
    fc = 0
    gc = 0
    hc = 0
    jc = 0
    kc = 0
    for i in range(2, len(e)):
        if e[i] != e[i-2]:
            e[i] = e[i-2]
            ec += 1
        if f[i] != f[i-2]:
            f[i] = f[i-2]
            fc += 1
        if g[i] != g[i-2]:
            g[i] = g[i-2]
            gc += 1
        if h[i] != h[i-2]:
            h[i] = h[i-2]
            hc += 1
        if j[i] != j[i-2]:
            j[i] = j[i-2]
            jc += 1
        if k[i] != k[i-2]:
            k[i] = k[i-2]
            kc += 1
    print(min(ec, fc, gc, hc, jc, kc))
### BUGGY CODE ###

import collections
import math
import copy


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

for ai in a:
    cc = copy.deepcopy(c)
    cc[ai] -= 1
    print(sum(comb(v, 2) for v in cc.values()))

### FIXED CODE ###

import collections
import math


def comb(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


input()
a = list(map(int, input().split()))
c = collections.Counter(a)

summ = sum([comb(v, 2) for v in c.values()])
for ai in a:
    print(summ - c[ai] + 1)