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

import sys
from collections import deque
sys.setrecursionlimit(10**6)


def main(input, print):
    vx = [0, 1, 0, -1]
    vy = [-1, 0, 1, 0]

    H, W, K = map(int, input().split())
    x1, y1, x2, y2 = map(int, input().split())
    table = [[] for _ in range(H)]
    for i in range(H):
        table[i] = list(input().strip())
    q = deque()
    q.append((x1-1, y1-1, 0))
    table[x1-1][y1-1] = 0
    while len(q) > 0:
        x, y, cnt = q.popleft()
        for i in range(4):
            for k in range(1, K+1):
                nx = x + vx[i] * k
                ny = y + vy[i] * k
                if nx < 0 or ny < 0 or nx >= H or ny >= W:
                    break
                if table[nx][ny] == '@':
                    break
                if table[nx][ny] != '.':
                    continue
                table[nx][ny] = cnt+1
                q.append((nx, ny, cnt+1))
    if table[x2-1][y2-1] == '.':
        print(-1)
    else:
        print(table[x2-1][y2-1])


if __name__ == '__main__':
    main(sys.stdin.readline, print)


### FIXED CODE ###

import sys
from collections import deque
sys.setrecursionlimit(10**6)


def main(input, print):
    vx = [0, 1, 0, -1]
    vy = [-1, 0, 1, 0]

    H, W, K = map(int, input().split())
    x1, y1, x2, y2 = map(int, input().split())
    table = [[] for _ in range(H)]
    for i in range(H):
        table[i] = list(input().strip())
    q = deque()
    q.append((x1-1, y1-1, 0))
    table[x1-1][y1-1] = 0
    while len(q) > 0:
        x, y, cnt = q.popleft()
        for i in range(4):
            for k in range(1, K+1):
                nx = x + vx[i] * k
                ny = y + vy[i] * k
                if nx < 0 or ny < 0 or nx >= H or ny >= W:
                    break
                if table[nx][ny] == '@':
                    break
                if table[nx][ny] != '.':
                    if table[nx][ny] < cnt + 1:
                        break
                    else:
                        continue
                table[nx][ny] = cnt+1
                q.append((nx, ny, cnt+1))
    if table[x2-1][y2-1] == '.':
        print(-1)
    else:
        print(table[x2-1][y2-1])


if __name__ == '__main__':
    main(sys.stdin.readline, print)
### BUGGY CODE ###

def resolve():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)
    for i in range(N):
        B = A[:i]+A[i+1:]
        print(max(B))
resolve()

### FIXED CODE ###

def resolve():
    N = int(input())
    A = []
    C = []
    for _ in range(N):
        a = int(input())
        A.append(a)
        C.append(a)
    B = max(A)
    C.remove(B)
    D = max(C)
    for i in range(N):
        if B != A[i]:
            print(B)
        else:
            print(D)
resolve()
### BUGGY CODE ###

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


#print(N,K,Q,A)
'''
score=[K]*N

for answer in A:
    score=[point-1 for point in score]
    score[answer-1]+=1
    print(score)

for point in score:
    if point>0:
        print('Yes')
    else:
        print('No')
'''

### FIXED CODE ###

N, K, Q=map(int, input().split())
A=[None]*Q
for i in range(Q):
    A[i]=int(input())
#print(A)

import collections
dict=collections.Counter(A)
for person in range(1,N+1):
    if K-Q+dict[person]>0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import itertools

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

comb_ab = []
for a, b in itertools.product(A, B):
    comb_ab.append(sum([a, b]))

comb_ab_top = sorted(comb_ab, reverse=True)[:K]

comb_abc = []
for ab, c in itertools.product(comb_ab_top, C):
    comb_abc.append(sum([ab, c]))

ans = sorted(comb_abc, reverse=True)[:K]
print(*ans, sep='\n')


### FIXED CODE ###

import itertools

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

comb_ab = []
for a, b in itertools.product(A, B):
    comb_ab.append(sum([a, b]))

