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

from collections import deque

h,w = map(int,input().split())
s = [None]*h

for i in range(h):
    s[i] = input()

d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0

sx = []
sy = []
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sx.append(j)
            sy.append(i)
            d[i][j] = 0
            
            
def bfs():
    que = deque()
    for i in range(len(sx)):
        que.append([sy[i],sx[i]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] == 10000000:
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append([ny,nx])

    ans = 0
    for l in range(h):
        ans = max(max(d[l]) , ans)
    print(ans)
        
bfs()

### FIXED CODE ###

from collections import deque
 
h,w = map(int,input().split())
s = [None]*h
 
for i in range(h):
    s[i] = input()
 
d = [[10000000 for i in range(w)] for j in range(h)]
sharp = 0
 
sx = []
sy = []
            
dx = [1,0,-1,0]
dy = [0,1,0,-1]
 
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            sx.append(j)
            sy.append(i)
            d[i][j] = 0
            
            
def bfs():
    que = deque()
    ans = 0
    for i in range(len(sx)):
        que.append([sy[i],sx[i]])
    
    while que:
        y,x = que.popleft()
        
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            
            if 0<=nx and nx<w and 0<=ny and ny<h and d[ny][nx] == 10000000:
                if d[ny][nx] > d[y][x]+1:
                    d[ny][nx] = d[y][x]+1
                    que.append([ny,nx])
                    
                    if d[ny][nx] > ans:
                        ans = d[ny][nx]
    
    print(ans)
        
bfs()
### BUGGY CODE ###


import numpy as np

N,K = list(map(int, input().split()))
LRs = [list(map(int, input().split())) for _ in range(K)]



move_list = []
checker = np.zeros(N+1 ,dtype = int)
for LR in LRs:
#    for i in range(LR[0], LR[1]+1):
#        move_list.append(i)
    for i in range(LR[0], LR[1]+1):
        checker[i] = 1

#print(move_list)
#move_list.sort()

#print(move_list)
for index, check in enumerate(checker):
    if(check == 1):
        move_list.append(index)

#print(move_list)

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

for i in range(1, N+1):
    for j in move_list:
        if(i < j):
            break
#        print(i,j)
        dp[i] = (dp[i] +dp[i-j]) % 998244353

print(dp[N])

### FIXED CODE ###

import numpy as np

N,K = list(map(int, input().split()))
LRs = [list(map(int, input().split())) for _ in range(K)]

dp = np.zeros(N+2, dtype = int)
dp[1] = 1
dp[2] = -1

atai = 0
for i in range(1, N+2):
    atai += dp[i]
    for LR in LRs:
        if(i+LR[0] <= N):
            dp[i+LR[0]] = (dp[i+LR[0]] + atai) % 998244353
        if(i+LR[1] <= N):
            dp[i+LR[1]+1] = (dp[i+LR[1]+1] -atai) % 998244353

#    print(dp)

#復元
ruisekiwa = [0]

for hoge in dp:
    ruisekiwa.append(ruisekiwa[-1]+hoge)
print(ruisekiwa[N+1] % 998244353)
### BUGGY CODE ###


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

lis = []

nowchar = -1
num = 0

for i in range(N):

        if nowchar == S[i]:

            num += 1

        elif nowchar != -1:

            lis.append([nowchar,num])

            nowchar = S[i]
            num = 1

        else:

            nowchar = S[i]
            num = 1

lis.append([nowchar,num])


nlis = []
zeronum = 0
summ = 0
ans = 0


while True:

    if zeronum <= K:

        ans = max(ans,summ)

        if len(lis) == 0:
            break

        new = lis.pop(0)
        nlis.append(new)

        if new[0] == "0":
            zeronum += 1

        summ += new[1]

    else:

        old = nlis.pop(0)

        if old[0] == "0":
            zeronum -= 1

        summ -= old[1]

print (ans)
        
    


### FIXED CODE ###


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

#N = 10 ** 5
#K = 3
#S = "01" * ((10 ** 5) // 2 )

lis = []

nowchar = -1
num = 0

for i in range(N):

        if nowchar == S[i]:

            num += 1

        elif nowchar != -1:

            lis.append([nowchar,num])

            nowchar = S[i]
            num = 1

        else:

            nowchar = S[i]
            num = 1

lis.append([nowchar,num])


nlis = []
lisst = 0
lisla = -1
zeronum = 0
summ = 0
ans = 0


while True:

    if zeronum <= K:

        ans = max(ans,summ)

        if lisla == len(lis)-1:
            break

        new = lis[lisla+1]
        lisla += 1
        #nlis.append(new)

        if new[0] == "0":
            zeronum += 1

        summ += new[1]

    else:

        old = lis[lisst]
        lisst += 1

        if old[0] == "0":
            zeronum -= 1

        summ -= old[1]

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

N = int(input())
A_l = [int(i) for i in input().split()]
a_sum = 0
for i in range(N):
    for j in range(i+1,N):
        a_sum = a_sum + (A_l[i] * A_l[j])
print(a_sum % (10**9+7))

### FIXED CODE ###

N = int(input())
A_l = [int(i) for i in input().split()]
a_sum = 0

A_l = [i for i in A_l if i != 0]

sum_l = [0] * len(A_l)
for i in range(len(A_l)):
    if i == 0:
        sum_l[i] = A_l[i]
    else:
        sum_l[i] = sum_l[i-1] + A_l[i]

for i in range(len(A_l)-1):
    a_sum = a_sum + sum_l[i] * A_l[i+1]
print(a_sum % (10**9+7))
### BUGGY CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline

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

for i in range(K):
    imo = [0]*(N+1)
    flag = 1
    for j in range(N):
        imo[max(0,j-A[j])] += 1
        imo[min(N,j+A[j]+1)] -= 1
        if j-A[j]>0 or j+A[j]+1<N:
            flag = 0
    A = list(itertools.accumulate(imo))[:-1]
    if flag == 1:
        break
print(*A)


### FIXED CODE ###

import sys,math,collections,itertools
input = sys.stdin.readline

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

for i in range(K):
    imo = [0]*(N+1)
    flag = 1
    for j in range(N):
        imo[max(0,j-A[j])] += 1
        imo[min(N,j+A[j]+1)] -= 1
        if j-A[j]>0 or j+A[j]+1<N:
            flag = 0
    A = list(itertools.accumulate(imo))[:-1]
    if flag == 1:
        break
print(*A)
### BUGGY CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*13) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 13 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 13 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 13 * (K - A[i])) & ((1 << 13 * A[i]) - 1):
        ans -= 1
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
A = [int(a) for a in input().split()]
A = [0 if a >= K else a for a in A]
X = [1] * N
Y = [1] * N
m = (1<<K*8) - 1
for i in range(N-1):
    X[i+1] = (X[i] | X[i] << 8 * A[i]) & m if A[i] else X[i]
for i in range(1, N)[::-1]:
    Y[i-1] = (Y[i] | Y[i] << 8 * A[i]) & m if A[i] else Y[i]

ans = N
for i in range(N):
    if A[i] == 0 or ((X[i] * Y[i] & m) >> 8 * (K - A[i])) & ((1 << 8 * A[i]) - 1):
        ans -= 1
print(ans)
### BUGGY CODE ###

from itertools import permutations


def warshall_floyd(n, d):
    from builtins import min
    for i in range(n):
        di = d[i]
        for j in range(n):
            dj = d[j]
            for k in range(n):
                dj[k] = min(dj[k], dj[i] + di[k])


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

d = [[1000000000] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C
warshall_floyd(N + 1, d)

result = 1000000000
for p in permutations(r):
    t = 0
    for i in range(R - 1):
        t += d[p[i]][p[i + 1]]
    result = min(result, t)
print(result)


### FIXED CODE ###

from itertools import permutations


def warshall_floyd(n, d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])


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

d = [[1000000000] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    A, B, C = map(int, input().split())
    d[A][B] = C
    d[B][A] = C
warshall_floyd(N + 1, d)

result = 1000000000
for p in permutations(r):
    t = 0
    for i in range(R - 1):
        t += d[p[i]][p[i + 1]]
    result = min(result, t)
print(result)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int, input().split()))
ans = 0

