Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
def com(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

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

cnt = Counter(a)
for i in range(1, n + 1):
    temp = a[i - 1]
    ans = 0
    for num, k in cnt.items():
        kosu = k
        if num == temp:
            kosu -= 1
        if kosu >= 2:
            ans += com(kosu, 2)

    print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
import math
def com(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

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

cnt = Counter(a)
for i in range(1, n + 1):
    temp = a[i - 1]
    ans = 0
    for num, k in cnt.items():
        kosu = k
        if num == temp:
            kosu -= 1
        if kosu >= 2:
            ans += com(kosu, 2)

    print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans={}
for i in set(a):
    temp=cnt[i]-1
    ans[i]=0
    for x,y in cnt.items():
        if x!=i and y>=2:
            ans[i]+=(y-1)*y//2
        elif x==i and temp>=2:
            ans[i]+=(temp-1)*temp//2

for i in a:
    print(ans[i])

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)

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

from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans={}
for i in set(a):
    temp=cnt[i]-1
    ans[i]=0
    for x,y in cnt.items():
        if x!=i and y>=2:
            ans[i]+=(y-1)*y//2
        elif x==i and temp>=2:
            ans[i]+=(temp-1)*temp//2

for i in a:
    print(ans[i])

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)

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

from collections import Counter,defaultdict
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=defaultdict(lambda :0)
for i in set(a):
    temp=cnt[i]-1
    for x,y in cnt.items():
        if x!=i and y>=2:
            ans[i]+=(y-1)*y//2
        elif x==i and temp>=2:
            ans[i]+=(temp-1)*temp//2

for i in a:
    print(ans[i])

Fixed submission:
import sys
input=sys.stdin.readline
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
cnt=Counter(a)
#print(cnt)

ans=0
for i in cnt.values():
    ans=ans+i*(i-1)//2

for i in a:
    print(ans-cnt[i]+1)