Problem: We have N+M balls, each of which has an integer written on it.   It is known that:    * The numbers written on N of the balls are even.   * The numbers written on M of the balls are odd.  Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.   It can be shown that this count does not depend on the actual values written on the balls.

Submission attempts (in order):
N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A


A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A


A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return j * (j-1) // 2 if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  res_list[m] = s - combs[m] + ncr(A_c[m] - 1)

for k in range(N):
  res.append(res_list[A[k]])
print('\n'.join([str(s) for s in res]))

N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

# res = [] # solution for each key in A
res_list = {} # solution for each value in A


A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  cnt = combs[m]

  n = s
  n -= cnt # the only inaccurate entry
  n += ncr(A_c[m] - 1)
  res_list[m] = n

res = ''
for k in range(N):
  res += '\n' + str(res_list[A[k]])
print(res[1:])
# print('\n'.join([str(s) for s in res]))

N = int(input())
A = [int(k) for k in input().split(' ')]

from collections import Counter 
import math 

res = [] # solution for each key in A
res_list = {} # solution for each value in A


A_c = Counter(A)
l = len(A_c)

def ncr(j):
  return math.factorial(j) // math.factorial(2) // math.factorial(j - 2) if j >= 2 else 0

# store ncr for each value 
combs = {k: ncr(v) for k, v in A_c.items()}

s = sum(combs.values())
  
for m in A_c.keys():
  cnt = combs[m]

  n = s
  n -= cnt # the only inaccurate entry
  n += ncr(A_c[m] - 1)
  res_list[m] = n

for k in range(N):
  print(res_list[A[k]])
# print('\n'.join([str(s) for s in res]))

M, N = [int(k) for k in input().split(' ')]
import math 
res = 0

if N >= 2:
  res += (math.factorial(N) // math.factorial(2) // math.factorial(N - 2))

if M >= 2:
  res += (math.factorial(M) // math.factorial(2) // math.factorial(M - 2))

print(res)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted