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

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
from functools import lru_cache
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]


N = I()
a = LI()

@lru_cache(maxsize=None)
def rec(i, j, k):
    if (i==0) and (j==0) and (k==0):
        return 0
    res = N
    if (i>0):
        res += rec(i-1, j, k)*i
    if (j>0):
        res += rec(i+1, j-1, k)*j
    if (k>0):
        res += rec(i, j+1, k-1)*k
    res /= i+j+k
    return res

print(rec(a.count(1), a.count(2), a.count(3)))


### FIXED CODE ###

import sys

def I(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    N = I()
    a = LI()
    t = [0, 0, 0]
    for ai in a:
        t[ai-1] += 1
    A, B, C = t
    E = B+C

    dp = [[0 if (i+j==0) else N/(i+j) for j in range(E+1)] for i in range(N+1)]

    for k in range(C+1):
        for i in range(N+1):
            dp[i][E] = 0 if (i+E+k==0) else N/(i+E+k)
        for j in range(E+1):
            for i in range(N+1):
                z = i+j+k
                if (not z):
                    continue
                d = dp[i][j]
                if (i<N):
                    dp[i+1][j] += (i+1)*d/(z+1)
                if (i>0) and (j<E):
                    dp[i-1][j+1] += (j+1)*d/z
                if (j>0) and (k<C):
                    dp[i][j-1] = (k+1)*d/z + N/z

    print(dp[A][B])

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

x = -1
y = -1
S = list(input())
for i in range(0, len(S)-1):
    for j in range(i+2, len(S)+1):
        s = S[i:j]
        s_set = list(set(s))
        for s_i in s_set:
            if s.count(s_i) > (len(s)//2):
                x = i+1
                y = j
                break
        if s.count(s_i) > (len(s)//2):
            break
    if s.count(s_i) > (len(s)//2):
        break
print(x, y)

### FIXED CODE ###

# 回答を見て

x = -1
y = -1
S = list(input())

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        x = i+1
        y = x+1
        break
    elif i+2<=len(S)-1:
        if S[i] == S[i+2]:
            x = i+1
            y = x+2
            break
        else:
            pass
    else:
        pass
print(x, y)
### BUGGY CODE ###

from collections import Counter
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, m, r = read_line(int, int, int)

rs = [int(r) for r in input().split()]

cities = Counter()

routes = {}
for _ in range(m):
    a, b, c = read_line(int, int, int)

    cities[a] = 1
    cities[b] = 1

    if a in routes:
        routes[a][b] = c
    else:
        routes[a] = { b : c }

    if b in routes:
        routes[b][a] = c
    else:
        routes[b] = { a : c }

def cost(selected):
    c = 0
    for i in range(len(selected) - 1):
        a = selected[i]
        b = selected[i + 1]
        if a in routes and b in routes[a]:
            c += routes[a][b]
        else:
            c += 100000 + 1
    return c

def passing_all_cities(selected):
    for r in rs:
        if r not in selected:
            return False
    return True


smallest = 100000 + 1

def f(selected, rest):
    global smallest
    if passing_all_cities(selected):
        c = cost(selected)
        if smallest > c:
            smallest = c
    else:
        for i in range(len(rest)):
            r = rest[i]
            rest_copy = rest[:]
            del rest_copy[i]
            f(selected + [r], rest_copy)

f([], list(cities.keys()))
print(smallest)


### FIXED CODE ###

from itertools import permutations

def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

n, m, r = read_line(int, int, int)

rs = [int(r) for r in input().split()]

costs = {}
for i in range(n + 1):
    costs[i] = {}
    for j in range(n + 1):
        costs[i][j] = float('inf')

for _ in range(m):
    a, b, c = read_line(int, int, int)

    costs[a][b] = costs[b][a] = c

for k in range(n + 1):
    for i in range(n + 1):
        for j in range(n + 1):
            c = costs[i][k] + costs[k][j]
            if costs[i][j] > c:
                costs[i][j] = c

def cost(selected):
    c = 0
    for i in range(len(selected) - 1):
        a = selected[i]
        b = selected[i + 1]
        c += costs[a][b]
    return c

smallest = float('inf')

for p in permutations(rs):
    c = cost(p)
    if smallest > c:
        smallest = c

print(smallest)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
M = N - K
A = [0] + LIST()

# dp[i][j] := 列をi個使って、最後に使ったのがj列目の時の最小コスト
dp = list2d(M+1, N+1, INF)
dp[0][0] = 0
for i in range(M):
    for j, h1 in enumerate(A[i:], i):
        if dp[i][j] == INF:
            break
        for k in range(j+1, N+1):
            h2 = A[k]
            dp[i+1][k] = min(dp[i+1][k], dp[i][j] + max(h2 - h1, 0))
print(min(dp[M]))


### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
M = N - K
A = [0] + LIST()

# dp[i][j] := 列をi個使って、最後に使ったのがj列目の時の最小コスト
dp = list2d(M+1, N+1, INF)
dp[0][0] = 0
for i in range(1, M+1):
    for j, h1 in enumerate(A):
        for k in range(max(j-N, 0), j):
            h2 = A[k]
            dp[i][j] = min(dp[i][j], dp[i-1][k] + max(h1 - h2, 0))
print(min(dp[M]))
### BUGGY CODE ###

from sys import stdin
N=int(stdin.readline().rstrip())
cnt=0
for i in range(N+1):
    if set(list(str(i)))=={"3","5","7"}:
        cnt+=1
print(cnt)

### FIXED CODE ###

import itertools
from sys import stdin
N=int(stdin.readline().rstrip())
ans=0
for i in range(3,11):
    for j in list(itertools.product("753",repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j)))==3:
            ans+=1
print(ans)
### BUGGY CODE ###

num, capacity = map(int, input().split())
dp = [0]*(capacity+1)

for i in range(1, num + 1):
    weight, value = map(int, input().split())
    for w in range(capacity,weight - 1,-1):
        if w < weight:
            continue
        else:
            dp[w] = max( dp[w - weight] + value,  dp[w] )
print(dp[capacity])

### FIXED CODE ###

def calc(num,capacity):
    dp = [0]*(capacity+1)
    for _ in range(num):
        weight, value = map(int, input().split())
        for w in range(capacity,weight - 1,-1):
            tmp = dp[w - weight] + value
            if dp[w] < tmp:
              dp[w] = tmp
    return dp[capacity]

num, capacity = map(int, input().split())
print(calc(num,capacity))
### BUGGY CODE ###

a,b,m=map(int, input().split())
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m
ans = []
for i in range(m):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])
for i in range(b):
	for j in range(a):
		ans.append(rei[j]+den[i])
print(min(ans))

### FIXED CODE ###

m=list(map(int, input().split()))
rei=list(map(int, input().split())) 
den=list(map(int, input().split())) 
cou = [0] * m[2]
ans = []
for i in range(m[2]):
	cou[i]=list(map(int, input().split()))
	ans.append(rei[cou[i][0]-1]+den[cou[i][1]-1]-cou[i][2])

ans.append(min(rei)+min(den))
print(min(ans))
### BUGGY CODE ###

n = int(input())
S = list(input())
r = 0
h = 0
for i in range(n-1):
  if S[i] == "#" and S[i+1] == ".":
    r = max(r, S[:i+1].count("#"))
    h = max(h, S[i:].count("."))  
print(min(r,h))

### FIXED CODE ###

n = int(input())
s=input()
if ('.' not in s) or ('#' not in s):
    print(0)
    exit()
bc = [0 for i in range(n)]
wc = [0 for i in range(n)]
for i in range(n):
  if s[i] == '#':
    bc[i] = 1
  else:
    wc[i] = 1
for i in range(n-1):
  bc[i+1] += bc[i]
for i in range(n-1,0,-1):
  wc[i-1] += wc[i]
ans = min(wc[0],bc[-1])
for i in range(n-1):
  ans = min(ans,bc[i]+wc[i+1])
print(ans)
### BUGGY CODE ###

from itertools import product


X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))