comb_ab_top = sorted(comb_ab, reverse=True)[:K]

comb_abc = []
for ab, c in itertools.product(comb_ab_top, C):
    comb_abc.append(sum([ab, c]))

ans = sorted(comb_abc, reverse=True)[:K]
print(*ans, sep='\n')
### BUGGY CODE ###

import sys
import numpy as np

def main(N, S):
    dp = np.zeros((N + 1, N + 1), dtype=int)
    ans = 0
    for i in range(N - 1):
        for j in range(i + 1, N):
            dp[i, j] = min(j - i, dp[i - 1, j - 1] + 1) if S[i] == S[j] else 0
        ans = max(ans, np.max(dp[i]))
    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('main', 'i8(i8,i8[:])')(main)
    # b1: bool, i4: int32, i8: int64, double: f8, [:], [:, :]
    cc.compile()
else:
    try:
        from my_module import main
    except:
        1
    N = int(input())
    S = np.array([ord(_) for _ in input()])
    print(main(N, S))


### FIXED CODE ###

import itertools
N = int(input())
S = input()
dp = [[0] * N for _ in range(N)]
ans = 0
for i, j in itertools.combinations(range(N), 2):
    if S[i] == S[j]:
        dp[i][j] = dp[i - 1][j - 1] + 1
    else:
        dp[i][j] = 0
    ans = max(ans, min(j - i, dp[i][j]))
print(ans)
### BUGGY CODE ###

import sys
def first_white(c):
    for i,ele in enumerate(c):
        if ele == 0:
            return i
    return -1
        
def last_red(c):
    for i in range(len(c)-1, -1, -1):
        if c[i] == 1:
            return i
    return -1
  
n = int(input())
c = [0 if x=='W' else 1 for x in input()]
counter = 0
while True:
    first_w = first_white(c)
    last_r = last_red(c)
    if (len(c) == 0) or (first_w < 0) or (last_r < 0) or (last_r < first_w):
        print(counter)
        sys.exit()
    c = c[first_w+1:last_r]    
    counter += 1

### FIXED CODE ###

import sys

n = int(input())
c = [0 if x=='W' else 1 for x in input()]
counter = 0

white_index = [i for i,ele in enumerate(c) if ele == 0]
red_index = [i for i in range(len(c)-1, -1, -1) if c[i] == 1]
    
    
for i in range(min(len(white_index), len(red_index))):
    if white_index[i] < red_index[i]:
        counter += 1
print(counter)
### BUGGY CODE ###

def second_largest(numbers):
    count = 0
    m1 = m2 = float('-inf')
    for x in numbers:
        count += 1
        if x > m2:
            if x >= m1:
                m1, m2 = x, m1            
            else:
                m2 = x
    return m2 if count >= 2 else None

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

cnt = 0
for i in range(len(p)):
    for j in range(i+1,len(p)):
        cnt += second_largest(p[i:j+1])
print(cnt)

### FIXED CODE ###

#!/usr/bin/env python3
N=int(input())
p=list(map(int,input().split()))
LL = [0] + [i for i in range(N+1)]
RR = [i+1 for i in range(N+1)] + [N+1]
E = [(v, i+1) for i, v in enumerate(p)]
E.sort()
ans=0
for v, i in E:
  r0 = RR[i]
  r1 = RR[r0]
  l0 = LL[i]
  l1 = LL[l0]
  RR[l0] = r0
  LL[r0] = l0

  ans += ((r1 - r0)*(i-l0)+(r0-i)*(l0 - l1))*v

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

n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)


### FIXED CODE ###

n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
prv_count=-1#人の見て追加

#flag=True
while count!=prv_count:
    prv_count=count
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            #flag=True
if A==B:
    print(count)
else:
    print(-1)
### BUGGY CODE ###

r, c, k = map(int, input().split())
dp = [[[0] * 4 for _ in range(c+1)] for _ in range(r+1)]

