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):
import sys
from operator import mul
from functools import reduce

def combinations_count(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())
l = [int(x) for x in input().split()]


cl = []
ll = [x for x in set(l) if l.count(x) > 1]

# print(ll)

if not ll:
    for i in range(n):
        print(0)
    sys.exit()

sum = 0
for i in ll:
    m = l.count(i)
    nc = combinations_count(m, 2)
    sum += nc
    # print(nc)
    
    cl.append(nc - int(nc * (m - 2) / m))

# print(sum)
# print(cl)
for i in l:
    
    idx = ll.index(i)
    if idx:
        print(0)
    else:
        print(sum - cl[ll.index(i)])


import sys
import collections
from operator import mul
from functools import reduce
 
def combinations_count(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())
l = [int(x) for x in input().split()]
c = collections.Counter(l)
 

cl = []
 
# print(ll)
 
if not ll:
    for i in range(n):
        print(0)
    sys.exit()
 
sum = 0
for a, v in c:
    nc = combinations_count(v, 2)
    sum += nc
    # print(nc)
    
    cl.append(nc - int(nc * (v - 2) / v))
 
# print(sum)
# print(cl)
 
def my_index(l, x, default=n):
    if x in l:
        return l.index(x)
    else:
        return default
 
for i in l:
    
    idx = my_index(ll, i)
    if idx == n:
        print(sum)
    else:
        print(sum - cl[idx])

import sys
import collections
from operator import mul
from functools import reduce
 
def combinations_count(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())
l = [int(x) for x in input().split()]
c = collections.Counter(l)
 

cl = []
ll = [x for x in set(l) if l.count(x) > 1]
 
# print(ll)
 
if not ll:
    for i in range(n):
        print(0)
    sys.exit()
 
sum = 0
for i in ll:
    nc = combinations_count(c[i], 2)
    sum += nc
    # print(nc)
    
    cl.append(nc - int(nc * (m - 2) / m))
 
# print(sum)
# print(cl)
 
def my_index(l, x, default=n):
    if x in l:
        return l.index(x)
    else:
        return default
 
for i in l:
    
    idx = my_index(ll, i)
    if idx == n:
        print(sum)
    else:
        print(sum - cl[idx])

import collections

def combinations_count(n, r):
    return n * (n-1) // r


n = int(input())
l = [int(x) for x in input().split()]

l1 = []
l2 = []
c = collections.Counter(l)

total = sum([combinations_count(i, 2) for i in c.values()])

for a in l:
    l1.append(combinations_count(c[a], 2))
    l2.append(combinations_count(c[a]-1, 2))
print(l1, l2)
for i in range(len(l)):
    print(total-l1[i]+l2[i])


import sys
import collections
from operator import mul
from functools import reduce


def combinations_count(n, r):
    if n < r:
        return 0
    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())
l = [int(x) for x in input().split()]
c = collections.Counter(l)


cd = {}

# print(ll)

if not c:
    for _ in range(len(l)):
        print(0)
    sys.exit()

sum = 0
for a in c:
    nc = combinations_count(c[a], 2)
    sum += nc
    # print(nc)
    
    cd[a] = (nc - int(nc * (c[a] - 2) / c[a]))

"""
def my_index(lv):
    if lv not in c.keys():
        return sum
    else:
        return cd[lv]
"""

for lv in l:
    print(sum-cd[lv])


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted