Buggy python submission (verdict: Runtime Error):
N = int(input())
A = input().split()

L = [0 for i in range(N)]

for i in range(N):
  L[int(A[i])-1] +=1

c = 0
for i in range(N):
  n = L[i]
  if n >= 2:
    c += factorial(n) // factorial(2) // factorial(n - 2)

for i in range(N):
  n = L[A[i]-1]
  if n >= 2:
    print(c - n + 1)
  else:
      print(c)

Fixed submission:
from math import factorial
import collections

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    n = L[A[k]]
    if n >= 3:
        c1 -= n-1
    elif n == 2:
        c1 -= factorial(n) // factorial(2) // factorial(n-2)
    print(c1)

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

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    x = A[k]
    n = L[x]
    if n >= 2:
        c1 -= factorial(n) // factorial(2) // factorial(n - 2)
        if n >= 3:
            c1 += factorial(n-1) // factorial(2) // factorial(n-3)
    print(c1)

Fixed submission:
from math import factorial
import collections

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    n = L[A[k]]
    if n >= 3:
        c1 -= n-1
    elif n == 2:
        c1 -= factorial(n) // factorial(2) // factorial(n-2)
    print(c1)

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

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for z in L.items():
    if z[1] >=2:
        c += factorial(z[1]) // factorial(2) // factorial(z[1] - 2)

for k in range(N):
    c1 = c
    x = A[k]
    if L[x] >= 2:
        c1 -= factorial(L[x]) // factorial(2) // factorial(L[x] - 2)
        if L[x]-1 >= 2:
            c1 += factorial(L[x]-1) // factorial(2) // factorial(L[x]-1 - 2)
    print(c1)


Fixed submission:
from math import factorial
import collections

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    n = L[A[k]]
    if n >= 3:
        c1 -= n-1
    elif n == 2:
        c1 -= factorial(n) // factorial(2) // factorial(n-2)
    print(c1)

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

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

L = L.most_common()

c = 0
for z in L:
    if z[1] >=2:
        c += factorial(z[1]) // factorial(2) // factorial(z[1] - 2)

for k in range(N):
    c1 = c
    x = A[k]
    for z in L:
        if z[0] == x and z[1] >= 2:
            c1 -= factorial(z[1]) // factorial(2) // factorial(z[1] - 2)
            if z[1]-1 >= 2:
                c1 += factorial(z[1]-1) // factorial(2) // factorial(z[1]-1 - 2)
    print(c1)

Fixed submission:
from math import factorial
import collections

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    n = L[A[k]]
    if n >= 3:
        c1 -= n-1
    elif n == 2:
        c1 -= factorial(n) // factorial(2) // factorial(n-2)
    print(c1)

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

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

L = L.most_common()

for k in range(N):
    c = 0
    x = A[k]
    for z in L:
        if z[0] == x:
            if z[1]-1 >= 2:
                c += factorial(z[1]-1) // factorial(2) // factorial(z[1]-1 - 2)
        else:
            if z[1] >=2:
                c += factorial(z[1]) // factorial(2) // factorial(z[1] - 2)
    print(c)

Fixed submission:
from math import factorial
import collections

N = int(input())
A = input().split()
A = [int(x) for x in A]

L = collections.Counter(A)

c = 0
for i in range(1,N+1):
    n = L[i]
    if n >=2:
        c += factorial(n) // factorial(2) // factorial(n - 2)

for k in range(N):
    c1 = c
    n = L[A[k]]
    if n >= 3:
        c1 -= n-1
    elif n == 2:
        c1 -= factorial(n) // factorial(2) // factorial(n-2)
    print(c1)