v_dict = dict()
for _ in range(k):
    y, x, v = map(int, input().split())
    v_dict[(y, x)] = v

for y in range(1, r+1):
    for x in range(1, c+1):
        p = (y, x)
        prev_y_max = max(dp[y-1][x][:])
        dp[y][x][0] = max(prev_y_max, dp[y][x-1][0])
        if p in v_dict:
            v = v_dict[p]
            dp[y][x][1] = max(prev_y_max + v, dp[y][x-1][0] + v, dp[y][x-1][1])
            dp[y][x][2] = max(dp[y][x-1][1] + v, dp[y][x-1][2])
            dp[y][x][3] = max(dp[y][x-1][2] + v, dp[y][x-1][3])
        else:
            for i in range(1, 4):
                dp[y][x][i] = dp[y][x-1][i]
print(max(dp[r][c]))


### FIXED CODE ###

r, c, k = map(int, input().split())
dp = [[[0] * (c+1) for _ in range(r+1)] for _ in range(4)]

v_dict = dict()
for _ in range(k):
    y, x, v = map(int, input().split())
    v_dict[(y, x)] = v

for y in range(1, r+1):
    for x in range(1, c+1):
        prev_y_max = 0
        for i in range(4):
            prev_y_max = max(dp[i][y-1][x], prev_y_max)
        dp[0][y][x] = max(prev_y_max, dp[0][y][x-1])
        if (y, x) in v_dict:
            v = v_dict[(y, x)]
            dp[1][y][x] = max(prev_y_max + v, dp[0][y][x-1] + v, dp[1][y][x-1])
            dp[2][y][x] = max(dp[1][y][x-1] + v, dp[2][y][x-1])
            dp[3][y][x] = max(dp[2][y][x-1] + v, dp[3][y][x-1])
        else:
            for i in range(1, 4):
                dp[i][y][x] = dp[i][y][x-1]
ans = 0
for i in range(4):
    ans = max(dp[i][r][c], ans)
print(ans)
### BUGGY CODE ###

from collections import deque


N = int(input())
branch = [[0] + list(map(lambda x: int(x) - 1, input().split())) for _ in range(N - 1)]
vertex = [False] * N


def bfs():
    max_color = 0
    q = deque()
    v = 0
    bc = 0
    q.append((v, bc))

    while len(q):
        v, bc = q.popleft()
        vertex[v] = True
        b_list = [c for c in branch if v in c[1:]]

        color = 1
        for c in b_list:
            if color == bc:
                color += 1
            if (c[0] == 0):
                c[0] = color
                color += 1
            nv = c[1] if c[2] == v else c[2]
            if vertex[nv] is False:
                q.append((nv, c[0]))
        max_color = max(max_color, color - 1)

    return max_color


print(bfs())
for b in branch:
    print(b[0])


### FIXED CODE ###

import sys


sys.setrecursionlimit(10 ** 6)

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append((b - 1, i))
    edge[b - 1].append((a - 1, i))
ec = [0] * (N - 1)


def dfs(node, pc):
    color = 1

    for to, idx in edge[node]:
        if ec[idx] == 0:
            if color == pc:
                color += 1
            ec[idx] = color

            dfs(to, color)
            color += 1


dfs(0, -1)
print(max(ec))
for c in ec:
    print(c)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import Counter

def maybe_check(n,A):
    try:
        if n <= 0 or n > 100000:
            raise

        div = 1000000007
        maybe_list = [abs(abs(i - n) - ((n -1 ) - abs(i - n))) for i in range(1, n+1) ]
        pattern = len([num for num,count in Counter(maybe_list).items() if count != 1])

        for i in A:
            if i < 0  or i >= n:
                raise
            elif i in maybe_list:
                maybe_list.remove(i)
            else:
                raise

        return (2 ** pattern) % div


    except:
        return 0


_n = int(raw_input())
_A = map(int,raw_input().split())

print maybe_check(_n,_A)


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import Counter

def maybe_check(n,A):
    try:
        if n <= 0 or n > 100000:
            raise

        div = 1000000007
        maybe_list = [abs(abs(i - n) - ((n -1 ) - abs(i - n))) for i in range(1, n+1)]
        maybe_list.sort()
        A.sort()
        if A !=  maybe_list:
            raise

        pattern = len([num for num,count in Counter(maybe_list).items() if count != 1])
        return (2 ** pattern) % div

    except:
        return 0


_n = int(raw_input())
_A = map(int,raw_input().split())

print maybe_check(_n,_A)
### BUGGY CODE ###

N, c = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(N)]
A = [[0 for i in range(c)] for j in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(c):
            A[(i+j)%3][k] += D[C[i][j]-1][k]

ans = 1e9
for i in range(c):
    for j in range(i):
        for k in range(j):
            for l in range(3):
                ans = min(ans, A[l][i]+A[(l+1)%3][j]+A[(l+2)%3][k],
                          A[l][i]+A[(l-1)%3][j]+A[(l-2)%3][k])
print(ans)


### FIXED CODE ###

N, c = map(int, input().split())
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(N)]
A = [[0 for i in range(c)] for j in range(3)]
for i in range(N):
    for j in range(N):
        for k in range(c):
            A[(i+j)%3][k] += D[C[i][j]-1][k]

ans = 1e9
for i in range(c):
    for j in range(i):
        for k in range(j):
            for l in range(3):
                ans = min(ans, A[l][i]+A[(l+1)%3][j]+A[(l+2)%3][k],
                          A[l][i]+A[(l-1)%3][j]+A[(l-2)%3][k])
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0]*M
mod = 10**9+7

for i in range(M):
    a[i] = int(input())

DP = [0]*(N+1)
DP[0] = 1
if 1 in a:
    DP[1] = 0
else:
    DP[1] = 1

for i in range(2, N+1):
    if(i not in a):
        DP[i] = (DP[i-1]+DP[i-2])%mod
        
print(DP[-1])

### FIXED CODE ###

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = [0]*M
mod = 10**9+7

for i in range(M):
    a[i] = int(input())

a = set(a)
DP = [0]*(N+1)
DP[0] = 1
if 1 in a:
    DP[1] = 0
else:
    DP[1] = 1

for i in range(2, N+1):
    if(i not in a):
        DP[i] = (DP[i-1]+DP[i-2])%mod
        
print(DP[-1])
### BUGGY CODE ###

N = int(input())
HP_list = [int(i) for i in input().split()]
HP_list.sort()
while len(HP_list)>1:
    HP_list[-1] = min([HP_list[-1]%i for i in HP_list[:-1]])
    if HP_list[-1]== 0:
        HP_list.pop(-1)
    else:
        HP_list.sort()
print(HP_list[0])

### FIXED CODE ###

import numpy as np
N = int(input())
HPs = np.array([int(i) for i in input().split()])
np.sort(HPs)
while len(HPs) > 1:
    HPs[1:] %= HPs[0]
    HPs[HPs==0] = HPs[0]
    HPs=np.unique(HPs)
print(HPs[0])
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
ans = [0 for i in range(len(s))]
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    ans[i] = 1
      
for i in range(q):
  l, r = map(int, input().split())
  count = 0
  for j in range(l-1, r-1):
    count += ans[j]
  print(count)
    
  
  



### FIXED CODE ###

n, q = map(int, input().split())
s = input()
tmp = [0 for i in range(len(s))]
for i in range(len(s)-1):
  if s[i] == "A" and s[i+1] == "C":
    tmp[i] = 1
    
ans = [0 for i in range(len(s)+1)]
for i in range(1, len(ans)):
  ans[i] = ans[i-1] + tmp[i-1]
  
for i in range(q):
  l, r = map(int, input().split())
  count = 0
  print(ans[r-1] - ans[l-1])
### BUGGY CODE ###

import sys
import copy
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
# A = np.array(list(map(int, (input().split()))))
A = list(map(int, (input().split())))
# nd = np.zeros((N,N), dtype=bool)
# print(*A)
for i in range(min(K,N)):
    cnt = [0]*N
    for j in range(N):
        # nd[j, max(j-A[j],0):min(j+A[j]+1,N)] = True
        for k in range(max(j-A[j],0), min(j+A[j]+1,N)):
            cnt[k] += 1
    # print(nd)
    A = copy.copy(cnt)
    # print(*A)

print(*A)

### FIXED CODE ###

import numpy as np
from numba import njit
import sys
# import copy
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10 ** 7)

N, K = map(int, input().split())
# A = np.array(list(map(int, (input().split()))))
A = np.array(input().split(), dtype=np.int64)
# A = list(map(int, (input().split())))
# nd = np.zeros((N,N), dtype=bool)
# print(*A)

# @njit('(i8[::1],)', cache=True)
@njit(cache=True)
def loop(A):
    for i in range(K):
        # cnt = [0]*N
        cnt = np.zeros_like(A)
        for j, x in enumerate(A):
            # nd[j, max(j-A[j],0):min(j+A[j]+1,N)] = True
            l = max(j-x,0)
            r = min(j+x+1,N)
            cnt[l] += 1
            if r<N:
                cnt[r] -= 1
            # for k in range(max(j-A[j],0), min(j+A[j]+1,N)):
            #     cnt[k] += 1
        # print(nd)
        # A = np.count_nonzero(nd, axis=0)
        # print(cnt)
        A = np.cumsum(cnt)
        if A[0] == A[N-1] == N:
            break
        # print(*A)
    return A

A = loop(A)
print(*A)
### BUGGY CODE ###

import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from sys import stdin
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, m = map(int, input().split())
a = sorted(list(map(int, stdin.readline().split())))
x = [(0, 0)] * m
for i in range(m):
    b, c = map(int, stdin.readline().split())
    x[i] = (c, b)
x.sort(reverse=True)
for i in range(m):
    z = [x[i][0]] * x[i][1]
    a.extend(z)
a.sort()
ans = 0
# print(a)
print(sum(a[len(a) - n:]))


### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
bc = [list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1], reverse=True)
  
for b,c in bc:
  a.extend([c]*b)
  if len(a) > n*2:
    break
a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

n = int(input())
print(sum(range(1,n)))

### FIXED CODE ###

