Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial    N = int(input())
A = list(map(int, input().split()))

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))


Fixed submission:
from collections import defaultdict
from math import factorial

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

Fixed submission:
from collections import defaultdict
from math import factorial

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    # print(f"a:{a} n:{n}", file=sys.stderr)
    print(combination_all - (combi[a] - combi2[a]))

Fixed submission:
from collections import defaultdict
from math import factorial

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))