Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
import collections
from functools import reduce
from operator import mul

def combinations_count2(n, r):
    if n < 2:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

c = collections.Counter(A)

dic = {}
for i in c:
    dic[i]= [combinations_count2(c[i], 2), combinations_count2(c[i] - 1, 2)]
dic_ans = {}
for ai in A:
    if ai in dic_ans:
        print(dic_ans[ai])
        continue
    ans = 0
    for i in dic:
        if i == ai:
            ans += dic[i][1]
        else:
            ans += dic[i][0]
    print(ans)


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
import collections
from functools import reduce
from operator import mul

def combinations_count2(n, r):
    if n < 2:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

c = collections.Counter(A)

dic = {}
for i in c:
    dic[i]= [combinations_count2(c[i], 2), combinations_count2(c[i] - 1, 2)]
dic_ans = {}
for ai in A:
    if ai in dic_ans:
        print(dic_ans[ai])
        continue
    ans = 0
    for i in dic:
        if i == ai:
            ans += dic[i][1]
        else:
            ans += dic[i][0]
    print(ans)


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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
import collections
from functools import reduce
from operator import mul

def combinations_count2(n, r):
    if n < 2:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

c = collections.Counter(A)

dic = {}
for i in c:
    dic[i]= [combinations_count2(c[i], 2), combinations_count2(c[i] - 1, 2)]
dic_ans = {}
for ai in A:
    if ai in dic_ans:
         print(dic_ans[ai])
    ans = 0
    for i in dic:
        if i == ai:
            ans += dic[i][1]
        else:
            ans += dic[i][0]
    print(ans)

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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
 
import collections
from functools import reduce
from operator import mul

def combinations_count2(n, r):
    if n < 2:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

c = collections.Counter(A)

dic = {}
for i in c:
    dic[i]= [combinations_count2(c[i], 2), combinations_count2(c[i] - 1, 2)]

for ai in A:
    ans = 0
    for i in dic:
        if i == ai:
            ans += dic[i][1]
        else:
            ans += dic[i][0]
    print(ans)

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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

import collections
import copy
import math
def combinations_count(n, r):
    if n < 2:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c = collections.Counter(A)
c_copy = copy.copy(c)
for ai in A:
    c[ai] -= 1
    ans = 0
    for i in c:
        ans += combinations_count(c[i], 2)
    c = copy.copy(c_copy)
    print(ans)

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

d = {}
for a in A:
    if a in d:
        d[a] += 1
    else:
        d[a] = 1

s = 0
for k in d:
    s += d[k] * (d[k] - 1) // 2

for i in range(N):
    t = d[A[i]]
    print(s - t * (t - 1) // 2 + (t - 1) * (t - 2) // 2)