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

h, w = map(int, input().split())
lis = []

for i in range(h):
    lis.append(input())

mtx = [[[0] * 2 for i in range(w)] for j in range(h)]

for i in range(len(lis)):
    cnt = 0
    start = 0
    for j in range(w):
        if lis[i][j] == '.':
            cnt += 1
            if j == w - 1:
                for k in range(start, w):
                    mtx[i][k][0] = cnt
        else:
            for k in range(start, j):
                mtx[i][k][0] = cnt
            start = j + 1
            cnt = 0

for i in range(w):
    cnt = 0
    start = 0
    for j in range(h):
        if lis[j][i] == '.':
            cnt += 1
            if j == h - 1:
                for k in range(start, h):
                    mtx[k][i][1] = cnt
        else:
            for k in range(start, j):
                mtx[k][i][1] = cnt
            start = j + 1
            cnt = 0


ret = 0
for i in range(h):
    for j in range(w):
        ret = max(ret, mtx[i][j][0] + mtx[i][j][1] - 1)

print(ret)


### FIXED CODE ###

h, w = map(int, input().split())

mtx = [input() for _ in range(h)]

ret_mtx1 = [[0] * w for _ in range(h)]
ret_mtx2 = [[0] * w for _ in range(h)]
ret_mtx3 = [[0] * w for _ in range(h)]
ret_mtx4 = [[0] * w for _ in range(h)]

# left 2 right
for i in range(h):
    for j in range(w):
        if mtx[i][j] == '.':
            ret_mtx1[i][j] = 1 if i == 0 else ret_mtx1[i-1][j] + 1
            ret_mtx2[i][j] = 1 if j == 0 else ret_mtx2[i][j-1] + 1
        if mtx[-1-i][-1-j] == '.':
            ret_mtx3[-1-i][-1-j] = 1 if i == 0 else ret_mtx3[-i][-1-j] + 1
            ret_mtx4[-1-i][-1-j] = 1 if j == 0 else ret_mtx4[-1-i][-j] + 1

ret = 0

for i in range(h):
    for j in range(w):
        tmp = ret_mtx1[i][j] + ret_mtx2[i][j] + \
            ret_mtx3[i][j] + ret_mtx4[i][j] - 3
        ret = max(ret, tmp)

print(ret)
### BUGGY CODE ###

N,M=map(int,input().split())
nekotyann=[]
wanntyann=[]
ans="IMPOSSIBLE"
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        if b in wanntyann:
            ans="POSSIBLE"
            break
        else:
            nekotyann.append(b)
    if b==N:
        if a in nekotyann:
            ans="POSSIBLE"
            break
        else:
            wanntyann.append(a)
print(ans)


### FIXED CODE ###

N,M=map(int,input().split())
nekotyann=[0]*N
wanntyann=[0]*N
ans="IMPOSSIBLE"
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        nekotyann[b-1]+=1
    if b==N:
        wanntyann[a-1]+=1
for k in range(N):
    if nekotyann[k]!=0 and wanntyann[k]!=0:
        ans="POSSIBLE"
        break
print(ans)
### BUGGY CODE ###

n=int(input())
A=[int(input()) for i in range(n)]
B=list(set(A))
m=len(B)
counter=0
for i in range(m):
    if A.count(B[i])%2==1:
        counter+=1
print(counter)

### FIXED CODE ###

N=int(input())
s=set()
for i in range(N):s^={input()}
print(len(s))
### BUGGY CODE ###

a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

# for i in range(len(P)):
#     P[i] = (float)(P[i]+1)/2

max = 0
maxj = 0

for i in range(len(P)-K+1):
    num = 0
    for j in range(K):
        num += P[i+j]
        # print(P[i+j],end=" ")
    # print(num)
    if(max < num):
        max = num
        maxj = i

a = 0
for i in range(K):
    a += (float)(P[maxj+i]+1)/2

print("{0:6f}".format(a))


### FIXED CODE ###

a = list(map(int, input().split()))
N = a[0]
K = a[1]
P = list(map(int, input().split()))

