Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
nCr = {}
def cmb(n):
    if n >= 2:
        return int(n * (n-1) / 2)
    else:
        return 0

A = input().split()
len(set(A))
B = {}
C = {}
for i in set(A):
    B[i] = cmb(A.count(i) - 1)
    C[i] = cmb(A.count(i))
sC = sum(C.values())
for i in A:
    print(B[i] - C[i] + sC)

Fixed submission:
n = int(input())

a = list(map(int, input().split()))
s = [0]*n
for i in range(n):
    s[a[i]-1] += 1
k = 0
for i in range(n):
    if s[i] >= 2:
        k += ((s[i]*(s[i]-1))//2)
for i in range(n):
    if s[a[i]-1] >= 2:
        print(k-(s[a[i]-1]-1))
    else:
        print(k)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
nCr = {}
def cmb(n, r):
    if n >= 2:
        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
    else:
        return 0

A = input().split()
len(set(A))
B = {}
C = {}
for i in set(A):
    B[i] = cmb(A.count(i) - 1, 2)
    C[i] = cmb(A.count(i), 2)
sC = sum(C.values())
for i in A:
    print(B[i] - C[i] + sC)


Fixed submission:
n = int(input())

a = list(map(int, input().split()))
s = [0]*n
for i in range(n):
    s[a[i]-1] += 1
k = 0
for i in range(n):
    if s[i] >= 2:
        k += ((s[i]*(s[i]-1))//2)
for i in range(n):
    if s[a[i]-1] >= 2:
        print(k-(s[a[i]-1]-1))
    else:
        print(k)

Buggy python submission (verdict: Runtime Error):
N = int(input())
import sys
sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if n >= 2:
        if r == 0 or r == n: return 1
        if r == 1: return n
        if (n, r) in nCr: return nCr[(n, r)]
        nCr[(n, r)] = cmb(n-1, r) + cmb(n-1, r-1)
        return nCr[(n, r)]
    else:
        return 0

A = input().split()
len(set(A))
B = {}
C = {}
for i in set(A):
    B[i] = cmb(A.count(i) - 1, 2)
    C[i] = cmb(A.count(i), 2)
sC = sum(C.values())
for i in A:
    print(B[i] - C[i] + sC)


Fixed submission:
n = int(input())

a = list(map(int, input().split()))
s = [0]*n
for i in range(n):
    s[a[i]-1] += 1
k = 0
for i in range(n):
    if s[i] >= 2:
        k += ((s[i]*(s[i]-1))//2)
for i in range(n):
    if s[a[i]-1] >= 2:
        print(k-(s[a[i]-1]-1))
    else:
        print(k)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())


def combination(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0

A = input().split()
len(set(A))
B = {}
C = {}
for i in set(A):
    B[i] = combination(A.count(i) - 1, 2)
    C[i] = combination(A.count(i), 2)
sC = sum(C.values())
for i in A:
    print(B[i] - C[i] + sC)


Fixed submission:
n = int(input())

a = list(map(int, input().split()))
s = [0]*n
for i in range(n):
    s[a[i]-1] += 1
k = 0
for i in range(n):
    if s[i] >= 2:
        k += ((s[i]*(s[i]-1))//2)
for i in range(n):
    if s[a[i]-1] >= 2:
        print(k-(s[a[i]-1]-1))
    else:
        print(k)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())


def combination(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0

A = input().split()
B = []
C = []
for i in range(N):
    B.append(combination(A.count(str(i + 1)) - 1, 2))
    C.append(combination(A.count(str(i + 1)), 2))
for i in A:
    print(B[int(i)-1] - C[int(i)-1] +sum(C))

Fixed submission:
n = int(input())

a = list(map(int, input().split()))
s = [0]*n
for i in range(n):
    s[a[i]-1] += 1
k = 0
for i in range(n):
    if s[i] >= 2:
        k += ((s[i]*(s[i]-1))//2)
for i in range(n):
    if s[a[i]-1] >= 2:
        print(k-(s[a[i]-1]-1))
    else:
        print(k)