Buggy python submission (verdict: Time Limit Exceeded):
n = input()
al = [int(x) for x in input().split()]
aset = set(al)

# {number: count}
counts_d = {i: sum(a == i for a in al) for i in aset}

vset = set(counts_d.values())
# Count of count
v_counts = {v: sum(v == i for i in counts_d.values()) for v in vset}

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

# C013_scrambled まで通り，次からTLE


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
n = input()
al = [int(x) for x in input().split()]
aset = set(al)

# {number: count}
counts_d = {i: sum(a == i for a in al) for i in aset}

vset = set(counts_d.values())
# Count of count
v_counts = {v: sum(v == i for i in counts_d.values()) for v in vset}

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
al = [int(x) for x in input().split()]
aset = list(set(al))
aset.sort()

# {number: count}
counts_d = {i: sum(a == i for a in al) for i in aset}

vset = set(counts_d.values())
# Count of count
v_counts = {v: sum(v == i for i in counts_d.values()) for v in vset}

whole_patterns = 0
for k, v in v_counts.items():
    if k > 1:
        whole_patterns += (int(k * (k-1) / 2)) * v

for a in al:
    print(whole_patterns - counts_d[a] + 1)


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
import copy

n = int(input())
al = [int(x) for x in input().split()]
aset = set(al)

# {number: count}
counts_d = {i: sum(j == i for j in al) for i in range(1, n + 1) if i in aset}

whole_patterns = 0
for v in counts_d.values():
    whole_patterns += int(v * (v - 1) / 2)

for a in al:
    print(whole_patterns - counts_d[a] + 1)


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy

n = int(input())
al = [int(x) for x in input().split()]
ccc = collections.Counter
cs_orig = dict(ccc(al))
copy_copy = copy.copy

aset = set(al)
patterns_d = {}

for i in range(1, n+1):
    cs = copy_copy(cs_orig)
    patterns = 0
    if i in aset:
        cs[i] -= 1

        cscs = dict(ccc(cs.values()))
        for k, v in cscs.items():
            if k > 1:
                patterns += (int(k * (k-1) / 2)) * v

        patterns_d[i] = patterns

for a in al:
    print(patterns_d[a])


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy

n = int(input())
al = [int(x) for x in input().split()]
cs_orig = dict(collections.Counter(al))
copy_copy = copy.copy

aset = set(al)
patterns_d = {}

for i in range(1, n+1):
    cs = copy_copy(cs_orig)
    patterns = 0
    if i in aset:
        cs[i] -= 1
        for count in cs.values():
            if count > 1:
                patterns += int(count * (count - 1) / 2)

        patterns_d[i] = patterns

for a in al:
    print(patterns_d[a])


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]

Buggy python submission (verdict: Time Limit Exceeded):
import collections
import copy

n = int(input())
al = [int(x) for x in input().split()]
cs_orig = collections.Counter(al)
copy_copy = copy.copy

for a in al:
    cs = copy_copy(cs_orig)
    patterns = 0
    cs[a] -= 1
    for count in cs.values():
        if count > 1:
            patterns += int(count * (count-1) / 2)

    print(patterns)


Fixed submission:
import collections

n = input()
al = tuple(x for x in input().split())
aset = set(al)

# {number: count}
ccc = collections.Counter
counts_d = ccc(al)

# Count of count
v_counts = ccc(v for v in counts_d.values())

whole_patterns = sum(
    (int(k * (k - 1) / 2)) * v for k, v in v_counts.items() if k > 1
)

[print(whole_patterns - counts_d[a] + 1) for a in al]