lst_AB = [a + b for a, b in product(lst_A, lst_B)]
lst_AB.sort(reverse=True)


lst_ABC = [ab + c for ab, c in list(product(lst_AB[:min(3000, X*Y*Z)], lst_C))]
lst_ABC.sort(reverse=True)


print(*lst_ABC[:K], sep="\n")


### FIXED CODE ###

import sys
from itertools import product


X, Y, Z, K = map(int, input().split())
lst_A = list(map(int, input().split()))
lst_B = list(map(int, input().split()))
lst_C = list(map(int, input().split()))
lst_A.sort(reverse=True)
lst_B.sort(reverse=True)
lst_C.sort(reverse=True)

# lst_A_K = lst_A[:K]
# lst_B_K = lst_B[:K]
lst_C_K = lst_C[:K]


lst_AB = sorted([a+b for a, b in product(lst_A, lst_B)], reverse=True)
lst_AB_K = lst_AB[:K]

lst_ABC = sorted([ab+c for ab, c in product(lst_AB_K, lst_C_K)], reverse=True)
lst_ABC_K = lst_ABC[:K]

print(*lst_ABC_K, sep="\n")
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    dp = [0] * (N+1)
    for i in range(1, N+1):
        gold, silver, copper = 0, 0, 0
        if i >= A[0]:
            gold = dp[i-A[0]] + B[0]
        if i >= A[1]:
            silver = dp[i-A[1]] + B[1]
        if i >= A[2]:
            copper = dp[i-A[2]] + B[2]
        dp[i] = max(i, gold, silver, copper)

    M = dp[N]
    dp = [0] * (M+1)
    for i in range(1, M+1):
        gold, silver, copper = 0, 0, 0
        if i >= B[0]:
            gold = dp[i-B[0]] + A[0]
        if i >= B[1]:
            silver = dp[i-B[1]] + A[1]
        if i >= B[2]:
            copper = dp[i-B[2]] + A[2]
        dp[i] = max(i, gold, silver, copper)

    return dp[M]


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    dp = [0] * (N+1)
    for i in range(1, N+1):
        gold, silver, copper = 0, 0, 0
        if i >= A[0]:
            gold = dp[i-A[0]] + B[0]
        if i >= A[1]:
            silver = dp[i-A[1]] + B[1]
        if i >= A[2]:
            copper = dp[i-A[2]] + B[2]
        dp[i] = max(i, gold, silver, copper)

    M = dp[N]
    dp = [0] * (M+1)
    for i in range(1, M+1):
        gold, silver, copper = 0, 0, 0
        if i >= B[0]:
            gold = dp[i-B[0]] + A[0]
        if i >= B[1]:
            silver = dp[i-B[1]] + A[1]
        if i >= B[2]:
            copper = dp[i-B[2]] + A[2]
        dp[i] = max(i, gold, silver, copper)

    return dp[M]


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

