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

def cmb(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

def main():

    N = int(input())

    a_l = [0] * N

    nums = list(map(int, input().split()))

    for i in nums:
        a_l[i-1] += 1

    for i in nums:
        a_l[i-1] -= 1
        total = 0
        for j in a_l:
            if j > 1:
                total += cmb(j,2)
        print(total)
        a_l[i-1] += 1




if __name__ == '__main__':
    main()

Fixed submission:
def cmb(n):
    return int(n * (n-1) / 2)

def main():

    N = int(input())

    a_l = [0] * N

    nums = list(map(int, input().split()))
    for i in nums:
        a_l[i-1] += 1

    total = 0
    for j in a_l:
        if j > 1:
            total += cmb(j)

    for k in nums:
        if a_l[k-1] > 1:
            print(total - cmb(a_l[k-1]) + cmb(a_l[k-1] - 1))
        else:
            print(total)


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Runtime Error):
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
nsum = 0

for i in setnum:
    dicnum[i] = numlist.count(i)
    if dicnum[i] >= 2:
        nsum += dicnum[i]*(dicnum[i]-1)//2
    else:
        del dicnum[i]

for j in range(n):
    ans = nsum
    if numlist[j] in dicnum:
        ans = ans - dicnum[numlist[j]] + 1
    print(ans)

Fixed submission:
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
dicnum = {}
nsum = 0

for i in setnum:
    dicnum[i] = numlist.count(i)
    if dicnum[i] >= 2:
        nsum += dicnum[i]*(dicnum[i]-1)//2
    
for j in range(n):
    ans = nsum
    cal = dicnum[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)

Fixed submission:
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
dicnum = {}
nsum = 0

for i in setnum:
    dicnum[i] = numlist.count(i)

for l in setnum:
    cal = dicnum[l]
    if cal >= 2:
        nsum += cal*(cal-1)//2
    
for j in range(n):
    ans = nsum
    dicpos = numlist[j]
    cal2 = dicnum[dicpos]
    if cal2 >= 2:
        ans = ans - (cal2-1)
    print(ans)

Fixed submission:
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = [int(_) for _ in input().split()]
setnum = set(numlist)
dicnum = {}

for i in setnum:
    dicnum[i] = numlist.count(i)
    
for j in range(n):
    ans = 0
    dicpos = numlist[j]
    for k in setnum:
        if k == dicpos:
            cal = dicnum[k] - 1
        else:
            cal = dicnum[k]
        if cal >= 2:
            ans += cal*(cal-1)//2
    print(ans)

Fixed submission:
n = int(input())
numlist = [int(_) for _ in input().split()]
numdic = {}
nsum = 0

for i in range(n):
    if numlist[i] in numdic:
        numdic[numlist[i]] += 1
    else:
        numdic[numlist[i]] = 1

for k in numdic:
    nsum += numdic[k] * (numdic[k] - 1) // 2

for j in range(n):
    ans = nsum
    cal = numdic[numlist[j]]
    if cal >= 2:
        ans = ans - (cal-1)
    print(ans)