for i in range(N - 1):
    if ans > N - i:
        break
    else:
        cnt = 0
        for j in range(i, N - 1):

            if H[j] >= H[j + 1]:
                cnt += 1
            else:
                break

    if ans < cnt:
        ans = cnt

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int, input().split()))
ans = []
cnt = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        cnt += 1
    else:
        ans.append(cnt)
        cnt = 0

ans.append(cnt)
print(max(ans))
### BUGGY CODE ###

import math
N=int(input())
ans=list()
for i in range(1,N+1):
    tmp=0
    tgt=int(math.sqrt(i)+1)
    ##print('a',tgt)
    for j in range(1,tgt):
        for k in range(j,tgt):
            for h in range(k,tgt):
                if h**2+j**2+k**2+h*j+j*k+k*h==i:
                    if j==k==h:
                        tmp+=1
                    elif j==k or k ==h:
                        tmp+=3
                    else:
                        tmp+=6
    ans.append(tmp)
for i in ans:
    print(i)

### FIXED CODE ###

N=int(input())
a=[0]*10**4
for j in range(1,101):
    for k in range(1,101):
        for h in range(1,101):
            tmp=h**2+j**2+k**2+h*j+j*k+k*h
            if tmp<=10000:
                a[tmp-1]+=1
for i in range(N):
    print(a[i])
