Problem: We have N balls. The i-th ball has an integer A_i written on it.   For each k=1, 2, ..., N, solve the following problem and print the answer.    * Find the number of ways to choose two distinct balls (disregarding order) from the N-1 balls other than the k-th ball so that the integers written on them are equal.

Submission attempts (in order):
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':
  	main()

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':
	main()

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

def main()
    n=n0()
    a=n1()

    from math import factorial
    def comb(n):
        if n<=1:
            return 0
        if n==2:
            return 1
        return factorial(n)//(factorial(2)*factorial(n-2))

    c=[a.count(i) for i in range(1,n+1)]
    d=[comb(m) for m in c]
    s=sum(d)

    for i in range(n):
        print(s-d[a[i]-1]+comb(c[a[i]-1]-1))
if __name__ == '__main__':

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

from scipy.misc import comb
def combi(n):
    if n<=1:
        return 0
    if n==2:
        return 1
    return comb(n,2)

c=[a.count(i) for i in range(1,n+1)]
d=[combi(m) for m in c]
s=sum(d)

for i in range(n):
    print(s-d[a[i]-1]+combi(c[a[i]-1]-1))

def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
a=n1()

def comb(n):
    if n<=1:
        return 0
    if n==2:
        return 1
    return (n*(n-1))//2

from collections import Counter
c=Counter(a)
# print(c)
d={i:comb(j) for i,j in c.items()}
# print(d)
s=sum(d.values())
# print(s)

for i in a:
    print(s-d[i]+comb(c[i]-1))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted