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

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	rows, cols = rli()
	r0, c0 = rli(); r0 -= 1; c0 -= 1;
	r1, c1 = rli(); r1 -= 1; c1 -= 1;
	G = []
	for _ in range(rows):
		row = []
		for c in rll()[0]:
			if c == "#": 
				row.append(1)
			else:
				row.append(0)
		G.append(row)

	inside = lambda r, c: r>=0 and c>=0 and r<rows and c<cols	
	seen = defaultdict(lambda: False)
	Q = deque() #(num magics, r, c)
	Q.append((0, r0, c0))
	ans = INF
	while Q:
		magics, r, c = Q.pop()
		if seen[(r, c)]: continue
		seen[(r, c)] = True
		if r == r1 and c == c1:
			ans = magics 
			break
		for dr in range(-2, 3):
			for dc in range(-2, 3):
				nr, nc = r + dr, c + dc 
				if not inside(nr, nc) or seen[(nr, nc)] or G[nr][nc] == 1: continue
				if abs(dr) + abs(dc) > 1:
					Q.appendleft((magics+1, nr, nc))
				else:
					Q.append((magics, nr, nc))
	print(ans if ans < INF else -1)
	stdout.close()

if __name__ == "__main__":
	main()

### FIXED CODE ###

from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	rows, cols = rli()
	r0, c0 = rli(); r0 -= 1; c0 -= 1;
	r1, c1 = rli(); r1 -= 1; c1 -= 1;
	G = []
	for _ in range(rows):
		row = []
		for c in rll()[0]:
			if c == "#": 
				row.append(1)
			else:
				row.append(0)
		G.append(row)

	inside = lambda r, c: r>=0 and c>=0 and r<rows and c<cols	
	seen = [0 for _ in range(rows*cols+10)]
	Q = deque() #(num magics, r, c)
	Q.append((0, r0, c0))
	ans = INF
	while Q:
		magics, r, c = Q.pop()
		val = r*cols + c 
		if seen[val]: continue
		seen[val] = True
		if r == r1 and c == c1:
			ans = magics 
			break
		for dr in range(-2, 3):
			for dc in range(-2, 3):
				nr, nc = r + dr, c + dc 
				if not inside(nr, nc) or seen[cols*nr + nc] or G[nr][nc] == 1: continue
				if abs(dr) + abs(dc) > 1:
					Q.appendleft((magics+1, nr, nc))
				else:
					Q.append((magics, nr, nc))
	print(ans if ans < INF else -1)
	stdout.close()

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

'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

n = int(input()) 
  
a = list(map(int,input().strip().split()))[:n] 
x=1  
for i in range(n):
    x*=a[i]
    
if x>1000000000000000000:
    print(-1)
else:
    print(x)
    


### FIXED CODE ###

'''

                            Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

n = int(input()) 
  
a = list(map(int,input().strip().split()))[:n] 
x=1
flag=0
flag1=0
for i in range(n):
    if a[i]==0:
        x*=0
        flag1=1
        break
if flag!=1: 
    for i in range(n):
        if x*a[i]>1000000000000000000:
            flag=1
            break
        else:
            x*=a[i]
        
if flag1==1:
    print(0)
elif flag==1:
    print(-1)
else:
    print(x)
### BUGGY CODE ###

H, W, D = [int(x) for x in input().split()]
A = [(-1, -1)] * 100000

for y in range(H):
    tmp = [int(x) for x in input().split()]
    for x in range(W):
        A[tmp[x]] = (x, y)

Q = int(input())
LR = [tuple([int(x) for x in input().split()]) for i in range(Q)]

for start, goal in LR:
    place = start
    nxt = place + D
    point = 0

    while place != goal:
        placeX, placeY = A[place]
        nxtX, nxtY = A[nxt]

        point += (abs(nxtX - placeX) + abs(nxtY - placeY))
        place += D
        nxt += D
    print(point)


### FIXED CODE ###

H, W, D = [int(x) for x in input().split()]
size = H*W+1
c = [(-1, -1)] * size
p = [0] * size

for y in range(H):
    for x, a in enumerate([int(s) for s in input().split()]):
        c[a] = (x, y)

for a in range(D+1, size):
    p[a] = p[a-D] + abs(c[a][0] - c[a-D][0]) + abs(c[a][1] - c[a-D][1])

Q = int(input())
for i in range(Q):
    L, R = [int(lr) for lr in input().split()]
    print(p[R] - p[L])
### BUGGY CODE ###

S = input()
Q = int(input())
q = [list(input().split()) for _ in range(Q)]


flip = 0
for i in range(len(q)):

    if q[i][0] == "1":
        flip ^= 1
    else:
        if flip == 0 and q[i][1] == "1":
            S = q[i][2] + S
        elif flip == 0 and q[i][1] == "2":
            S = S + q[i][2]
        elif flip == 1 and q[i][1] == "1":
            S = S + q[i][2]
        else:
            S = q[i][2] + S

if flip == 1:
    print(S[::-1])
else:
    print(S)            
    

### FIXED CODE ###

S = list(input())
Q = int(input())
q = [list(input().split()) for _ in range(Q)]
head = []
tail = []
flip = 0
for i in range(len(q)):

    if q[i][0] == "1":
        flip ^= 1
    else:
        if flip == 0 and q[i][1] == "1":
            head.append(q[i][2])
        elif flip == 0 and q[i][1] == "2":
            tail.append(q[i][2])
        elif flip == 1 and q[i][1] == "1":
            tail.append(q[i][2])
        else:
            head.append(q[i][2])

if flip == 0:
    ans = "".join(head[::-1] + S + tail)
    # print(head)
    # print(S)
    # print(tail)
    print( ans )
else:
    ans = "".join(tail[::-1] + S[::-1] + head)
    print( ans )
### BUGGY CODE ###

X, Y = [int(x) for x in input().split()]

def solve(X, Y):
    if X == Y:
        return -1
    for x in range(X, 10**18+1, X):
        if x % Y != 0:
            return x
print(solve(X, Y))





### FIXED CODE ###

X, Y = [int(x) for x in input().split()]

def solve(X, Y):
    if X == Y:
        return -1
    if Y < X:
        if X % Y == 0:
            return -1

    for x in range(X, 10**18+1, X):
        if x % Y != 0:
            return x
print(solve(X, Y))
### BUGGY CODE ###

mod = 998244353

N, K, *LR = map(int, open(0).read().split())

S = set()
for l, r in zip(*[iter(LR)] * 2):
    for i in range(l, r + 1):
        S.add(i)

S = sorted(S)

dp = [0] * N
dp[0] = 1
for i in range(N):
    for s in S:
        if i + s >= N:
            break
        dp[i + s] += dp[i]
        dp[i + s] %= mod

print(dp[-1])

### FIXED CODE ###

# https://ikatakos.com/pot/programming_algorithm/data_structure/binary_indexed_tree

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

class RangeUpdate:
    def __init__(self, n):
        self.p = Bit(n + 1)
        self.q = Bit(n + 1)

    def add(self, s, t, x):
        t += 1
        self.p.add(s, -x * s)
        self.p.add(t, x * t)
        self.q.add(s, x)
        self.q.add(t, -x)

    def sum(self, s, t):
        t += 1
        return (self.p.sum(t) + self.q.sum(t) * t - \
               self.p.sum(s) - self.q.sum(s) * s) % mod


mod = 998244353

N, K, *LR = map(int, open(0).read().split())

LR = list(zip(*[iter(LR)] * 2))

dp = RangeUpdate(N)
dp.add(1, 1, 1)
for i in range(1, N + 1):
    for l, r in LR:
        dp.add(i + l, i + r, dp.sum(i, i))

print(dp.sum(N, N))
### BUGGY CODE ###

from heapq import heapify, heappop

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

A = map(int, input("").split(" "))
A = list(A)
heapify(A)

for i in range(M):
    B, C = map(int, input("").split(" "))

    c = 0
    for j in range(B):
        if A[0] < C:
            heappop(A)
            c += 1
        else:
            break

    A.extend([C]*c)
    heapify(A)

c = 0
for a in A:
    c += a

print(c)


### FIXED CODE ###

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

A = map(int, input("").split(" "))
A = list(A)
A.sort()

potentials = []
for i in range(M):
    B, C = map(int, input("").split(" "))

    potentials.append((B, C))

potentials.sort(key=lambda x: x[1], reverse=True)

c = 0
for p in potentials:
    for b in range(p[0]):
        if p[1] > A[c]:
            A[c] = p[1]
            c += 1
            if c >= len(A):
                break
        else:
            break
    if c >= len(A):
        break

print(sum(A))
### BUGGY CODE ###

from functools import reduce
n=int(input())
a=list(map(int,input().split()))
c=list(range(1,n+1))
num=list(map(lambda t:reduce(lambda a,b:a+1 if b==t else a,a,0),c))
"""
test=list(map(lambda t:map(lambda x,y:x if (y!=t or x==0) else x-1,num,c),c))
for i in range(5):
    print(list(test[i]))
"""
preans=reduce(lambda x,y:x+y*(y-1)/2,num,0)

for i in range(n):
    print(int(preans-num[a[i]-1]+1))

### FIXED CODE ###

from functools import reduce
n=int(input())
a=list(map(int,input().split()))
c=list(range(1,n+1))
num=[0]*n
for i in range(n):
    num[a[i]-1]=num[a[i]-1]+1
preans=reduce(lambda x,y:x+y*(y-1)/2,num,0)

for i in range(n):
    print(int(preans-num[a[i]-1]+1))
### BUGGY CODE ###

import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(n)
for i in range(1,n):
    flag = max(0,i-k)
    dp[i] = np.min(dp[flag:i]+abs(h[flag:i]-h[i]))
print(int(dp[n-1]))


### FIXED CODE ###

import numpy as np
n,k = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(n)
for i in range(1,n):
    flag = max(0,i-k)
    dp[i] = np.min(dp[flag:i]+abs(h[flag:i]-h[i]))
print(int(dp[-1]))
### BUGGY CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
if n == 1:
    print(a[0]//(2**m))
else:
    for i in range(m):
        a.sort(reverse = True)
        a[0] //= 2
    print(sum(a))

### FIXED CODE ###


import heapq as he

n,m = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x: x*(-1),a))
he.heapify(a)

for i in range(m):
    he.heappush(a,he.heappop(a)*(-1)//2*(-1))

print(sum(a)*(-1))
### BUGGY CODE ###

import numpy as np
import scipy.linalg as linalg

N = int(input())
solve_arr = [int(i) for i in input().split()]

w_arr = []

for i in range(N):
  arr = [0]*N
  if i == N-1:
    arr[i] = 1/2
    arr[0] = 1/2
  else:
    arr[i] = 1/2
    arr[i+1] = 1/2
  w_arr.append(arr)
  
LU = linalg.lu_factor(w_arr)
ans = linalg.lu_solve(LU, solve_arr)


for i in ans:
  print(str(int(i)) + " ", end ="")

### FIXED CODE ###

N = int(input())
dam_arr = list(map(int,input().split()))
mount_arr = []

# calculate 1st mount's rain
rain = 0
for i in range(N):
  if i%2==0:
    rain += dam_arr[i]
  else:
    rain -= dam_arr[i]
    
mount_arr.append(rain)

# caluculate others
for i in range(N-1):
  mount_arr.append(2*dam_arr[i]-mount_arr[-1])

mount_arr=[str(a) for a in mount_arr]
mount_arr=" ".join(mount_arr)
print(mount_arr)
### BUGGY CODE ###

x=int(input())
a=int(x**(1/5))+1
l=list(range(a+1))
s=[]
m=0
n=0
w=0
e=1
r=0
for i in l:
  k=i**5
  l[i]=k
for i in l:
  s.append(i*-1)
p=l+s
for i in p:
  if m==1:
    break
  for q in p:
    if x==i-q:
      print(int(i**(1/5)),end=" ")
      m+=1
      if p.index(q)<=a+1:
        print(p.index(q))
      else:
        print((p.index(q)-a-1)*-1)
      break
if m==0:
  while  n==0:
    u=e**5-w**5
    if u>x:
      r+=1
      w=r
      e=r+1
    if x==u:
      print(e,end=" ")
      print(w)
      n+=1
    else:
      e+=1

### FIXED CODE ###

x=int(input())
m=0
for i in range(500):
  for k in range(500):
    w=i**5
    e=k**5
    r=k**5*-1
    if w-e==x:
      print(i,end=" ")
      print(k)
      m+=1
      break
    elif w-r==x:
      print(i,end=" ")
      print(k*-1)
      m+=1
      break
  if m==1:
    break
### BUGGY CODE ###

n, m = map(int, input().split())
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

ret = 0
for i in range(1, m) :
    for j in range(1, n) :
        ret += (x[j]-x[j-1])*(y[i]-y[i-1])*(n-j)*(m-i)*i*j%MOD
        ret %= MOD
        
print(ret)


### FIXED CODE ###

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

x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

MOD = 10 ** 9 + 7

sx = 0
pre = 0
for i in range(1, n) :
    pre += (x[i]-x[i-1]) * i
    sx += pre
    sx %= MOD
    
sy = 0
pre = 0
for i in range(1, m) :
    pre += (y[i]-y[i-1]) * i
    sy += pre
    sy %= MOD
    
print(sx*sy%MOD)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	Q = II()
	c = 0
	head=[]
	tail=[]
	ans = S
	for _  in range(Q):
		query = IS()
		if(len(query)==1):
			c = (c + 1)%2
		else:
			T,F,C = query.split()
			T = int(T)
			F = int(F)
			if F==1:
				if(c==0):
					ans = C + ans
				else:
					ans = ans + C
			else:
				if(c==1):
					ans = C + ans
				else:
					ans = ans + C
	if c == 0:
		ans = ans
	else:
		ns = ans[::-1]
		ans = ns
	print(ans)




if __name__ == '__main__':
	main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	S = IS()
	Q = II()
	c = 0
	head=[]
	tail=[]
	for _  in range(Q):
		query = IS()
		if(len(query)==1):
			c = (c + 1)%2
		else:
			T,F,C = query.split()
			T = int(T)
			F = int(F)
			if F==1:
				if(c==0):
					head.append(C)
				else:
					tail.append(C)
			else:
				if(c==1):
					head.append(C)
				else:
					tail.append(C)
	if c == 0:
		head = ''.join(head[::-1])
		tail = ''.join(tail)
		ans = head+S+tail
	else:
		head = ''.join(head)
		tail = "".join(tail[::-1])
		ns = S[::-1]
		ans = tail+ns+head
	print(ans)




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

N = int(input())
l = sorted(list(map(int, input().split())))

result = 0

for i in range(N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      if(l[i] + l[j] > l[k]):
        result += 1
      else:
        break
        

print(result)

### FIXED CODE ###

import bisect

N = int(input())
l = sorted(list(map(int, input().split())))

result = 0

for i in range(N):
  for j in range(i + 1, N):
    cur = bisect.bisect_left(l, l[i] + l[j]) - j - 1
    result += cur if cur > 0 else 0   

print(result)
### BUGGY CODE ###

n, k, c = map(int, input().split())
s = input()

ans = ""
for i in range(n):
    if s[i] == "x":
        continue

    cur = 0
    count = 0

    while cur < n:
        if s[cur] == "o" and cur != i:
            count += 1
            cur += c

        cur += 1

        if count >= k:
            break

    if count < k:
        ans+=(str(i+1)+"\n")

print(ans)

### FIXED CODE ###

from sys import stdin
def main():
    input = stdin.readline
    n, k, c = map(int, input().split())
    s = input()

    l, r = [], []
    cur = 0
    count = 0

    while cur <= n:
        if s[cur] == "o":
            count += 1
            l.append((count, cur+1))
            cur += c

        cur += 1

    cur = n
    count = k

    while cur >= 0:
        if s[cur] == "o":
            r.append((count, cur+1))
            count -= 1
            cur -= c

        cur -= 1

    ans = (i[1] for i in set(l) & set(r))
    for i in sorted(ans):
        print(i)


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

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

INF = 10**4 + 1
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[0] - h[1])

for i in range(2, N):
    candidate = []
    for j in range(i-K, i):
        if j >= 0:
            candidate.append(dp[j]+abs(h[i]-h[j]))
    dp[i] = min(candidate)

print(dp[-1])

### FIXED CODE ###

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

dp = [0]*N

for i in range(1, N):
    h_to = h[i]
    dp[i] = min(
        [
            dp_from + abs(h_to - h_from)
            for dp_from, h_from in zip(
                dp[max(0, i-K):i], h[max(0, i-K):i]
            )
        ]
    )

print(dp[-1])
### BUGGY CODE ###

from collections import defaultdict
N, P = map(int,input().split())
S = input()

if P==5:
    ans = 0
    for i,m in enumerate(S):
        if m == '5' or m == '0':
            ans += i+1
elif P==2:
    ans = 0
    for i,m in enumerate(S):
        if int(m) % 2 ==0:
            ans += i+1
else:
    #primdic = defaultdict(int)
    primdic = [0]*P
    for i in range(N):
        # i~右端までの数字のmodP
        primdic[int(S[i:])%P] += 1
    primdic[0] += 1
    ans = 0
    #for value in primdic.values():
    #    ans += value*(value-1)//2
    for value in primdic:
        ans += value*(value-1)//2
print(ans)

### FIXED CODE ###

from collections import defaultdict
N, P = map(int,input().split())
S = input()

if P==5:
    ans = 0
    for i,m in enumerate(S):
        if m == '5' or m == '0':
            ans += i+1
elif P==2:
    ans = 0
    for i,m in enumerate(S):
        if int(m) % 2 ==0:
            ans += i+1
else:
    S = S[::-1]
    primdic = defaultdict(int)
    before = 0
    for i in range(0,N):
        now = (int(S[i])*pow(10,i,P)+before)%P
        primdic[now] += 1
        before = now
    # 文字なしの時はあまり0なので
    primdic[0] += 1
    ans = 0
    for value in primdic.values():
        ans += value*(value-1)//2
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    ## 1の位からi+1文字のうち13で割ったもののあまりがjであるものの数
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0]=1
    list10 = range(0,10)
    list13 = range(0,13)
    for i in range(1,N+1):
        if S[N-i]=="?":
            for j in list10:
                addmod = (j*10**(i-1))%13
                for k in list13:
                    modmod = (k+addmod)%13
                    dp[i][modmod] += dp[i-1][k]%MOD
        else:
            addmod = (int(S[N-i])*10**(i-1))%13
            for k in list13:
                modmod = (k+addmod)%13
                dp[i][modmod] = dp[i-1][k]%MOD

    print(dp[N][5]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    ## 1の位からi+1文字のうち13で割ったもののあまりがjであるものの数
    N = len(S)
    dp = [[0]*13 for _ in range(N+1)]
    dp[0][0]=1
    list10 = range(0,10)
    list13 = range(0,13)
    keta =1
    for i in range(1,N+1):
        if S[N-i]=="?":
            for j in list10:
                addmod = j*keta%13
                for k in list13:
                    modmod = (k+addmod)%13
                    dp[i][modmod] += dp[i-1][k]%MOD
        else:
            addmod = (int(S[N-i])*keta)%13
            for k in list13:
                modmod = (k+addmod)%13
                dp[i][modmod] = dp[i-1][k]%MOD
        keta*=10
        keta%=13
    print(dp[N][5]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

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

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

for i in range(M):
    B, C = map(int, input().split(" "))

    for j in range(B):
        A.append(C)
        
A.sort(reverse=True)
print(sum(A[0:N]))

### FIXED CODE ###

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

A.sort()

D = []
for i in range(M):
    B, C = map(int, input().split(" "))
    D.append((C, B))

#D = list(D_dict)
D.sort(reverse=True)

D_index = 0
D_index_max = len(D)

ans = 0

ct_D_i = 0
ct_D_i_max = D[0][1]

ct_D_total = 0

for i in range(N):
    a = A[i]
    d = D[D_index][0]
    if a > d:
        break

    A[i] = d


    ct_D_i += 1
    if ct_D_i >= ct_D_i_max:
        D_index += 1
        if D_index >= D_index_max:
            break

        ct_D_i = 0
        ct_D_i_max = D[D_index][1]




print(sum(A))
### BUGGY CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def cmb(n, r):
    if n < 2: return 0
    if n - r < r: r = n - r 
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (n - r)%p
            for k in range(p-1, r, p):
                numerator[k-offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def main():
    N = INT()
    A = LIST()

    c = Counter(A)
    l = [0 for _ in range(2 * (10**5) + 7)]
    h = [0 for _ in range(2 * (10**5) + 7)]

    for k, v in c.items():
        l[k] = cmb(v-1, 2)
        h[k] = cmb(v, 2)

    for a in A:
        ans = sum(h) - h[a] + l[a]
        print(ans) 


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N = INT()
    A = LIST()

    C = Counter(A)

    X = 0
    for v in C.values():
        X += v * (v - 1) // 2

    for i in range(N):
        print(X - C[A[i]] + 1)


if __name__ == '__main__':
    main()