Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from math import factorial
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += factorial(v) // factorial(2) // factorial(v - 2)


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = factorial(c[A[i]]) // factorial(2) // factorial(c[A[i]] - 2)
    count = factorial(num) // factorial(2) // factorial(num - 2)
    print(a - old + count)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)

Buggy python submission (verdict: Time Limit Exceeded):
# コードとしては正しいけどTLEが出る
# from collections import Counter
# from math import factorial
# N = int(input())
# A = list(map(int, input().split()))

# Length = len(list(set(A)))

# if (Length == len(A)):
#     for i in range(N):
#         print(0)
#     exit()

# c = Counter(A)
# d = [0] * N
# count = 0
# for i in range(N):
#     if (d[A[i]] != 0):
#         print(d[A[i]])
#         continue

#     if (c[A[i]] == 1):
#         for j, v in c.items():
#             if (v == 1):
#                 continue
#             else:
#                 count += factorial(v) // factorial(2) // factorial(v - 2)
#     else:
#         for j, v in c.items():
#             if (v == 1):
#                 continue
#             elif (j == A[i] and v - 1 != 1):
#                 count += factorial(v - 1) // factorial(2) // factorial(v - 3)
#             elif (j == A[i] and v - 1 == 1):
#                 continue
#             else:
#                 count += factorial(v) // factorial(2) // factorial(v - 2)
#     d[A[i]] = count
#     print(count)
#     count = 0

from collections import Counter
from math import factorial
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += factorial(v) // factorial(2) // factorial(v - 2)


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = factorial(c[A[i]]) // factorial(2) // factorial(c[A[i]] - 2)
    count = factorial(num) // factorial(2) // factorial(num - 2)
    print(a - old + count)


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from math import factorial
N = int(input())
A = list(map(int, input().split()))

Length = len(list(set(A)))

if (Length == len(A)):
    for i in range(N):
        print(0)
    exit()

c = Counter(A)
d = [0] * N
count = 0
for i in range(N):
    if (d[A[i]] != 0):
        print(d[A[i]])
        continue

    if (c[A[i]] == 1):
        for j, v in c.items():
            if (v == 1):
                continue
            else:
                count += factorial(v) // factorial(2) // factorial(v - 2)
    else:
        for j, v in c.items():
            if (v == 1):
                continue
            elif (j == A[i] and v - 1 != 1):
                count += factorial(v - 1) // factorial(2) // factorial(v - 3)
            elif (j == A[i] and v - 1 == 1):
                continue
            else:
                count += factorial(v) // factorial(2) // factorial(v - 2)
    d[A[i]] = count
    print(count)
    count = 0


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
from math import factorial
N = int(input())
A = list(map(int, input().split()))

count = 0
for i in range(N):
    if (i == 0):
        ap = A[1:]
    elif(i == N - 1):
        ap = A[:i]
    else:
        ap = A[:i] + A[i + 1:]
    c = Counter(ap)
    for j, v in c.items():
        if (v <= 1):
            continue
        else:
            count += factorial(v) // factorial(2) // factorial(v - 2)
    print(count)

    count = 0


Fixed submission:
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

allCount = 0
c = Counter(A)

for i, v in c.items():
    if (v == 1):
        continue
    else:
        allCount += v * (v - 1) // 2


if (allCount == 0):
    for i in range(N):
        print(0)
    exit()

for i in range(N):
    a = allCount
    num = c[A[i]] - 1
    if (num == 1 or num == 0):
        print(allCount - num)
        continue
    old = c[A[i]] * (c[A[i]] - 1) // 2
    count = num * (num - 1) // 2
    print(a - old + count)