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

cmb2 = [0] * 200001
for n in range(2, 200001):
    num = 1
    r = 2
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

n = int(input())
a = list(map(int, input().split()))
nn = len(a) - 1
ctr = Counter(a)

memo = {}
for aa in a:
    if aa not in memo:
        x = 0
        for k, v in ctr.items():
            if k == aa:
                v -= 1
            if v >= 2:
                x += cmb2[v]
        memo[aa] = x
    print(memo[aa])


Fixed submission:
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)

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

cmb2 = [0] * 200001
for n in range(2, 200001):
    num = 1
    r = 2
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

n = int(input())
a = list(map(int, input().split()))
nn = len(a) - 1
ctr = Counter(a)

for aa in a:
    x = 0
    for k, v in ctr.items():
        if k == aa:
            v -= 1
        if v >= 2:
            x += cmb2[v]
    print(x)


Fixed submission:
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)

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

def cmb(n, r):
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    return num

n = int(input())
a = list(map(int, input().split()))
nn = len(a) - 1
ctr = Counter(a)

f = {}

for aa in a:
    x = 0
    for k, v in ctr.items():
        if k == aa:
            v -= 1
        if v >= 2:
            #c = f[v] // (2 * f[v - 2])
            x += cmb(v, 2)
    print(x)


Fixed submission:
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)

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

n = int(input())
a = list(map(int, input().split()))
nn = len(a) - 1
ctr = Counter(a)

f = {}

for aa in a:
    x = 0
    for k, v in ctr.items():
        if k == aa:
            v -= 1
        if v >= 2:
            if v not in f:
                f[v] = math.factorial(v)
            if (v - 2) not in f:
                f[v - 2] = math.factorial(v - 2)
            c = f[v] // (2 * f[v - 2])
            x += c
    print(x)


Fixed submission:
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)

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

n = int(input())
a = list(map(int, input().split()))
nn = len(a) - 1
ctr = Counter(a)

for aa in a:
    x = 0
    for k, v in ctr.items():
        if k == aa:
            v -= 1
        if v >= 2:
            c = math.factorial(v) // (2 * math.factorial(v - 2))
            x += c
    print(x)


Fixed submission:
from collections import Counter
import math

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

ctr = Counter(aa)

cmb2 = [0] * 200001
for n in range(2, 200001):
    r = 2
    num = 1
    for i in range(1, r + 1):
        num = num * (n - i + 1) // i
    cmb2[n] = num

x = 0
for k, v in ctr.items():
    x += cmb2[v]

for a in aa:
    k = ctr[a] - 1
    print(x - k)