import sys
N,M = map(int,input().split())
A = []
B = []
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    A.append(tmp_a)
    B.append(tmp_b)
sum_A,sum_B = 0,0
for i in range(N):
    min_index = A.index(min(A))
    if (M-sum_B) > B[min_index]:
        sum_A += min(A)*B[min_index]
        sum_B += B[min_index]
        A.pop(min_index)
        B.pop(min_index)
    else:
        sum_A += min(A)*(M-sum_B)
        print(sum_A)
        sys.exit()

### FIXED CODE ###

import sys
N,M = map(int,input().split())
List =[]
for i in range(N):
    tmp_a,tmp_b = map(int,input().split())
    List.append([tmp_a,tmp_b])
List.sort()
sum_a,sum_b = 0,0
for i in range(N):
    if M-sum_b > List[i][1]:
        sum_a += List[i][0]*List[i][1]
        sum_b += List[i][1]
    else:
        sum_a += List[i][0]*(M-sum_b)
        sum_b += M-sum_b
        print(sum_a)
        sys.exit()
### BUGGY CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;

for i in range(Q):
  listA.sort()
  for j in range(len(listA)):
    if listA[j]==listB[i][0]:
      listA[j]=listB[i][1]
    elif listA[j]>listB[i][0]:
      break
  #print(listA)
  print(sum(listA))

### FIXED CODE ###

N=int(input())
listA=list(map(int, input().split()))
Q=int(input())

listB=[] #appendのために宣言が必要
while True:
    try:
        listB.append(list(map(int,input().split())))

    except:
        break;
        
sum=sum(listA)
numlist=[0]*(10**5+1)
for i in listA:
  numlist[i]+=1
  
for i in range(Q):
  B=listB[i][0]
  C=listB[i][1]
  if numlist[B]!=0:
    sum=sum+(C-B)*numlist[B]
    # print(C)
    numlist[C]+=numlist[B]
    numlist[B]=0
    # print(numlist)
  print(sum)
### BUGGY CODE ###

k = int(input())
s = input()
len_s = len(s)
MOD = 1000000007

pow26 = [1] * (k + 1)
pow25 = [1] * (k + 1)
comb = [1] * (k + 1)

for i in range(k):
  pow26[i+1] = (pow26[i] * 26) % MOD
  pow25[i+1] = (pow25[i] * 25) % MOD
  comb[i+1] =((((comb[i] * (len_s + i)) % MOD)) * pow(i + 1, -1, MOD)) % MOD

a = 0
for i in range(k + 1):
  a += (((comb[k-i] * pow26[i]) % MOD) * pow25[k-i]) % MOD
  a %= MOD

print(a)

### FIXED CODE ###

