Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}

@lru_cache(maxsize=None)
def calc(a):
    global C
    C[a] -= 1
    sum_ = sum([n * (n - 1) // 2 for n in C.values() if n > 1])
    C[a] += 1
    return sum_

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for i, a in enumerate(A):
    print(calc(a))


Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache
def calc(a):
    C[a] -= 1
    sum_ = sum([n * (n - 1) // 2 for n in C.values() if n > 1])
    C[a] += 1
    return sum_

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for i, a in enumerate(A):
    print(calc(a))


Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

Buggy python submission (verdict: Runtime Error):
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}
S = {}


@lru_cache
def calc(C, a):
    C[a] -= 1
    sum_ = sum([S[n] for n in C.values() if n > 1])
    C[a] += 1
    return sum_

for a in A:
    C.setdefault(a, 0)
    C[a] += 1


for i, a in enumerate(A):
    print(calc(C, a))


Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}
S = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for c in C.values():
    if c < 1:
        continue
    S.setdefault(c, c * (c - 1) // 2)
    if c < 2:
        continue
    S.setdefault(c - 1, (c - 1) * (c - 2) // 2)

for i, a in enumerate(A):
    C[a] -= 1
    sum_ = sum([S[n] for n in C.values() if n > 1])
    C[a] += 1
    print(sum_)


Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

Buggy python submission (verdict: Runtime Error):
N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}
S = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for c in C.values():
    if c < 1:
        continue
    C.setdefault(c, c * (c - 1) // 2)
    if c < 2:
        continue
    C.setdefault(c - 1, c * (c - 1) // 2)

for i, a in enumerate(A):
    C[a] -= 1
    sum_ = sum([S[n] for n in C.values() if n > 1])
    C[a] += 1
    print(sum_)

Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for i, a in enumerate(A):
    C[a] -= 1
    sum_ = sum([n * (n - 1) // 2 for n in C.values() if n > 1])
    C[a] += 1
    print(sum_)

Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))

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

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

for i, a in enumerate(A):
    c = copy.deepcopy(C)
    c[a] -= 1
    sum_ = sum([ n * (n - 1) // 2 for _, n in c.items() if n > 1])
    print(sum_)

Fixed submission:
from functools import lru_cache

N = int(input().strip())
A = [int(v) for v in input().strip().split()]
C = {}


@lru_cache(maxsize=None)
def pair(k):
    return k * (k - 1) // 2

@lru_cache(maxsize=None)
def calc(s, a):
    return s - pair(C[a]) + pair(C[a] - 1)

for a in A:
    C.setdefault(a, 0)
    C[a] += 1

S = sum([pair(v) for v in C.values()])

for a in A:
    print(calc(S, a))