for i in range(len(P)):
    P[i] = (float)(P[i]+1)/2

S = []
for i in range(len(P)):
    if(i > 0):
        S.append(P[i]+S[i-1])
    else:
        S.append(P[0])
# print(S)

max = S[K-1]
for i in range(len(S)-K):
    a = S[i+K]-S[i]
    # print(a)

    if(a > max):
        max = a

# max = 0

# for i in range(len(P)-K+1):
#     num = 0
#     for j in range(K):
#         num += P[i+j]
#         # print(P[i+j],end=" ")
#     # print(num)
#     if(max < num):
#         max = num

print("{0:6f}".format(max))
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline


def main():
    N = int(input())
    edge = [list(map(int,input().split())) for _ in range(N)]
    use = [[True for _ in range(N)] for _ in range(N)]
    count = 0
    for k in range(N):
        for i in range(N):
            if k == i:
                continue
            for j in range(N):
                if (k == j or i == j):
                    continue
                if edge[i][j] == edge[i][k] + edge[k][j]:
                    use[i][j] = False
                elif edge[i][j] > edge[i][k] + edge[k][j]:
                    print(-1)
                    exit()
    
    ans = 0
    for i in range(N):
        for j in range(i,N):
            ans += (edge[i][j]*use[i][j])
    print(ans)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    edge = [list(map(int,input().split())) for _ in range(N)]
    for i in range(N):
        edge[i][i] = 10**10
        
    ans = 0
    for i in range(N):
        for j in range(i):
            d = min(a+b for a,b in zip(edge[i],edge[j]))
            if edge[i][j] > d:
                print(-1)
                exit()
            elif edge[i][j] < d:
                ans += edge[i][j]

    print(ans)    

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

n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    a = [c if e == b else e for e in a]
    l.append(a)

for a in l:
    print(sum(a))

### FIXED CODE ###

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

l = [0] * 100001
for i in a:
    l[i] += 1

s = sum(a)

for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * l[b]
    l[c] += l[b]
    l[b] = 0
    print(s)
### BUGGY CODE ###

e,a = map(int,input().split())
cnt =0
while True:
    if e==0 and a==0:
        break
    else:
        for i in range(1,e+1):
            for j in range(i+1,e+1):
                for k in range(j+1,e+1):
                    if i+j+k ==a:
                        cnt +=1
print(cnt)


### FIXED CODE ###

while True:
    e,a = map(int,input().split())
    if e ==0 and a ==0:
        break
    cnt = 0
    for i in range(1,e+1):
        for j in range(1,e+1):
            if j<=i:
                continue
            X = a - (i + j)
            if X > j and X <=e:
                cnt +=1
    print(cnt)
### BUGGY CODE ###

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


def dfs(parts):
    global ans
    n = len(parts)
    if n == 3:
        ans += 1
    elif n == 2:
        for i in c:
            if parts[1] < i:
                dfs(parts + [i])
    elif n == 1:
        for j in b:
            if parts[0] < j:
                dfs(parts + [j])


ans = 0
for i in a:
    dfs([i])

print(ans)


### FIXED CODE ###

import bisect

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

ans = 0
for i in b:
    a_pos = bisect.bisect_left(a, i)
    c_pos = n - bisect.bisect_right(c, i)
    ans += a_pos * c_pos

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

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


#print(gcd(8, 20))
K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = gcd(i, j)
            ans += gcd(a, k)
print(ans)



### FIXED CODE ###

"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""
import sys
sys.setrecursionlimit(10 ** 7)


def wi(): return list(map(int, sys.stdin.readline().split()))
# WideIntPoint


def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]


def ws(): return sys.stdin.readline().split()


def si(): return int(sys.stdin.readline())  # SingleInt


def ss(): return input()


def hi(n): return [si() for _ in range(n)]


def hs(n): return [ss() for _ in range(n)]  # HeightString


def s_list(): return list(input())


def mi(n): return [wi() for _ in range(n)]  # MatrixInt


def mip(n): return [wip() for _ in range(n)]


def ms(n): return [ws() for _ in range(n)]


def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[
    0]] for _ in range(n)]  # NumberGrid