### BUGGY CODE ###

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

ans=-1e9

for i in range(li[0],li[1]+1):
  for j in range(li[2],li[3]+1):
    xy=i*j
    ans=max(xy,ans)
    
print(ans)


### FIXED CODE ###

li=list(map(int,input().split()))
ans=[]
a=li[0]*li[2]
b=li[0]*li[3]
c=li[1]*li[2]
d=li[1]*li[3]
ans.append(a)
ans.append(b)
ans.append(c)
ans.append(d)

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

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
idx = {}
A = list(map(int, input().split()))
for i in range(N):
    idx[A[i]] = i


def dfs(l):
    ret = 0
    if len(l) == 1:
        return l[0]
    elif len(l) == 0:
        return 0
    else:
        le = len(l)
        mi = min(l)
        min_ind = idx[mi]
        ret += mi*(min_ind+1)*(le-min_ind)
        return ret + dfs(l[:min_ind])+dfs(l[min_ind+1:])


def solve():
    ans = dfs(A)
    print(ans)


solve()


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

    def same(self, x, y):
        return self.find(x) == self.find(y)


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

Un = UnionFind(N+1)
pos = [-1]*(N+1)
for i, a in enumerate(A):
    pos[a] = i

ans = 0
for i in reversed(range(1, N+1)):
    ind = pos[i]
    left = 0
    right = 0
    if ind > 0 and A[ind] < A[ind-1]:
        left = Un.size[Un.find(ind-1)]
        Un.union(ind, ind-1)
    if ind+1 < N and A[ind+1] > A[ind]:
        right = Un.size[Un.find(ind+1)]
        Un.union(ind, ind+1)
    ans += (left+1)*(right+1)*A[ind]

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

N = int(input())

L = []
LL = []
S = set()
for i in range(N):
  s = input()
  L.append(s)
  if s not in S:
    S.add(s)
    LL.append(s)

L.sort()
LL.sort()

M = 0
for i in LL:
  M = max(M, L.count(i))
for i in LL:
  if L.count(i) == M:
    print(i)

### FIXED CODE ###

N = int(input())

dict = {}
L = []

for i in range(N):
  s = input()
  if s in dict:
    dict[s] = dict[s] + 1
  else:
    dict[s]=1
    L.append(s)

L.sort()

M = 0
for i in dict:
  M = max(M, dict[i])

for i in L:
  if dict[i] == M:
    print(i)
### BUGGY CODE ###

import sys
from math import factorial
n = int(input())
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10**9+7

res = 0
for i in range(n-1, -1, -1):
    res += (2 ** (n - 1) + 2 ** (n - 2) * i) * c_ls[i]
    res %= MOD
res = res * (2**n) % MOD
print(int(res))

### FIXED CODE ###

import sys

n = int(input())
c_ls = [int(i) for i in sys.stdin.readline().split()]
c_ls.sort(reverse=True)
MOD = 10 ** 9 + 7

res = 0
for i, c in enumerate(c_ls):
    res += (i + 2) * c % MOD
    res %= MOD
res = res * (4 ** (n - 1)) % MOD
print(int(res))
### BUGGY CODE ###

from itertools import combinations

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

counter = 0
for a, b, c in combinations(L, 3):
    if a < b + c and b < c + a and c < a + b:
        counter += 1
print(counter)

### FIXED CODE ###

from itertools import combinations
from bisect import bisect_left

