Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
list=[]
list1={}

for i in range(N):
    if A[i] not in list:
        list.append(A[i])
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        a=[j*(j-1)/2 for j in c.values() if j>1]
        print(int(sum(a)))
        A[i]=x
        list1[A[i]]=sum(a)
        
    else:
        print(int(list1[A[i]]))



Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
list=[]
list1={}

for i in range(N):
    if A[i] not in list:
        list.append(A[i])
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        for j in c.values():
            sum+=j*(j-1)/2
        print(int(sum))
        A[i]=x
        list1[A[i]]=sum
        sum=0
    else:
        print(int(list1[A[i]]))


Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

Buggy python submission (verdict: Time Limit Exceeded):
import collections

def main():
    N=int(input())
    A=list(map(int,input().split()))
    sum=0
    for i in range(N):
        x=A[i]
        A[i]=0
        c=collections.Counter(A)
        for j in c.values():
            sum+=j*(j-1)/2
        print(int(sum))
        sum=0
        A[i]=x


if __name__ == '__main__':
    main()



Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
    x=A[i]
    A[i]=0
    c=collections.Counter(A)
    for j in c.values():
        sum+=j*(j-1)/2
    print(int(sum))
    sum=0
    A[i]=x

Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
    x=A[i]
    A[i]=0
    c=collections.Counter(A)
    for j in c.values():
        sum+=j*(j-1)/2
    print(int(sum))
    sum=0
    A[i]=x

Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N=int(input())
A=list(map(int,input().split()))
sum=0
for i in range(N):
    x=A.pop(i)
    c=collections.Counter(A)
    for j in c.values():
        sum+=j*(j-1)/2
    print(int(sum))
    sum=0
    A.insert(i,x)


Fixed submission:
import collections
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


N=int(input())
A=list(map(int,input().split()))

c=collections.Counter(A)
list=c.values()
result=0

for x in list:
    if x>1:
        result+=cmb(x,2)
for y in c.keys():
    c[y]=result-(c[y]-1)

for z in A:
    print(c[z])