def grid(n): return [s_list() for _ in range(n)]


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    K = si()
    ans = 0
    q = [0]*201
    for i in range(1, K+1):
        for j in range(1, K+1):
            q[gcd(i, j)] += 1

    for k in range(1, K+1):
        for i in range(1, K+1):
            ans += gcd(i, k)*q[i]

    print(ans)


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

k,s=map(int,input().split())
c=0
for l in range(k+1):
    for m in range(k+1):
        for n in range(k+1):
            if l+m+n==s:c+=1
            else:pass
print(c)

### FIXED CODE ###

k,s=map(int,input().split())
c=0
for l in range(s+1):
    for m in range(min(l+1,k+1)):
        if s-l<=k and l-m<=k:c+=1
        else:pass
print(c)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
number = []
n = 0

for i in range(N):
  n = A.count(i)
  number.append(n)
  if n != 0:
    A.remove(i)
  n = 0

del number[0]
number.append(0)
for Answer in number:
  print(Answer)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
number = []
for i in range(N):
  number.append(0)

for i in range(N-1):
  n = A[i-1]*1
  number[n] = number[n] + 1

del number[0]
number.append(0)
for Answer in number:
  print(Answer)
### BUGGY CODE ###

s = input()
n = len(s)
p = 10 ** 9 + 7

# i = 0, ..., nについて
# dp[i][0] = i文字目まででありうる文字列の数（ABCなら1、AB?なら3）
# dp[i][1] = i文字目までに含まれるAの数
# dp[i][2] = i文字目までに含まれるABのパターン数
# dp[i][3] = i文字目までに含まれるABCのパターン数
dp = [[0 for j in range(4)] for i in range(n + 1)]
dp[0][0] = 1 # ''空の文字列は1パターン
for j in range(1, 4):
    dp[0][j] = 0  # 空の文字列にはAもABもABCも入っていない

for i in range(1, n + 1):
    m = 3 if s[i - 1] == '?' else 1

    for j in range(4):
        dp[i][j] = dp[i - 1][j] * m

    if s[i - 1] == 'A' or s[i - 1] == '?':
        dp[i][1] =  (dp[i][1] + dp[i - 1][0]) % p
    if s[i - 1] == 'B' or s[i - 1] == '?':
        dp[i][2] = (dp[i][2] + dp[i - 1][1]) % p
    if s[i - 1] == 'C' or s[i - 1] == '?':
        dp[i][3] = (dp[i][3] + dp[i - 1][2]) % p

print(dp[n][3])


### FIXED CODE ###

s = input()
n = len(s)
p = 10 ** 9 + 7

q = s.count('?')
l_a = [0] * n  # l_a[i] := s[i]より左にあるAの数
l_x = [0] * n  # l_x[i] := s[i]より左にある?の数
r_c = [0] * n  # r_c[i] := s[i]より右にあるCの数
r_x = [0] * n  # r_x[i] := s[i]より右にある?の数

for i in range(1, n):  # 1〜n-1
    l_a[i] = l_a[i - 1] + int(s[i - 1] == 'A')
    l_x[i] = l_x[i - 1] + int(s[i - 1] == '?')
    r_c[n - i - 1] = r_c[n - i] + int(s[n - i] == 'C')
    r_x[n - i - 1] = r_x[n - i] + int(s[n - i] == '?')

ans = 0
pow_q = []
for i in range(0, 4):
    pow_q.append(max(1, 3 ** (q - i) % p))

for i in range(n):
    if s[i] == 'B':
        ans += (l_a[i] * r_c[i] % p) * pow_q[0] % p  # ABC
        ans += (l_x[i] * r_c[i] % p) * pow_q[1] % p # ?BC
        ans += (l_a[i] * r_x[i] % p) * pow_q[1] % p # AB?
        ans += (l_x[i] * r_x[i] % p) * pow_q[2] % p # ?B?
        ans %= p
    elif s[i] == '?':
        ans += (l_a[i] * r_c[i] % p) * pow_q[1] % p # A?C
        ans += (l_x[i] * r_c[i] % p) * pow_q[2] % p # ??C
        ans += (l_a[i] * r_x[i] % p) * pow_q[2] % p # A??
        ans += (l_x[i] * r_x[i] % p) * pow_q[3] % p # ???
        ans %= p

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

