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

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Fixed submission:
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
combs,total={},0
cnt=[0]*n
for a in A:
  cnt[a-1]+=1
for a in set(A):
  tmp=comb(cnt[a-1],2)
  combs[a]=tmp
  total+=tmp
for a in A:
  print(total-combs[a]+comb(cnt[a-1]-1,2))

Fixed submission:
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
cnt,combs,total={},{},0
for a in set(A):
  cnt[a]=A.count(a)
  tmp=comb(cnt[a],2)
  combs[a]=tmp
  total+=tmp
for a in A:
  print(total-combs[a]+comb(cnt[a]-1,2))

Fixed submission:
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
cnt={}
for a in set(A):
  cnt[a]=A.count(a)
combs,total={},0
for c in cnt:
  tmp=comb(cnt[c],2)
  combs[c]=tmp
  total+=tmp
for a in A:
  print(total-combs[a]+comb(cnt[a]-1,2))

Fixed submission:
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import math
n=int(input())
A=list(map(int,input().split()))

def comb(n, r):
  if n<=1:
    return 0
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
cnt=[]
for i in range(max(A)):
  cnt.append(A.count(i+1))
combs=[]
for c in cnt:
  combs.append(comb(c,2))
total=sum(combs)
for a in A:
  print(total-combs[a-1]+comb(cnt[a-1]-1,2))

Fixed submission:
from operator import mul
from functools import reduce
import collections
n=int(input())
A=list(map(int,input().split()))

def comb(n,r):
    r = min(n-r,r)
    if n<=1: return 0
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
  
c=collections.Counter(A)
combs,total=[0]*n,0
for a in set(A):
  tmp=comb(c[a],2)
  combs[a-1]=tmp
  total+=tmp
for a in A:
  print(total-combs[a-1]+comb(c[a]-1,2))