N = int(input())
L = sorted(map(int, input().split()))

counter = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        upper_bound = bisect_left(L, L[i] + L[j], j+1, N)
        counter += upper_bound - (j+1)
print(counter)
### BUGGY CODE ###

n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

c=0
for i in range(n+1):
    for j in range(m+1):
        if a[i]+b[j]>k:
            break
        else:
            c=max(c,i+j)
else:
    print(c)

### FIXED CODE ###

n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a=[0]
b=[0]

for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])
    
c=0
idx=m

for i in range(n+1):
    while 1:
        if idx<0:
            break
        if a[i]+b[idx]>k:
            idx-=1
            continue
        else:
            c=max(i+idx,c)
            break
else:
    print(c)
### BUGGY CODE ###

K = int(input())
strs = [sorted(list(input())) for _ in range(K)]

answer = 0
for i in range(K-1):
    for j in range(i+1,K):
        if strs[i] == strs[j]:
            answer += 1

print(answer)

### FIXED CODE ###

N = int(input())
dic = {}
for _ in range(N):
    IN = input()
    A = "".join(sorted(list(IN)))
    if A not in dic:
        dic[A] = 1
    else:
        dic[A] += 1
answer = 0
for k,v in dic.items():
    answer += v*(v-1)//2
print(answer)
### BUGGY CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans = 0

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    for j in range(m + 1):
        if A_cumsum[i] + B_cumsum[j] > k:
            break
        ans = max(ans, i + j)

print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_cumsum, B_cumsum = [0], [0]

for i in range(n):
    A_cumsum.append(A_cumsum[i] + A[i])
    
for j in range(m):
    B_cumsum.append(B_cumsum[j] + B[j])
    
ans, j = 0, m

for i in range(n + 1): # 0を最初に代入した分
    if A_cumsum[i] > k:
        break
    while A_cumsum[i] + B_cumsum[j] > k:
        j -= 1
    ans = max(ans, i + j)

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

n = int(input())
L = list(map(int,input().split()))
ans = L[0]
for i in range(1,n):
  ans *= L[i]
print(ans if ans <= 10**18 else '-1')

### FIXED CODE ###

n = int(input())
L = list(map(int,input().split()))
ans = 1
if 0 in L:
  print(0)
else:
  for l in L:
    ans *= l
    if ans > 10**18:
      print(-1)
      exit()
  print(ans)
### BUGGY CODE ###

n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
hs=[xyh[i][-1] for i in range(n)]
mh=min(hs)
for cx in range(101):
    for cy in range(101):
        for h in range(mh,mh+101):
            j=True
            for i in range(n):
                if max(h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0)!=xyh[i][2]:
                    j=False
            if j:
                print(cx,cy,h)
                break

### FIXED CODE ###

n=int(input())
xyh=[list(map(int,input().split())) for _ in range(n)]
hs=[xyh[i][-1] for i in range(n)]
mh=max(hs)
if mh==0:
    mh=1
for cx in range(101):
    for cy in range(101):
        for h in range(mh,mh+101):
            j=True
            for i in range(n):
                if max(h-abs(xyh[i][0]-cx)-abs(xyh[i][1]-cy),0)!=xyh[i][2]:
                    j=False
            if j:
                print(cx,cy,h)
                break
### BUGGY CODE ###

import fractions


def solve(N, A):
    max_gcd = 0
    gcd1memo = None
    for i in range(N):
        gcd1 = None
        if gcd1memo is not None:
            gcd1 = fractions.gcd(gcd1memo, A[i - 1])
        else:
            for a in A[0:i]:
                gcd1 = fractions.gcd(gcd1, a) if gcd1 is not None else a
        gcd1memo = gcd1
        if i == N - 1:
            gcd = gcd1
        else:
            gcd2 = None
            for a in A[i + 1: N]:
                gcd2 = fractions.gcd(gcd2, a) if gcd2 is not None else a
            if gcd1 is None:
                gcd = gcd2
            elif gcd2 is None:
                gcd = gcd1
            else:
                gcd = fractions.gcd(gcd1, gcd2)
        if gcd > max_gcd:
            max_gcd = gcd
    return max_gcd


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


### FIXED CODE ###

from fractions import gcd


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

# l[i] := [0, i]の数のGCDメモ
l = [None for _ in range(N)]
l[0] = A[0]
for i in range(1, N):
    l[i] = gcd(l[i - 1], A[i])

