Buggy python submission (verdict: Runtime Error):
from collections import Collection
import math

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

c = Collection(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

Fixed submission:
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

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

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

if N == set(A):
    for _ in range(N):
        print(0)

c2 = math.factorial(2)
umemory = {}
dmemory = {}
memory = {}

count = Counter(A)

for k, v in count.items():
    umemory[k] = 0 if v < 2 else math.factorial(v) // (math.factorial(v - 2) * c2)
    dmemory[k] = 0 if v < 3 else math.factorial(v-1) // (math.factorial(v - 3) * c2)

for k in range(0, N):
    a = A[k]
    if a in memory:
        result = memory[a]
    else:
        memory[a] = sum(map(lambda kv: kv[1], filter(lambda kv: kv[0] != a, umemory.items())))
        memory[a] += dmemory[a]
        result = memory[a]
    print(result)

Fixed submission:
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

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

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

if N == set(A):
    for _ in range(N):
        print(0)

c2 = math.factorial(2)
umemory = {}
dmemory = {}

count = Counter(A)

for k, v in count.items():
    umemory[k] = 0 if v < 2 else math.factorial(v) // (math.factorial(v - 2) * c2)
    dmemory[k] = 0 if v < 3 else math.factorial(v-1) // (math.factorial(v - 3) * c2)

for k in range(0, N):
    a = A[k]
    hoge = sum(map(lambda kv: kv[1], filter(lambda kv: kv[0] != a, umemory.items())))
    hoge += dmemory[a]
    print(hoge)

Fixed submission:
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

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

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

c2 = math.factorial(2)

memory = {}

for k in range(1, N+1):
    a = A[:k-1] + A[k:]
    count = Counter(a)

    sum = 0
    for k, v in count.items():
        if v < 2:
            continue
        kvs = '%d,%d' % (k,v)
        if kvs in memory:
            sum += memory[kvs]
        else:
            memory[kvs] = math.factorial(v) // (math.factorial(v - 2) * c2)
            sum += memory[kvs]
    print(sum)

Fixed submission:
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))

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

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

c2 = math.factorial(2)

for k in range(1, N+1):
    a = A[:k-1] + A[k:]
    count = Counter(a)

    sum = 0
    for k, v in count.items():
        if v < 2:
            continue
        sum += math.factorial(v) // (math.factorial(v - 2) * c2)
    print(sum)

Fixed submission:
from collections import Counter
import math

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

c = Counter(A)

all_ans = 0
for n in c.values():
    if n <= 1:
        continue
    all_ans += math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

for n in A:
    print(all_ans - (c[n]-1))