Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
sum = 0
for i in range(N):
    sum += combinations_count(a[i], 2)
for k in range(N):
    print(sum +  combinations_count(a[A[k]-1]-1, 2) - combinations_count(a[A[k]-1], 2))


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in range(N):
    a[A[i]-1] += 1
sum = 0
for i in range(N):
    sum += combinations_count(a[i], 2)
for k in range(N):
    print(sum +  combinations_count(a[A[k]-1]-1, 2) - combinations_count(a[A[k]-1], 2))


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    if n >= 2:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in range(N):
    a[A[i]-1] += 1
sum = 0
for i in range(N):
    sum += combinations_count(a[i], 2)
for k in range(N):
    print(sum +  combinations_count(a[A[k]-1]-1, 2) - combinations_count(a[A[k]-1], 2))


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in range(N):
    a[A[i]-1] += 1
for k in range(N):
    sum = 0
    a[A[k]-1] -= 1
    for i in range(N):
        if a[i] >= 2:
            sum += combinations_count(a[i], 2)
    print(sum)
    a[A[k]-1] += 1


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))

Buggy python submission (verdict: Time Limit Exceeded):
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
A = [int(a) for a in input().split()]

for k in range(N):
    a = [0] * N
    sum = 0
    for i in range(N):
        a[A[i]-1] += 1
    a[A[k]-1] -= 1
    for i in range(N):
        if a[i] >= 2:
            sum += combinations_count(a[i], 2)
    print(sum)


Fixed submission:
N = int(input())
A = [int(a) for a in input().split()]
a = [0] * N
for i in A:
    a[i-1] += 1
cnt = 0
cnt += sum([i*(i-1)//2 for i in a])
for i in A:
    print(cnt - (a[i-1]-1))