n = int(input())
print((n)*(n-1) // 2)
### BUGGY CODE ###

import itertools

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

r = 0
for c in itertools.combinations(l, M):
  s = sum(abs(sum(v[i] for v in c)) for i in range(3))
  if s > r:
    r = s

print(r)

### FIXED CODE ###

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

a = 0

for xs in (1, -1):
  for ys in (1, -1):
    for zs in (1, -1):
      l_s = [x*xs + y*ys + z*zs for x, y, z in l]
      l_s.sort(reverse=True)
      a = max(sum(l_s[:M]), a)

print(a)
### BUGGY CODE ###

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

N, M = map(int, input().split())
a=[]
for _ in range(M):
    a.append(int(input()))

lst=[0]*(N+1)
def func(n):
    if n in a:
        return 0
    if n<=1:
        return 1
    else:
        if lst[n]:
            return lst[n]
        else:
            temp=(func(n-1)+func(n-2))%(10**9+7)
            lst[n]=temp
            return temp

print(func(N))

### FIXED CODE ###

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

N, M = map(int, input().split())
a=[]
for _ in range(M):
    a.append(int(input()))

lst=[None]*(N+1)
def func(n):
    #if n in a:
    #    return 0
    if n<=1:
        return 1
    else:
        if lst[n]:
            return lst[n]
        else:
            temp=(func(n-1)+func(n-2))%(10**9+7)
            lst[n]=temp
            return temp



a=[-1]+a+[N+1]
answer=1
for i in range(M+1):
    if a[i+1]-a[i]==1:
        print(0)
        break
    answer=( func(a[i+1]-a[i]-2)*answer )%(10**9+7)
else:
    print(answer)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
x=[0]*len(a)

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    if a[i]%a[j]==0:
      x[i]+=1
      continue
print(x.count(0))

### FIXED CODE ###

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

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 ###

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

for k in range(0, min(100,K)):
    work = [0] * N
    for i in range(0, N):
        l = max(0, i - A[i])
        r = min(N - 1, i + A[i])
        work[l] += 1
        if (r + 1 < N):
            work[r + 1] -= 1
    for i in range(1, N):
        work[i] += work[i - 1]
    A = work
    if (all([item == N for item in A])):
        break

print(" ".join([str(item) for item in work]))

### FIXED CODE ###

import sys
import numpy as np
from numba import njit

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

@njit('(i8[::1],)', cache=True)
def update(A):
    N = len(A)
    B = np.zeros_like(A)
    for i, x in enumerate(A):
        l = max(0, i - x)
        r = min(N - 1, i + x)
        B[l] += 1
        if r + 1 < N:
            B[r + 1] -= 1
    B = np.cumsum(B)
    return B

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

K = min(K, 100)
for _ in range(K):
    A = update(A)
print(' '.join(A.astype(str)))
### BUGGY CODE ###

def hantei(field,r,c):
    count=0
    for i in range(c):
        countc=0
        for j in range(r):
            countc=countc+field[j][i]
        count=max(countc,r-countc)+count
    return count
    
def turnr(field,rn,r,c):
    if rn==r:
        return hantei(field,r,c)
    field1=field
    field2=field
    field2[rn]=[not x for x in field[rn]]
    return max(turnr(field1,rn+1,r,c),turnr(field2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in raw_input().split()]
    if r==0:
        break
    else:
        field=[]
        for i in range(r):
            field.append([int(x) for x in raw_input().split()])
        print turnr(field,0,r,c)

### FIXED CODE ###


def hanteib(bfield,r,c):
    count=0
    for b in bfield:
        ccount=bin(b).count("1")
        count=count+max(ccount,r-ccount)
    return count

def turnrb(bfield,rn,r,c):
    if rn==r:
        return hanteib(bfield,r,c)
    bfield1=bfield
    bfield2=[b ^ 2**rn for b in bfield]
    return max(turnrb(bfield1,rn+1,r,c),turnrb(bfield2,rn+1,r,c))

while(1):
    [r,c]=[int(x) for x in raw_input().split()]
    if r==0:
        break
    else:
        field=[]
        bfield=[]
        for i in range(r):
            field.append([int(x) for x in raw_input().split()])
        for j in range(c):
            bb=0
            for i in range(r):
                bb=bb+2**i*field[i][j]
            bfield.append(bb)
        print turnrb(bfield,0,r,c)
### BUGGY CODE ###

K = int(input())
if K % 2 == 0:
    print(-1)
    exit()

for i in range(1, K + 1):
    tmp = '7' * i
    if int(tmp) % K == 0:
        print(i)
        exit()

print(-1)

### FIXED CODE ###

K = int(input())
if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()

tmp1 = 0
for i in range(1, 2 * K + 1):
    tmp1 += 7 * pow(10, i, K)
    if tmp1 % K == 0:
        print(i)
        exit()

print(-1)
### BUGGY CODE ###

from collections import Counter

def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    Da = Counter(A)
    Ds = sorted(Da.items(), key=lambda x: x[1])

    for i in range(n):
        cnt = 0
        for j in range(len(Ds) - Ds.count(1)):
            cnt += Ds[j][1]*(Ds[j][1] - 1)//2

        cnt -= Da[A[i]] - 1
        print(cnt)

if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import Counter

def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    Da = Counter(A)
    cnt = 0
    for v in Da.values():
        cnt += v*(v - 1)//2

    for i in range(n):
        print(cnt - (Da[A[i]] - 1))

if __name__ == "__main__":
    main()