# r[i] := [i, N - 1]の数のGCDメモ
r = [None for _ in range(N)]
r[N - 1] = A[N - 1]
for i in reversed(range(N - 1)):
    r[i] = gcd(r[i + 1], A[i])

ans = 0
for i in range(N):
    if i == 0:
        ans = max(ans, r[1])
    elif i == N - 1:
        ans = max(ans, l[N - 2])
    else:
        ans = max(ans, gcd(l[i - 1], r[i + 1]))
print(ans)
### BUGGY CODE ###

from collections import deque

Height, Width = map(int, input().split())
Map = [input() for _ in range(Height)]
min_step_map = [[10**6]*Width for _ in range(Height)]
research_point = deque()

# Find the minimum number of steps from all blacks.
# The maximum number of the obtained minimum steps is the answer.
def search_min_step():
    while len(research_point) > 0:
        y_now, x_now = research_point.popleft()
        
        for dy, dx in [(-1,0), (0,-1), (1,0), (0,1)]:
            y_next, x_next = y_now+dy, x_now+dx
            if (y_next <= -1 or Height <= y_next) or \
                                              (x_next <= -1 or Width <= x_next):
                continue
            
            if Map[y_next][x_next] == '#' or \
               min_step_map[y_next][x_next] <= min_step_map[y_now][x_now]:
                continue
            else:
                min_step_map[y_next][x_next] = min_step_map[y_now][x_now] + 1
                research_point.append([y_next, x_next])

for y in range(Height):
    for x in range(Width):
        if Map[y][x] == '#':
            min_step_map[y][x] = 0
            research_point.append([y, x])

search_min_step()

max_step = 0
for y in range(Height):
    max_step = max(max_step, max(min_step_map[y]))

print(max_step)

### FIXED CODE ###

from collections import deque

Height, Width = map(int, input().split())
Map = [input() for _ in range(Height)]
min_step_map = [[10**6]*Width for _ in range(Height)]
research_point = deque()

# Find the minimum number of steps from all blacks.
# The maximum number of the obtained minimum steps is the answer.
def search_min_step():
    while len(research_point) > 0:
        y_now, x_now = research_point.popleft()
        
        for dy, dx in [(-1,0), (0,-1), (1,0), (0,1)]:
            y_next, x_next = y_now+dy, x_now+dx
            if (y_next <= -1 or Height <= y_next) or \
                                              (x_next <= -1 or Width <= x_next):
                continue
            
            if Map[y_next][x_next] == '#' or \
                 min_step_map[y_next][x_next] <= min_step_map[y_now][x_now] + 1:
                continue
            else:
                min_step_map[y_next][x_next] = min_step_map[y_now][x_now] + 1
                research_point.append([y_next, x_next])

for y in range(Height):
    for x in range(Width):
        if Map[y][x] == '#':
            min_step_map[y][x] = 0
            research_point.append([y, x])

search_min_step()

max_step = 0
for y in range(Height):
    max_step = max(max_step, max(min_step_map[y]))

print(max_step)
### BUGGY CODE ###

import copy
import math


def main():
    import collections

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

    for k in range(N):
        tmp_A = ignore(A, k)
        tmp_A = collections.Counter(tmp_A)
        su = 0
        for pairs in sorted(tmp_A.values(), reverse=True):
            if pairs >= 2:
                su += combinations_count(pairs, 2)
            else:
                break
        print(su)


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def ignore(A, i):
    x = copy.copy(A)
    # del x[i]
    # return x
    x[i] = 0
    return x


if __name__ == '__main__':
    main()


### FIXED CODE ###



def main():
    import collections

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

    allc = collections.Counter(A)
    # all_list = [0]*N
    allsu = 0
    for pairs in sorted(allc.values(), reverse=True):
        allsu += pairs*(pairs-1)//2

    for a in A:
        num = allc[a]
        print(allsu - (num-1))

    # for i in range(N):
    #     x = A[i]
    #     A[i] = 0
    #     tmp_A = cc(A)
    #     su = 0
    #     for pairs in sorted(tmp_A.values(), reverse=True):
    #         if pairs >= 2:
    #             su += pairs*(pairs-1)//2
    #         else:
    #             break
    #     A[i] = x
    #     print(su)


if __name__ == '__main__':
    main()