Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    UNI = set(A)
    #CNT = [[i, A.count(i), int(A.count(i)*(A.count(i)-1)/2), int((A.count(i)-1)*(A.count(i)-2)/2)] for i in UNI]
    CNT = [[i, A.count(i)] for i in UNI]
    for j in A:
        sum = 0
        for i,cnt in CNT:
            if j == i: cnt -= 1
            sum += int(cnt*(cnt - 1) /2)
        print(sum)

main()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
def combi(n):
  return n*(n-1)//2
 
import sys
input = sys.stdin.readline
N = int(input())
A = input().split()
tmp = 0
idx = list(set(A))
value = [ A.count(_) for _ in idx ]
for n in value:
    tmp += combi(n)
#sum = 0
for i in A:
    j = idx.index(i)
    #sum += tmp - combi(j) + combi(j-1)
    print(int(tmp - combi(value[j]) + combi(value[j]-1)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
def combi(n):
  return n*(n-1)//2
  
N = int(input())
A = input().split()
tmp = 0
idx = list(set(A))
value = [ A.count(_) for _ in idx ]
for n in value:
    tmp += combi(n)
#sum = 0
for i in A:
    j = idx.index(i)
    #sum += tmp - combi(j) + combi(j-1)
    print(int(tmp - combi(value[j]) + combi(value[j]-1)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = input().split()
tmp = 0
idx = list(set(A))
value = [ A.count(_) for _ in idx ]
for n in value:
    tmp += combi(n)
#sum = 0
for i in A:
    j = idx.index(i)
    #sum += tmp - combi(j) + combi(j-1)
    print(int(tmp - combi(value[j]) + combi(value[j]-1)))

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
def combi(n):
    return n*(n-1)//2

def D159_1():
    N = int(input())
    A = input().split()
    tmp = 0
    idx = list(set(A))
    value = [ A.count(_) for _ in idx ]
    for n in value:
        tmp += combi(n)
    #sum = 0
    for i in A:
        j = idx.index(i)
        #sum += tmp - combi(j) + combi(j-1)
        print(int(tmp - combi(value[j]) + combi(value[j]-1)))


if __name__ == "__main__":
    D159_1()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
def combi(n):
    return n*(n-1)//2

def D159_1():
    N = int(input())
    A = input().split()
    tmp = 0
    idx = list(set(A))
    value = [ A.count(_) for _ in idx ]
    for n in value:
        tmp += combi(n)
    #sum = 0
    for i in A:
        j = idx.index(i)
        #sum += tmp - combi(j) + combi(j-1)
        print(int(tmp - combi(value[j]) + combi(value[j]-1)))


if __name__ == "__main__":
    D159_1()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
def combi(n):
    return n*(n-1)/2

def D159_1():
    N = int(input())
    A = input().split()
    tmp = 0
    idx = list(set(A))
    value = [ A.count(_) for _ in idx ]
    for n in value:
        tmp += combi(n)
    #sum = 0
    for i in A:
        j = idx.index(i)
        #sum += tmp - combi(j) + combi(j-1)
        print(int(tmp - combi(value[j]) + combi(value[j]-1)))


if __name__ == "__main__":
    D159_1()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def D159():
    N = int(input())
    A = input().split()
    #sum = 0
    for i in range(0, N):
        sum = 0
        A_ = copy.deepcopy(A)
        del A_[i]
        num = list(set(A_))
        num = [ _ for _ in num if A_.count(_) > 1]
        for j in num: # 全部回したら、タイムアウト
            sum += combinations_count(A_.count(j), 2)
        print(sum)

if __name__ == "__main__":
    D159()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)

Buggy python submission (verdict: Time Limit Exceeded):
import copy
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def D159():
    N = int(input())
    A = input().split()
    #sum = 0
    for i in range(0, N):
        sum = 0
        A_ = copy.deepcopy(A)
        del A_[i]
        num = list(set(A_))
        for j in num:
            if A_.count(j) > 1:
                sum += combinations_count(A_.count(j), 2)
        print(sum)

if __name__ == "__main__":
    D159()

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
import collections
A_count = collections.Counter(A)
 
import math
sum_ = 0
for ai in A_count:
    sum_ += (A_count[ai] * (A_count[ai] - 1)) // 2
 
for ai in A:
    #print(sum_ - (A_count[ai] * (A_count[ai] - 1)) // 2 + (A_count[ai] - 1) * (A_count[ai] - 2)) // 2
    l = A_count[ai] * (A_count[ai] - 1) // 2
    m = (A_count[ai] - 1) * (A_count[ai] - 2) // 2
    print(sum_ - l + m)