Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

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

	S = Counter(A)
	for a in A:
		S[a] -= 1
		ans = 0
		for d in S.values():
			ans += cmb2(d)
		print(ans)
		S[a] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import Counter

def cmb2(n):
	result = n * (n - 1) / 2

	return int(result)

if __name__ == "__main__":

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

	S = Counter(A)
	for a in A:
		S[a] -= 1
		ans = 0
		for d in S.values():
			ans += cmb2(d)
		print(ans)
		S[a] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
def cmb2(n):
	result = n * (n - 1) / 2

	return result

if __name__ == "__main__":

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

	A_set = set(A)

	ans_d = {}
	for a_s in A_set:
		#print(A.count(a))
		ans_d[str(a_s)] = A.count(a_s)



	for a in A:
		A_new = ans_d.copy()
		A_new[str(a)] -= 1
		ans = 0
		#print(A_new)
		#print("="*10)
		for a_n in A_new.values():
			if a_n <= 1:
				continue
			else:
				ans += cmb2(a_n)
		print(int(ans))
		#ans_d[str(a)] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
def cmb2(n):
	result = n * (n - 1) / 2

	return result

if __name__ == "__main__":

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

	A_set = set(A)

	ans_d = {}
	for a_s in A_set:
		#print(A.count(a))
		ans_d[str(a_s)] = A.count(a_s)

	for a in A:
		#A_new = ans_d.copy()
		ans_d[str(a)] -= 1
		ans = 0
		#print(A_new)
		#print("="*10)
		for a_n in ans_d.values():
			if a_n <= 1:
				continue
			else:
				ans += cmb2(a_n)
		print(int(ans))
		ans_d[str(a)] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
def cmb2(n):
	result = n * (n - 1) / 2

	return int(result)

if __name__ == "__main__":

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

	A_set = set(A)

	ans_d = {}
	for a_s in A_set:
		ans_d[str(a_s)] = A.count(a_s)

	for a in A:
		ans_d[str(a)] -= 1
		ans = 0
		for a_n in ans_d.values():
			if a_n <= 1:
				continue
			else:
				ans += cmb2(a_n)
		print(ans)
		ans_d[str(a)] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

A_set = set(A)

def cmb2(n):
	result = n * (n - 1) / 2

	return int(result)

ans_d = {}
for a_s in A_set:
	#print(A.count(a))
	ans_d[str(a_s)] = A.count(a_s)

for a in A:
    #A_new = ans_d.copy()
    ans_d[str(a)] -= 1
    ans = 0
    #print(A_new)
    #print("="*10)
    for a_n in ans_d.values():
        if a_n <= 1:
            continue
        else:
            ans += cmb2(a_n)
    print(ans)
    ans_d[str(a)] += 1

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

A_set = set(A)

def cmb2(n):
	result = n * (n - 1) / 2

	return int(result)

ans_d = {}
for a_s in A_set:
	#print(A.count(a))
	ans_d[str(a_s)] = A.count(a_s)

for a in A:
    A_new = ans_d.copy()
    A_new[str(a)] -= 1
    ans = 0
    #print(A_new)
    #print("="*10)
    for a_n in A_new.values():
        if a_n <= 1:
            continue
        else:
            ans += cmb2(a_n)
    print(ans)

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

A_set = set(A)

def cmb(n, r):
    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

ans_d = {}
for a_s in A_set:
	#print(A.count(a))
	ans_d[str(a_s)] = A.count(a_s)

for a in A:
    A_new = ans_d.copy()
    A_new[str(a)] -= 1
    ans = 0
    #print(A_new)
    #print("="*10)
    for a_n in A_new.values():
        if a_n <= 1:
            continue
        else:
            ans += cmb(a_n, 2)
    print(ans)

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(i) for i in input().split()]

A_set = set(A)

def cmb(n, r):
    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

ans_d = {}
for a_s in A_set:
	#print(A.count(a))
	ans_d[str(a_s)] = A.count(a_s)

for a in A:
    A_new = ans_d.copy()
    A_new[str(a)] -= 1
    ans = 0
    #print(A_new)
    #print("="*10)
    for a_n in A_new.values():
        if a_n <= 1:
            continue
        else:
            ans += cmb(a_n, 2)
    print(ans)

Fixed submission:
import sys
from collections import Counter

def cmb2(n):
	if n < 2:
		return 0

	return n * (n-1) // 2

if __name__ == "__main__":

	N = int(input())
	A = [int(i) for i in input().split()]
	# A = list(map(int, input().split()))

	c = Counter(A)
	s = 0
	for v in c.values():
		s += cmb2(v)

	for a in A:
		print(s - cmb2(c[a]) + cmb2(c[a] - 1))