Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
 
import copy
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

SortList = copy.copy(AList)
SortList.sort()
 
NumberList = []
CountList = []
tmp = SortList[0]
count = 0
for i in SortList:
    if tmp == i:
        count += 1
    else:
        NumberList.append(tmp)
        CountList.append(count)
        tmp = i
        count = 1
NumberList.append(tmp)
CountList.append(count)
 
CountListCopy = copy.copy(CountList)
 
result = 0
for i in range(0, len(AList)):
    CountListCopy[NumberList.index(AList[i])] -= 1
    for q in CountListCopy:
        if q < 2:
            continue
        else:
            result += combinations(q, 2)
    print(result)
    result = 0
    
    CountListCopy = copy.copy(CountList)

Fixed submission:
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

import copy
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def main():
    N = int(input())
    AList = list(map(int, input().split()))

    SortList = copy.copy(AList)
    SortList.sort()

    NumberList = []
    CountList = []
    tmp = SortList[0]
    count = 0
    for i in SortList:
        if tmp == i:
            count += 1
        else:
            NumberList.append(tmp)
            CountList.append(count)
            tmp = i
            count = 1
    NumberList.append(tmp)
    CountList.append(count)

    CountListCopy = copy.copy(CountList)

    result = 0
    for i in range(0, len(AList)):
        CountListCopy[NumberList.index(AList[i])] -= 1
        for q in CountListCopy:
            if q < 2:
                continue
            else:
                result += combinations(q, 2)
        print(result)
        result = 0
    
        CountListCopy = copy.copy(CountList)
    
if __name__ == '__main__':
    main()

Fixed submission:
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

import copy

def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())

AList = list(map(int, input().split()))

SortList = copy.copy(AList)
SortList.sort()

NumberList = []
CountList = []
tmp = SortList[0]
count = 0
for i in SortList:
    if tmp == i:
        count += 1
    else:
        NumberList.append(tmp)
        CountList.append(count)
        tmp = i
        count = 1
NumberList.append(tmp)
CountList.append(count)

CountListCopy = copy.copy(CountList)

result = 0
for i in range(0, len(AList)):
    CountListCopy[NumberList.index(AList[i])] -= 1
    for q in CountListCopy:
        if q < 2:
            continue
        else:
            result += combinations(q, 2)
    print(result)
    result = 0
    
    CountListCopy = copy.copy(CountList)

Fixed submission:
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))

Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

import copy

def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())

AList = list(map(int, input().split()))

SortList = copy.copy(AList)
SortList.sort()

NumberList = []
CountList = []
tmp = SortList[0]
count = 0
for i in SortList:
    if tmp == i:
        count += 1
    else:
        NumberList.append(tmp)
        CountList.append(count)
        tmp = i
        count = 1
NumberList.append(tmp)
CountList.append(count)

CountListCopy = copy.copy(CountList)

result = 0
for i in range(0, len(AList)):
    CountListCopy[NumberList.index(AList[i])] -= 1
    for q in CountListCopy:
        if q < 2:
            continue
        else:
            result += combinations(q, 2)
    print(result)
    result = 0
    
    CountListCopy = copy.copy(CountList)

Fixed submission:
from operator import mul
from functools import reduce
import collections
import sys
input = sys.stdin.readline
 
def combinations(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
 
N = int(input())
 
AList = list(map(int, input().split()))

NumberList = set(AList)
CountList = collections.Counter(AList)

result = 0
for i in NumberList:
    if CountList[i] >= 2:
        result += combinations(CountList[i], 2)


for i in AList:
    print(result - (CountList[i] - 1))