Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (n+1)
numSet = set()

resultList = [0] * (n+1)
resultSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

for i in range(len(a)):
    if(a[i] in resultSet):
        print(resultList[a[i]])
        continue
    s = 0
    for j in numSet:
        if(j == a[i]):
            if(numList[j]>2):
                s += ncr(numList[j]-1,2)
        else:
            s += ncr(numList[j],2)
    print(s)
    resultList[a[i]] = s
    resultSet.add(a[i])

    


Fixed submission:
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (n+1)
numSet = set()

ncrList = [0] * (n+1)

resultList = [0] * (n+1)
resultSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

sums = 0
for i in numSet:
    ncrList[i] = ncr(numList[i], 2)
    sums += ncrList[i]

for i in range(len(a)):
    if(a[i] in resultSet):
        print(resultList[a[i]])
        continue
    s = sums
    if(a[i] in numSet):
        if(numList[a[i]] == 2):
            s -= 1
        else:
            s -= ncrList[a[i]]
            s += ncr(numList[a[i]]-1, 2)
    print(s)
    resultList[a[i]] = s
    resultSet.add(a[i])

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (2*(10**5))
numSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

for i in range(len(a)):
    s = 0
    for j in numSet:
        if(j == a[i]):
            if(numList[j]>2):
                s += ncr(numList[j]-1,2)
        else:
            s += ncr(numList[j],2)
    print(s)

    


Fixed submission:
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (n+1)
numSet = set()

ncrList = [0] * (n+1)

resultList = [0] * (n+1)
resultSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

sums = 0
for i in numSet:
    ncrList[i] = ncr(numList[i], 2)
    sums += ncrList[i]

for i in range(len(a)):
    if(a[i] in resultSet):
        print(resultList[a[i]])
        continue
    s = sums
    if(a[i] in numSet):
        if(numList[a[i]] == 2):
            s -= 1
        else:
            s -= ncrList[a[i]]
            s += ncr(numList[a[i]]-1, 2)
    print(s)
    resultList[a[i]] = s
    resultSet.add(a[i])

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
def ncr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (2*(10**5))
numSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

for i in range(len(a)):
    s = 0
    for j in numSet:
        if(j == a[i]):
            if(numList[j]>2):
                s += ncr(numList[j]-1,2)
        else:
            s += ncr(numList[j],2)
    print(s)

    


Fixed submission:
from operator import mul
from functools import reduce

def ncr(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
a = list(map(int, input().split()))

numList = [0] * (n+1)
numSet = set()

ncrList = [0] * (n+1)

resultList = [0] * (n+1)
resultSet = set()

for i in range(len(a)):
    numList[a[i]] += 1
    if(numList[a[i]]==2):
        numSet.add(a[i])

sums = 0
for i in numSet:
    ncrList[i] = ncr(numList[i], 2)
    sums += ncrList[i]

for i in range(len(a)):
    if(a[i] in resultSet):
        print(resultList[a[i]])
        continue
    s = sums
    if(a[i] in numSet):
        if(numList[a[i]] == 2):
            s -= 1
        else:
            s -= ncrList[a[i]]
            s += ncr(numList[a[i]]-1, 2)
    print(s)
    resultList[a[i]] = s
    resultSet.add(a[i])