Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
aset = set(alist)
blist = list(aset)
from math import factorial
def cmb(n,r):
  a = factorial(n) // factorial(r) // factorial(n - r)
  return a
ans1 = sum([cmb(alist.count(i),2) for i in blist if alist.count(i) >= 2])
for i in range(n):
  if alist.count(alist[i]) >= 2:
    print(ans1-alist.count(alist[i])+1)
  else:
    print(ans1)


Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
aalist = [0]*n
aset = set(alist)
adic = {}
for a in alist:
    if a not in adic:
        adic[a] = 0
    adic[a] += 1
a_counter = list(adic.items())

sigma = 0
for counter in a_counter:
    sigma += counter[1] * (counter[1] - 1) // 2

for i in range(n):
    aalist[i] = adic[alist[i]]-1

anslist = []
for a in aalist:
    anslist.append(sigma - a)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
aset = set(alist)
blist = list(aset)
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
ans1 = sum([cmb(alist.count(i),2) for i in blist if alist.count(i) >= 2])
for i in range(n):
  if alist.count(alist[i]) >= 2:
    print(ans1-alist.count(alist[i])+1)
  else:
    print(ans1)


Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
aalist = [0]*n
aset = set(alist)
adic = {}
for a in alist:
    if a not in adic:
        adic[a] = 0
    adic[a] += 1
a_counter = list(adic.items())

sigma = 0
for counter in a_counter:
    sigma += counter[1] * (counter[1] - 1) // 2

for i in range(n):
    aalist[i] = adic[alist[i]]-1

anslist = []
for a in aalist:
    anslist.append(sigma - a)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
pcount = len(set(alist))
blist = list(set(alist))
ans = 0
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

for i in range(n):
  for j in blist:
    if alist[i] == j:
      if alist.count(j)-1>=2:
        ans += cmb(alist.count(j)-1,2)

    else:
      if alist.count(j)>=2:
        ans += cmb(alist.count(j),2)
  print(ans)
  ans = 0


Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
aalist = [0]*n
aset = set(alist)
adic = {}
for a in alist:
    if a not in adic:
        adic[a] = 0
    adic[a] += 1
a_counter = list(adic.items())

sigma = 0
for counter in a_counter:
    sigma += counter[1] * (counter[1] - 1) // 2

for i in range(n):
    aalist[i] = adic[alist[i]]-1

anslist = []
for a in aalist:
    anslist.append(sigma - a)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n = int(input())
alist = tuple(map(int,input().split()))
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

adic = {}
ans = 0
for i in alist:
  if i not in adic:
    adic[i] = 1
  else:
    adic[i] += 1
for i in range(n):
  for j in adic:
    if j == alist[i]:
      if adic[j] >= 3:
        ans += cmb(adic[j]-1,2)
      else:
        ans += 0
    else:
      if adic[j] >= 2:
        ans += cmb(adic[j],2)
      else:
        ans += 0
  print(ans)
  ans = 0

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
aalist = [0]*n
aset = set(alist)
adic = {}
for a in alist:
    if a not in adic:
        adic[a] = 0
    adic[a] += 1
a_counter = list(adic.items())

sigma = 0
for counter in a_counter:
    sigma += counter[1] * (counter[1] - 1) // 2

for i in range(n):
    aalist[i] = adic[alist[i]]-1

anslist = []
for a in aalist:
    anslist.append(sigma - a)

for ans in anslist:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
alist = list(map(int,input().split()))
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

adic = {}
ans = 0
for i in alist:
  if i not in adic:
    adic[i] = 1
  else:
    adic[i] += 1
for i in range(n):
  for j in adic:
    if j == alist[i]:
      if adic[j] >= 3:
        ans += cmb(adic[j]-1,2)
      else:
        ans += 0
    else:
      if adic[j] >= 2:
        ans += cmb(adic[j],2)
      else:
        ans += 0
  print(ans)
  ans = 0

Fixed submission:
import sys
input = sys.stdin.readline
n = int(input())
alist = list(map(int,input().split()))
aalist = [0]*n
aset = set(alist)
adic = {}
for a in alist:
    if a not in adic:
        adic[a] = 0
    adic[a] += 1
a_counter = list(adic.items())

sigma = 0
for counter in a_counter:
    sigma += counter[1] * (counter[1] - 1) // 2

for i in range(n):
    aalist[i] = adic[alist[i]]-1

anslist = []
for a in aalist:
    anslist.append(sigma - a)

for ans in anslist:
    print(ans)