k = int(input())
s = input()
len_s = len(s)
MOD = 1000000007

x_i = pow(26, k, MOD)
r = (25 * pow(26, -1, MOD)) % MOD
comb_i = 1

a = 0
for i in range(k + 1):  
  a += (comb_i  * x_i  ) % MOD
  a %= MOD
  
  x_i  = (x_i  * r) % MOD
  comb_i = (comb_i * (len_s + i) * pow(i + 1, -1, MOD)) % MOD


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

def resolve():
    a, b, x = map(int, input().split())

    cnt = 0
    for i in range(a, b + 1):
        if i % x == 0:
            cnt += 1

    print(cnt)


resolve()


### FIXED CODE ###

# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    a, b, x = map(int, input().split())

    print(b//x-(a-1)//x)


resolve()
### BUGGY CODE ###

n, *a = map(int, open(0).read().split())
b = set()
for i in a:
    b = b ^ {i}
print(len(b))

### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict
n, *a = map(int, open(0).read().split())
b = defaultdict(int)
for i in a:
    b[i] += 1
print(sum(i % 2 > 0 for i in b.values()))
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]
#print(list)

for i in range(Q):
    l,r = map(int, input().split())
    list[i][0] = l
    list[i][1] = r

for i in range(Q):
    sub_S = S[list[i][0]-1:list[i][1]]
    count = 0
    for j in range(len(sub_S)-1):
        if sub_S[j] == 'A':
            if sub_S[j:j+2] == 'AC':
                count += 1
                j += 1
    print(count)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
list = [[0 for i in range(2)] for j in range(Q)]

b = [0] * (N+1)
for i in range(N):
    if S[i:i+2] == 'AC':
        b[i+1] = b[i] + 1
    else:
        b[i+1] = b[i]
for i in range(Q):
    l,r = map(int, input().split())
    print(b[r-1]-b[l-1])
### BUGGY CODE ###

K, S = map(int, input().split())
n = 0
for i in range(K + 1):
    for j in range(K + 1):
        for k in range(K + 1):
            if (i + j + k) == S:
                n += 1
print(str(n))


### FIXED CODE ###

K, S = map(int, input().split())
n = 0
for x in range(K + 1):
    for y in range(K + 1):
        if (x + y) > S:
            break
        elif (S - (x + y)) <= K:
            n += 1
print(str(n))
### BUGGY CODE ###

n, m, qqq = map(int, input().split())
LR1 = [[] for _ in range(n)]
LR2 = [[] for _ in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    if l < n-r:
        for j in range(l):
            LR1[j].append(r)
    else:
        for j in range(r-1, n):
            LR2[j].append(l)


for i in range(qqq):
    p, q = map(int, input().split())
    ans = 0
    for j in LR1[p-1]:
        if j <= q:
            ans+=1
    for j in LR2[q-1]:
        if j >= p:
            ans+=1
    print(ans)
# print(LR1, LR2)

### FIXED CODE ###

n, m, qqq = map(int, input().split())
DP = [[0 for _ in range(n)]for __ in range(n)]

for i in range(m):
    l, r = map(int, input().split())
    DP[l-1][r-1]+=1


#DP = [[0 for _ in range(n)]for __ in range(n)]
for i in range(n-1)[::-1]:
    for j in range(1,n):
        DP[i][j] += DP[i+1][j]+DP[i][j-1]-DP[i+1][j-1]

for i in range(qqq):
    p, q = map(int, input().split())
    print(DP[p-1][q-1])
# print(DP)
### BUGGY CODE ###

N = int(input())
mod = 10**9 + 7
A = sorted([int(i) for i in input().split()])
bits = [0]*61

ans = 0
for i, a in enumerate(A):
    for b in range(len(bin(a))-2):
        if (a >> b) & 1:
            ans += (2**b)*(i-bits[b])
            bits[b] += 1
        else:
            ans += (2**b)*bits[b]
    ans %= mod
print(ans)


### FIXED CODE ###

import numpy as np

N = int(input())
mod = 10**9 + 7
A = np.array(input().split(), dtype=np.int64)
# print(A)

ans = 0
for i in range(60):
    b = np.count_nonzero(A >> i & 1)
    ans += 2**i*(b*(N-b))
    ans %= mod
    # c = np.count_nonzero(A >> i)
    # print(c)
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N-1):
        for j in range(i, N):
            if S[i] == S[j]:
                continue
            c = 'RGB'.replace(S[i], '')
            c = c.replace(S[j], '')
            ans += S[j+1:].count(c)
            if 2*j - i < N and S[2*j-i] == c:
                ans -= 1
    print(ans)

