Buggy python submission (verdict: Time Limit Exceeded):
class Combination:
    def __init__(self,N):
        self.fact = [0 for _ in range(N+1)]
        self.N = N
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,N + 1):
            self.fact[i] = self.fact[i-1] * i

    def calc(self,n,k):
        return self.fact[n] / (self.fact[k] * self.fact[n-k])

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
comb = Combination(N)
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += comb.calc(i,2)

for i in A:
    ans_tmp = ans - comb.calc(A_num[i],2)
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += comb.calc(A_num[i] -1, 2)
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1

Fixed submission:
class Combination:
    def __init__(self):
        self.fact = [0 for _ in range(100001)]
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,100001):
            self.fact[i] = self.fact[i-1] * i
            print(self.fact[i])

    def calc(self,n,k):
        return int(self.fact[n] / (self.fact[k] * self.fact[n-k]))

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += i * (i - 1) // 2

for i in A:
    x = A_num[i]
    ans_tmp = ans - (x * (x - 1) // 2 )
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += ((x - 1) * (x - 2) // 2 )
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1

Buggy python submission (verdict: Time Limit Exceeded):
class Combination:
    def __init__(self,N):
        self.fact = [0 for _ in range(N+1)]
        self.N = N
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,N + 1):
            self.fact[i] = self.fact[i-1] * i

    def calc(self,n,k):
        return self.fact[n] / (self.fact[k] * self.fact[n-k])

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
conb = Combination(N)

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A:
    A_num[i] -= 1
    ans = 0
    for a in A_num:
        if a < 2:
            continue
        else:
            ans += conb.calc(a,2)
    print(int(ans))
    A_num[i] += 1

Fixed submission:
class Combination:
    def __init__(self):
        self.fact = [0 for _ in range(100001)]
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,100001):
            self.fact[i] = self.fact[i-1] * i
            print(self.fact[i])

    def calc(self,n,k):
        return int(self.fact[n] / (self.fact[k] * self.fact[n-k]))

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += i * (i - 1) // 2

for i in A:
    x = A_num[i]
    ans_tmp = ans - (x * (x - 1) // 2 )
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += ((x - 1) * (x - 2) // 2 )
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1

Buggy python submission (verdict: Time Limit Exceeded):
class Combination:
    def __init__(self,N):
        self.fact = [0 for _ in range(N+1)]
        self.N = N
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,N + 1):
            self.fact[i] = self.fact[i-1] * i

    def calc(self,n,k):
        return self.fact[n] / (self.fact[k] * self.fact[n-k])

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
conb = Combination(N)

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A:
    A_num[i] -= 1
    ans = 0
    for a in A_num:
        if a < 2:
            continue
        else:
            ans += conb.calc(a,2)
    print(int(ans))
    A_num[i] += 1

Fixed submission:
class Combination:
    def __init__(self):
        self.fact = [0 for _ in range(100001)]
        self.init_fact()
    
    def init_fact(self):
        self.fact[0] = 1
        self.fact[1] = 1
        for i in range(2,100001):
            self.fact[i] = self.fact[i-1] * i
            print(self.fact[i])

    def calc(self,n,k):
        return int(self.fact[n] / (self.fact[k] * self.fact[n-k]))

N = int(input())

A_num = [0 for _ in range(N + 1)]
A = []
ans = 0

for i in input().split(" "):
    A_num[int(i)] += 1
    A.append(int(i))

for i in A_num:
    if i < 2:
         continue
    else:
        ans += i * (i - 1) // 2

for i in A:
    x = A_num[i]
    ans_tmp = ans - (x * (x - 1) // 2 )
    if (A_num[i] - 1) < 2:
        print(int(ans_tmp))
        continue
    else:
        ans_tmp += ((x - 1) * (x - 2) // 2 )
        print(int(ans_tmp))
        continue

    print(int(ans))
    A_num[i] += 1