N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
counter = 0
while A:
    num = A.count(A[0])
    if num % 2 == 1:
        counter += 1
    del A[:num]

print(counter)


### FIXED CODE ###

N = int(input())
maps = {}

for _ in range(N):
    A = int(input())
    if A in maps:
        maps.pop(A)
    else:
        maps[A] = 1

print(len(maps))
### BUGGY CODE ###

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

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

que=[0]
done=[-1]*N
while len(que)>0:
    now=que.pop(0)
    done[now]=1
    for nex in G[now]:
        if done[nex]==1:
            continue
        else:
            X[nex]+=X[now]
            que.append(nex)

print(" ".join(map(str, X)))

### FIXED CODE ###

from collections import deque 
N,Q=map(int, input().split())
G=[[] for _ in range(N)]
for i in range(N-1):
    a,b=map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
X=[0]*N
for i in range(Q):
    p,x=map(int, input().split())
    X[p-1]+=x
que=deque([(0,-1)])
#print(que)
while que:
    now, pre=que.pop()
    for nex in G[now]:
        if nex==pre:
            continue
        else:
            X[nex]+=X[now]
            que.append((nex,now))

print(" ".join(map(str, X)))
### BUGGY CODE ###

h,w,a,b=map(int,input().split())

p=10**9+7
#p=127

def modp_factorial(n):
    s=1
    for x in range(1,h+1):
        s=(s*x) % p
    return s
def modp_prod(lst):
    s=1
    for x in lst:
        s=(s*x)%p
    return s
def inv(n):
    s=1
    q=p-2
    while q>0:
        if q&1:
            s=s*n % p
        n=n*n
        q>>=1
    return s

l=[1]
f=1
for x in range(1,h+w+1):
    f=f*x % p
    l.append(f)
invl=[inv(l[-1])]
for n in range(h+w,1,-1):
    invl.append((invl[-1]*n) % p)
invl.append(1)
invl.reverse()


s=0
for x in range(1,h-a+1):
    s=s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
        ,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])% p
print(s)


### FIXED CODE ###

h,w,a,b=map(int,input().split())

p=10**9+7
#p=127

def modp_factorial(n):
    s=1
    for x in range(1,h+1):
        s=(s*x) % p
    return s
def modp_prod(lst):
    s=1
    for x in lst:
        s=(s*x)%p
    return s
def inv(n):
    s=1
    q=p-2
    while q>0:
        if q&1:
            s=(s*n) % p
        n=(n*n) % p
        q>>=1
    return s

l=[1]
f=1
for x in range(1,h+w):
    f=(f*x) % p
    l.append(f)
invl=[inv(l[-1])]
for n in range(h+w-1,1,-1):
    invl.append((invl[-1]*n) % p)

invl.append(1)
invl.reverse()


s=0
for x in range(1,h-a+1):
    s=(s+modp_prod([l[x+b-2],invl[x-1],invl[b-1]\
        ,l[w-b+h-x-1],invl[h-x],invl[w-b-1]])) % p
print(s)
### BUGGY CODE ###

n,k=map(int,input().split())
s=list(input())
a=[]
f=1
s.append(2)
for i in range(n):
    if s[i]==s[i+1]:
        f+=1
    else:
        a.append(f)
        f=1
g=len(a)
if s[0]=='1':
    ans=0
    for i in range(g):
        if 2*i<g:
            ans=max(ans,sum(a[2*i:2*i+2*k+1]))
        else:
            break
    print(ans)
else:
    ans=sum(a[0:2*k])
    for i in range(g):
        if 2*i+1<g:
            ans=max(ans,sum(a[2*i+1:2*i+2*k+2]))
        else:
            break
    print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
s=list(input())
a=[]
f=1
s.append(2)
for i in range(n):
    if s[i]==s[i+1]:
        f+=1
    else:
        a.append(f)
        f=1