main()

### FIXED CODE ###

from collections import Counter
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    ans = 0
    r, g, b = [0 for _ in range(N+1)], [0 for _ in range(N+1)], [0 for _ in range(N+1)]
    for i in range(N):
        r[i+1], g[i+1], b[i+1] = r[i], g[i], b[i]
        if S[i] == "R":
            r[i+1] += 1
        elif S[i] == "G":
            g[i+1] += 1
        else:
            b[i+1] += 1
    
    for i in range(1, N-1):
        if S[i] == "R":
            ans += g[i] * (b[N] - b[i+1]) + b[i] * (g[N] - g[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"G", "B"}:
                    ans -= 1
        
        elif S[i] == "G":
            ans += r[i] * (b[N] - b[i+1]) + b[i] * (r[N] - r[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"R", "B"}:
                    ans -= 1
        elif S[i] == "B":
            ans += g[i] * (r[N] - r[i+1]) + r[i] * (g[N] - g[i+1])
            for j in range(1, min(i, N-i-1)+1):
                if {S[i-j], S[i+j]} == {"G", "R"}:
                    ans -= 1
    print(ans)

main()
### BUGGY CODE ###

from scipy.misc import comb

N = int(input())
num_list = list(map(int, input().split()))
num_set = set(num_list)

# 全数あるときの組み合わせ
ans_dict_1 = {}
# 1個抜いたときの組み合わせ
ans_dict_2 = {}

for i in num_set:
  ans_dict_1[i] = comb(num_list.count(i),2,exact=True)
  ans_dict_2[i] = comb(num_list.count(i)-1,2,exact=True)

total = sum(ans_dict_1.values())

for i in num_list:
  print(total - ans_dict_1[i] + ans_dict_2[i])

### FIXED CODE ###

from scipy.misc import comb
from collections import Counter
import datetime

N = int(input())
num_list = list(map(int, input().split()))
# num_set = set(num_list)
num_dict = {}

num_counter = Counter(num_list)
  
# 全数あるときの組み合わせ
ans_dict_1 = {}
# 1個抜いたときの組み合わせ
ans_dict_2 = {}
rap_2 = datetime.datetime.now()
for k, v in num_counter.most_common():
  ans_dict_1[k] = comb(v,2,exact=True)
  ans_dict_2[k] = comb(v-1,2,exact=True)

total = sum(ans_dict_1.values())

for i in num_list:
  print(total - ans_dict_1[i] + ans_dict_2[i])
### BUGGY CODE ###

N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

for i in range(N):
  B=A[:]
  del B[i]
  print(max(B))


### FIXED CODE ###

N=int(input())
A=[]
for i in range(N):
  A.append(int(input()))

maxA=max(A)
countNumber=A.count(maxA)

for i in range(N):
  if A[i]<maxA:
    print(maxA)
  elif countNumber>1:
    print(maxA)
  else:
    B=A[:]
    del B[i]
    print(max(B))
### BUGGY CODE ###

S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)

uniques = list(set(mod))
for i in uniques:
  if mod.count(i) != 1:
    cnt += (mod.count(i) * (mod.count(i) - 1)) // 2


print(cnt)

### FIXED CODE ###

import collections
S = input()
cnt = 0

mod = [0]
reverse_S = S[::-1]
for i in range(len(reverse_S)):
  now = int(reverse_S[i]) * pow(10,i,2019)
  mod.append((now + mod[i]) % 2019)


c = collections.Counter(mod)
hindo = c.values()
for i in hindo:
  if i != 1:
    cnt += i*(i-1)//2


print(cnt)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:22:42 2019

@author: doppe
"""
import copy
import math


def isAnagram(dict, str2):
    dictCopy = copy.copy(dict)
    for c2 in str2:
        if (c2 in dictCopy):
            dictCopy[c2] -= 1
            if (dictCopy[c2] < 0):
                return False
        else:
            return False
    return True
 
def makeDict(str1):
    dict = {}
    for c in str1:
        if (c in dict):
            dict[c] += 1
        else:
            dict[c] = 1
    return dict

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}
for i in range(0, len(S)):
    if (i in groupList):
        continue
    dict = makeDict(S[i])
    for j in range(i + 1, len(S)):
        if (j in groupList):
            continue
        if (isAnagram(dict, S[j])):
            groupList.append(j)
            if (i in groupDict):
                groupDict[i] += 1
            else:
                groupDict[i] = 2

for v in groupDict.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(int(ans))