g=len(a)
r=[0]*(g+1)
for i in range(g):
    r[i+1]=r[i]+a[i]
if s[0]=='1':
    ans=sum(a[0:2*k+1])
    if s[-2]=='0':
        ans=max(ans,sum(a[max(0,g-2*k):g]))
    for i in range(g):
        if 2*i+2*k+1<g+1:
            ans=max(ans,r[2*i+2*k+1]-r[2*i])
        else:
            break
    print(ans)
else:
    ans=sum(a[0:2*k])
    if s[-2]=='0':
        ans=max(ans,sum(a[max(0,g-2*k):g]))
    for i in range(g):
        if 2*i+2*k+2<g+1:
            ans=max(ans,r[2*i+2*k+2]-r[2*i+1])
        else:
            break
    print(ans)
### BUGGY CODE ###

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

left = [[] for _ in range(N)]
for i in range(N):
  for j in range(N):
    if (j-i == 0 or j-i == 1) and not i == N-1:
      left[i].append(0.5)
    else:
      left[i].append(0)
left[N-1][0] = 0.5
left[N-1][N-1] = 0.5
from numpy.linalg import solve
answer = solve(left, A)
answer = list(map(int, answer))
print(*answer)

### FIXED CODE ###

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

X = []
X.append(sum(A)-2*sum(A[2*i+1] for i in range(N//2)))
for i in range(N-1):
  X.append(2*A[i]-X[-1])
print(*X)
### BUGGY CODE ###

import itertools
from copy import deepcopy

def turnOverRow(now_state,combs,c):
    for i in combs:
        for j in range(c):
            now_state[i][j]=0 if now_state[i][j]==1 else 1

def turnOverCol(now_state,r,c):
    h=r/2
    for i in range(c):
        cnt=0
        for j in range(r):
            if now_state[j][i]==1:
                cnt+=1
        if cnt>h:
            for j in range(r):
                now_state[j][i]=1 if now_state[j][i]==0 else 0

def countMax(now_state,r):
    return sum(sum(now_state[i]) for i in range(r))

while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    init_state=[map(int,raw_input().split()) for i in range(r)]
    now_state=deepcopy(init_state)
    ans=10000000000
    for i in range(r+1):
        for combs in itertools.combinations(range(r),i):
            turnOverRow(now_state,combs,c)
            turnOverCol(now_state,r,c)
            ans=min(ans,countMax(now_state,r))
            now_state=deepcopy(init_state) #initialization
    print r*c-ans

### FIXED CODE ###

while True:
    r,c=map(int,raw_input().split())
    if r==c==0:break
    state=[raw_input().split() for i in range(r)]
    state=map(list,zip(*state))
    new_state=[int("".join(ls),2) for ls in state]
    ans=0
    h=r/2
    for i in range(pow(2,r)):
        cnt=0
        for j in new_state:
            n=bin(i^j).count("1")
            cnt+=n if n>h else r-n
        ans=max(ans,cnt)
    print ans
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

need =[2,5,5,4,5,6,3,7,6]

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    if j == need[A[i]-1]:
      dp[i][j] = A[i]
    elif j > need[A[i]-1]:
      if dpmax[j-need[A[i]-1]] != 0:
        dp[i][j] = max(int(str(A[i]) + str(dpmax[j-need[A[i]-1]])),
                       int(str(dpmax[j-need[A[i]-1]]) + str(A[i])))
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])

### FIXED CODE ###

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

if N % 2 == 0:
  if 1 in A:
    print(int('1'*(N//2)))
    exit()

need =(2,5,5,4,5,6,3,7,6)

if 2 in A and 3 in A:
  del A[A.index(2)]
if 3 in A and 5 in A:
  del A[A.index(3)]
if 6 in A and 9 in A:
  del A[A.index(6)]
if 1 in A and 4 in A:
  del A[A.index(4)]
if 6 in A and 7 in A:
  del A[A.index(6)] 
if 7 in A and 9 in A:
  del A[A.index(9)] 
if 1 in A and 6 in A:
  del A[A.index(6)] 
if 1 in A and 9 in A:
  del A[A.index(9)] 
  
A = tuple(A)
M = len(A)

dp = [[0]*(N+1) for _ in range(M)]
dpmax = [0]*(N+1)

def take_max():
  return max(A[i]*(10**len(str(tmp2)) + tmp2,tmp2*10+A[i]))

for j in range(2,N+1):
  tmpmax = 0
  for i in range(M):
    tmp = need[A[i]-1]
    if j == tmp:
      dp[i][j] = A[i]
    elif j > tmp:
      if dpmax[j-tmp] != 0:
        tmp2 = dpmax[j-tmp]
        dp[i][j] = take_max()
    if tmpmax < dp[i][j]:
      tmpmax = dp[i][j]
  dpmax[j] = tmpmax
  
print(dpmax[-1])
### BUGGY CODE ###

N,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
DP = [1000000000]*N
DP[0] = 0
def handan(i,x):
    if DP[i] > x:
        DP[i] = x
for i in range(1,N):
    for j in range(min(i,k)):
        x = DP[i-j-1] + abs(h[i]-h[i-j-1])
        handan(i,x)
print(DP[N-1])

### FIXED CODE ###

N,k = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
DP = [1000000000]*N
DP[0] = 0
def handan(i,x):
    if DP[i] > x:
        DP[i] = x
for i in range(1,N):
    for j in range(min(i,k)):
        x = DP[i-j-1] + abs(h[i]-h[i-j-1])
        handan(i,x)
print(DP[N-1])
### BUGGY CODE ###

n=int(input())
a=list(input().split())
if n==1:
  print(a[0])
  exit()
bl=a[-1]
br=a[-2]
for i in range(2,n):
  if i%2==0:
    bl+=' '+a[-1-i]
  else:
    br=a[-1-i]+' '+br
bl+=' '+br
print(bl)

### FIXED CODE ###

n=int(input())
a=list(input().split())
if n==1:
  print(a[0])
  exit()
bl=[a[-1]]
br=[a[-2]]
for i in range(2,n):
  if i%2==0:
    bl.append(a[-1-i])
  else:
    br.append(a[-1-i])
m=len(br)
br=[br[-i-1] for i in range(m)]
bl[len(bl):len(bl)]=br
print(' '.join(bl))
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
sameNumber = collections.Counter(A)

def count(val):
  cnt = 0
  sameNumber[val] -= 1
  for n in sameNumber:
    cnt += sameNumber[n] * (sameNumber[n]-1) //2
  sameNumber[val] += 1
  return cnt

for n in A:
  res = 0
  res += count(n)
  print(res)

### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
sameNumber = collections.Counter(A)
total = 0
for n in sameNumber:
  total += sameNumber[n] * (sameNumber[n]-1)

def count(val):
  if sameNumber[val] > 1:
    return (total -2 * (sameNumber[val]-1)) //2
  return total //2

for n in A:
  print(count(n))
### BUGGY CODE ###

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を除いたlistで同じ数字を引く回数を出力
memo = {}
for k in range(N):
    ans = 0
    m = A[k]
    if m in memo.keys():
        ans = memo[m]
    else:
        dict_work = dict.copy()
        dict_work[A[k]] -= 1
        for d in dict_work.values():
            if d > 1:
                ans += (d * (d - 1)) // 2
        memo[m] = ans
    print(ans)


### FIXED CODE ###

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

# 各数字の個数を格納
dict = {}
for a in A:
    if a in dict:
        dict[a] += 1
    else:
        dict[a] = 1

# k番目の値を消さない場合の場合分けの個数
ans = 0
for d in dict.values():
    if d > 1:
        ans += (d * (d - 1)) // 2

# k番目の値を除いた場合に減る場合の数を引いて答えを出力
for k in range(N):
    w = dict[A[k]]
    # 減る数
    decrease = 0
    if w == 1:
        pass
    elif w == 2:
        decrease = -1
    elif w > 2:
        decrease = ((w - 1) * (w - 2) // 2) - (w * (w - 1) // 2 )
    print(ans + decrease)