AtCoder Beginner Contest 159 - The Number of Even Pairs

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.

-----Constraints-----
 - 0 \leq N,M \leq 100
 - 2 \leq N+M
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M

-----Output-----
Print the answer.

-----Sample Input-----
2 1

-----Sample Output-----
1

For example, let us assume that the numbers written on the three balls are 1,2,4.
 - If we choose the two balls with 1 and 2, the sum is odd;
 - If we choose the two balls with 1 and 4, the sum is odd;
 - If we choose the two balls with 2 and 4, the sum is even.
Thus, the answer is 1.

Difficulty: EASY

Starter code:

Solutions:
(a, b) = map(int, input().split())
print(int(a * (a - 1) / 2 + b * (b - 1) / 2))


(n, m) = map(int, input().split())
r = n * (n - 1) // 2 + m * (m - 1) // 2
print(r)


(a, b) = [int(x) for x in input().split()]
print((a * a + b * b - a - b) // 2)


(n, m) = map(int, input().split())
ans = int(n * (n - 1) / 2 + m * (m - 1) / 2)
print(ans)


(n, m) = map(int, input().split())
l = n + m
print(l * (l - 1) // 2 - n * m)


(N, M) = list(map(int, input().split()))
print(N * (N - 1) // 2 + M * (M - 1) // 2)


(N, M) = map(int, input().split())
n = N * (N - 1) + M * (M - 1)
print(n // 2)


print(sum([x * (x - 1) // 2 for x in map(int, input().split())]))


(A, B) = map(int, input().split())
print(A * (A - 1) // 2 + B * (B - 1) // 2)


(N, M) = map(int, input().split())
print(sum(range(0, N)) + sum(range(0, M)))


from math import floor
(n, m) = list(map(int, input().split()))
a = n * (n - 1) / 2
b = m * (m - 1) / 2
print(floor(a + b))


(n, m) = map(int, input().split())
print(n * ~-n // 2 + m * ~-m // 2)


(n, m) = [int(i) for i in input().split()]
print(n * (n - 1) // 2 + m * (m - 1) // 2)


(n, m) = map(int, input().split())
a = n * (n - 1) >> 1
a += m * (m - 1) >> 1
print(a)


import sys
sys.setrecursionlimit(10 ** 8)
ini = lambda : int(sys.stdin.readline())
inl = lambda : [int(x) for x in sys.stdin.readline().split()]
ins = lambda : sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print('\x1b[33m', *a, '\x1b[0m', **dict(file=sys.stderr, **kw))

def solve():
	(n, m) = inl()
	return n * (n - 1) // 2 + m * (m - 1) // 2
print(solve())


from operator import mul
from functools import reduce

def cmb(n, r):
	r = min(n - r, r)
	if n <= 1:
		return 0
	if r == 0:
		return 1
	over = reduce(mul, range(n, n - r, -1))
	under = reduce(mul, range(1, r + 1))
	return over // under
(N, M) = map(int, input().split())
print(cmb(N, 2) + cmb(M, 2))


(X, Y) = map(int, input().split())
print(int(X * (X - 1) / 2 + Y * (Y - 1) / 2))


(n, m) = map(int, input().split())
x = n * (n - 1) / 2 + m * (m - 1) / 2
print(int(x))


(N, M) = map(int, input().split())
ans = (N + M) * (N + M - 1) // 2 - N * M
print(ans)


(n, m) = map(int, input().split())
print(max(0, n * (n - 1) // 2 + m * (m - 1) // 2))


(N, M) = list(map(int, input().split()))
if N < 2:
	guusuu = 0
else:
	guusuu = N * (N - 1) / 2
if M < 2:
	kisuu = 0
else:
	kisuu = M * (M - 1) / 2
print(int(guusuu + kisuu))


(n, m) = map(int, input().split())
a = n * (n - 1) // 2
b = m * (m - 1) // 2
print(a + b)


(x, y) = map(int, input().split())
print((x * (x - 1) + y * (y - 1)) // 2)


def factorial(n):
	ans = 1
	for i in range(1, n + 1):
		ans *= i
	return ans

def combination(n, r):
	return factorial(n) // (factorial(n - r) * factorial(r))
(N, M) = map(int, input().split())
print(combination(N, 2) + combination(M, 2))


(n, m) = list(map(int, input().split()))
if n >= 2:
	even = n * (n - 1) / 2
else:
	even = 0
if m >= 2:
	odd = m * (m - 1) / 2
else:
	odd = 0
print(int(even + odd))


import math
(n, m) = list(map(int, input().split()))

def c(a, b):
	if a >= 2:
		return math.factorial(a) // (math.factorial(b) * math.factorial(a - b))
	else:
		return 0
print(c(n, 2) + c(m, 2))


(n, w) = map(int, input().split())
print(n * (n - 1) // 2 + w * (w - 1) // 2)


import itertools
(n, m) = map(int, input().split())
i = [2] * n
j = [2] * m
p = list(itertools.combinations(i, 2))
q = list(itertools.combinations(j, 2))
print(len(p) + len(q))


(N, M) = map(int, input().split(sep=' '))
print(N * (N - 1) // 2 + M * (M - 1) // 2)


[n, m] = input().split()
n = int(n)
m = int(m)
sum_n = 0
sum_m = 0
for i in range(n):
	sum_n += i
for j in range(m):
	sum_m += j
print(sum_n + sum_m)


(N, M) = map(int, input().split())
all = (M * (M - 1) + N * (N - 1)) // 2
print(all)


import math
(n, m) = list(map(int, input().split()))

def combinations_count(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if n >= 2 and m >= 2:
	ans = combinations_count(m, 2) + combinations_count(n, 2)
elif n < 2 and m < 2:
	ans = 0
elif n < 2:
	ans = combinations_count(m, 2)
elif m < 2:
	ans = combinations_count(n, 2)
print(ans)


(n, m) = list(map(int, input().split()))
sum = n * (n - 1) / 2 + m * (m - 1) / 2
print(int(sum))


import math
(N, M) = map(int, input().split())

def C(x):
	if x >= 2:
		return math.factorial(x) // (math.factorial(x - 2) * 2)
	else:
		return 0
print(C(N) + C(M))


[N, M] = [int(i) for i in input().split()]
print(int(N * max(N - 1, 0) / 2) + int(M * max(M - 1, 0) / 2))


print(sum((i * ~-i // 2 for i in map(int, input().split()))))


(N, M) = map(int, input().split())
x = N + M
print(x * (x - 1) // 2 - N * M)


(N, M) = map(int, input().split())
X = N * (N - 1) // 2
Y = M * (M - 1) // 2
print(X + Y)


import math

def comb(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
(n, m) = list(map(int, input().split()))
if n <= 1 and m <= 1:
	ans = 0
elif n <= 1:
	ans = comb(m, 2)
elif m <= 1:
	ans = comb(n, 2)
else:
	ans = comb(n, 2) + comb(m, 2)
print(ans)


from scipy.special import comb
(n, m) = map(int, input().split())
print(int(comb(n, 2) + comb(m, 2)))


import itertools
(N, M) = map(int, input().split())
ball = list(range(2, 2 * N + 1, 2)) + list(range(1, 2 * M, 2))
count = 0
for (i, j) in list(itertools.combinations(ball, 2)):
	if (i + j) % 2 == 0:
		count += 1
print(count)


from scipy.special import comb
(N, M) = input().split()
N = int(N)
M = int(M)
A = 0
B = 0
if N >= 2:
	A = comb(N, 2, exact=True)
if M >= 2:
	B = comb(M, 2, exact=True)
print(A + B)


(N, M) = list(map(int, input().split()))
ki = N * (N - 1) // 2
gu = M * (M - 1) // 2
print(ki + gu)


(n, m) = map(float, input().split())
print(int((n * (n - 1) + m * (m - 1)) / 2))


print(sum([i * (i - 1) // 2 for i in list(map(int, input().split()))]))


(e, o) = map(int, input().split())
print(e * (e - 1) // 2 + o * (o - 1) // 2)


(n, m) = map(int, input().split())
if n > 1:
	an = n * (n - 1) / 2
else:
	an = 0
if m > 1:
	am = m * (m - 1) / 2
else:
	am = 0
print(int(an + am))


(n, m) = map(int, input().split())
s = n * (n - 1) // 2 + m * (m - 1) // 2
print(s)


def main():
	(N, M) = tuple([int(_x) for _x in input().split()])
	print(N * (N - 1) // 2 + M * (M - 1) // 2)
main()


import itertools
(n, m) = list(map(int, input().split()))
ln = []
ans = 0
for i in range(n):
	ln.append(2)
for i in range(m):
	ln.append(3)
for x in itertools.combinations(ln, 2):
	if (x[0] + x[1]) % 2 == 0:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
res = (N * (N - 1) + M * (M - 1)) / 2
print(int(res))


(N, M) = map(int, input().split())
cnt = 0
if N >= 2:
	cnt += N * (N - 1) / 2
if M >= 2:
	cnt += M * (M - 1) / 2
print(int(cnt))


(N, M) = map(int, input().split())
print(N * ~-N // 2 + M * ~-M // 2)


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		self.adj_list[u].append(v)
		if self.is_directed == False:
			self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print((node, '->', self.adj_list[node]))

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)
				parents.append(i)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 1)
		parents = [v]
		self.dfsUTIL(v, visited, parents)
		return len(parents)

def dict_sort(ans):
	ans = sorted(list(ans.items()), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def factors(n):
	d = {}
	while n % 2 == 0:
		if 2 in d:
			d[2] += 1
		else:
			d[2] = 1
		n /= 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
			n /= i
	n = int(n)
	if n > 1:
		d[n] = 1
	return d

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(a, b, c):
	chk = b * b - 4 * a * c
	if chk >= 0:
		ans1 = (-b + chk ** 0.5) / (2 * a)
		ans2 = (-b - chk ** 0.5) / (2 * a)
		return [int(ans1), int(ans2)]
	return -1

def permutation(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(n - r + 1, n + 1):
		ans *= i
	return ans

def combination(n, r):
	if n < r:
		return 0
	ans = 1
	for i in range(r):
		ans *= n - i
	div = 1
	for i in range(2, r + 1):
		div *= i
	return ans // div

def arinp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return list(map(int, input().split()))

def main():
	(n, m) = mult_inp()
	print(combination(n, 2) + combination(m, 2))

def __starting_point():
	main()
__starting_point()


(n, m) = list(map(int, input().split()))
ans = 0
if n == 0:
	print(int(m * (m - 1) / 2))
	return
if m == 0:
	print(int(n * (n - 1) / 2))
	return
ans = n * (n - 1) / 2 + m * (m - 1) / 2
print(int(ans))


import math
(N, M) = list(map(int, input().split()))
x = N * (N - 1) / 2 + M * (M - 1) / 2
print(math.floor(x))


(N, M) = map(int, input().split())
print(str(int(N * (N - 1) / 2 + M * (M - 1) / 2)))


(N, M) = map(int, input().split())
i = N * (N - 1) / 2 + M * (M - 1) / 2
print('%d' % i)


(n, m) = map(int, input().split())
na = n * (n - 1) // 2
ma = m * (m - 1) // 2
print(na + ma)


(n, m) = map(int, input().split())
ans = 0
if n >= 2:
	ans += n * (n - 1) // 2
else:
	ans += 0
if m >= 2:
	ans += m * (m - 1) // 2
else:
	ans += 0
print(ans)


import math
(n, m) = map(int, input().split())

def combinations_count(a, b):
	if a != 0 and a != 1:
		return math.factorial(a) // (math.factorial(a - b) * math.factorial(b))
	else:
		return 0
print(combinations_count(n, 2) + combinations_count(m, 2))


a = list(map(int, input().rstrip().split()))
out = 0
for i in a:
	if i > 1:
		out += i * (i - 1) // 2
print(out)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
from operator import itemgetter
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(N, M) = na()
print(N * (N - 1) // 2 + M * (M - 1) // 2)


(N, M) = map(int, input().split())
a = M + N
print(int(a * (a - 1) / 2 - M * N))


def main():
	(n, m) = map(int, input().split())
	cnt = 0
	if m >= 2:
		cnt += m * (m - 1) // 2
	if n >= 2:
		cnt += n * (n - 1) // 2
	print(cnt)

def __starting_point():
	main()
__starting_point()


inp = input().split()
n = int(inp[0])
m = int(inp[1])
arr = []
pares = 0
impares = 0
count = 1
nums = 0

def binary(arr, menor, mayor, x):
	if mayor >= menor:
		med = (mayor + menor) // 2
		if arr[med] == x:
			return med
		elif arr[med] > x:
			return binary(arr, menor, med - 1, x)
		else:
			return binary(arr, med + 1, mayor, x)
	else:
		return -1
while len(arr) < m + n:
	if count % 2 == 0 and pares < n:
		arr.append(count)
		pares += 1
	elif count % 2 != 0 and impares < m:
		arr.append(count)
		impares += 1
	count += 1
sums = []
for x in arr:
	for y in arr:
		if (x + y) % 2 == 0 and binary(sums, 0, len(sums) - 1, [y, x]) == -1 and (x != y):
			sums.append([x, y])
			nums += 1
print(nums)


(n, m) = [int(x) for x in input().split()]
print((n * (n - 1) + m * (m - 1)) // 2)


(N, M) = map(int, input().split())
c = (N * (N - 1) + M * (M - 1)) // 2
print(c)


(N, M) = map(int, input().split())
A = N * (N - 1) // 2
B = M * (M - 1) // 2
print(A + B)


(N, M) = map(int, input().split())
s = N + M
print(s * (s - 1) // 2 - N * M)


(N, M) = [int(s) for s in input().split(' ')]
print((N * (N - 1) + M * (M - 1)) // 2)


(N, M) = map(int, input().split())
print(int(N * (N - 1) / 2.0 + M * (M - 1) / 2.0))


print(sum(map(lambda x: int(x) * (int(x) - 1) // 2, input().split())))


(n, m) = map(int, input().split())
print(round((n + m) * (n + m - 1) / 2 - n * m))


import math
(n, m) = map(int, input().split())
print(n * (n - 1) // 2 + m * (m - 1) // 2)


(N, M) = map(int, input().split())
r = N * (N - 1) // 2 + M * (M - 1) // 2
print(r)


import math

def comb(n, r):
	if n <= 1:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
(N, M) = list(map(int, input().split()))
print(comb(N + M, 2) - N * M)


from scipy.special import comb
(n, m) = list(map(int, input().split()))
if n <= 1:
	a = 0
else:
	a = comb(n, 2, exact='true')
if m <= 1:
	b = 0
else:
	b = comb(m, 2, exact='true')
print(a + b)


import math
(N, M) = map(int, input().split())
print((M + N) * (M + N - 1) // 2 - M * N)


(N, M) = [int(x) for x in input().split()]
print(int(N * (N - 1) / 2 + M * (M - 1) / 2))


def resolve():
	(n, m) = map(int, input().split())
	print(int(n * (n - 1) / 2 + m * (m - 1) / 2))
resolve()


import numpy as np
a = list(map(int, input().rstrip().split()))
out = 0
for i in a:
	if i > 1:
		out += i * (i - 1) // 2
print(out)


(n, m) = map(int, input().split())
ex1 = n * (n - 1) // 2
ex2 = m * (m - 1) // 2
ans = ex1 + ex2
print(ans)


(n, m) = map(int, input().split())
c = n * (n - 1) / 2 + m * (m - 1) / 2
print(int(c))


a = input('')
lista = a.split()
lista2 = []
par = 0
impar = -1
contador = 0
for i in range(int(lista[0])):
	par += 2
	lista2.append(par)
for i in range(int(lista[1])):
	impar += 2
	lista2.append(impar)
longitud = len(lista2) - 1
for i in range(0, len(lista2)):
	b = i
	while True:
		if b + 1 > longitud:
			break
		else:
			suma = lista2[i] + lista2[b + 1]
			b = b + 1
			if suma % 2 == 0:
				contador += 1
print(contador)


(n, m) = map(int, input().split())
ans = 0

def com2(x):
	return x * (x - 1) // 2
if n >= 2:
	ans += com2(n)
if m >= 2:
	ans += com2(m)
print(ans)


(N, M) = map(int, input().split())
k = (M * (M - 1) + N * (N - 1)) // 2
print(k)


(N, M) = map(int, input().split())
K = (N + M) * (N + M - 1) / 2 - N * M
print(int(K))


def main():
	(n, m) = map(int, input().split())
	cnt = 0
	for i in range(n):
		for j in range(i + 1, n):
			cnt += 1
	for i in range(m):
		for j in range(i + 1, m):
			cnt += 1
	return cnt

def __starting_point():
	print(main())
__starting_point()


(a, b) = list(map(int, input().split()))
x = int(a / 2 * (a - 1) + b / 2 * (b - 1))
print(x)


(n, m) = map(int, input().split())
k = n * (n - 1) / 2 + m * (m - 1) / 2
print(int(k))


print(sum(map(lambda i: int(i) * (int(i) - 1) // 2, input().split())))


import math

def combinations_count(n, r):
	if n < 2:
		return 0
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
(n, m) = [int(i) for i in input().split()]
print(combinations_count(n, 2) + combinations_count(m, 2))


(N, M) = map(int, input().split())
gg = N * (N - 1) // 2
kk = M * (M - 1) // 2
print(gg + kk)


import sys

def solve(N: int, M: int):
	T = N + M
	T = T * (T - 1) / 2
	return print(int(T - M * N))

def main():

	def iterate_tokens():
		for line in sys.stdin:
			for word in line.split():
				yield word
	tokens = iterate_tokens()
	N = int(next(tokens))
	M = int(next(tokens))
	solve(N, M)

def __starting_point():
	main()
__starting_point()


import math
a = list(map(int, input().split()))
if a[0] == 1 and a[1] == 1:
	print(0)
elif a[0] == 0 or a[0] == 1:
	b = math.factorial(a[1]) / (math.factorial(2) * math.factorial(a[1] - 2))
	print(int(b))
elif a[1] == 0 or a[1] == 1:
	b = math.factorial(a[0]) / (math.factorial(2) * math.factorial(a[0] - 2))
	print(int(b))
else:
	b = math.factorial(a[1]) / (math.factorial(2) * math.factorial(a[1] - 2))
	c = math.factorial(a[0]) / (math.factorial(2) * math.factorial(a[0] - 2))
	print(int(b + c))


(g, k) = map(int, input().split())
ans = g * (g - 1) // 2 + k * (k - 1) // 2
print(ans)


import os, sys, re, math
(N, M) = [int(n) for n in input().split()]
cn = N * (N - 1) // 2
cm = M * (M - 1) // 2
print(cn + cm)


(n, m) = list(map(int, input().split()))
ln = []
ans = 0
for i in range(n):
	ln.append(2)
for i in range(m):
	ln.append(3)
for a in range(len(ln)):
	for b in range(len(ln)):
		if a != b:
			if (ln[a] + ln[b]) % 2 == 0:
				ans += 1
print(ans // 2)


(x, y) = map(int, input().split())
a = x * (x - 1) // 2
b = y * (y - 1) // 2
print(a + b)


(N, M) = map(int, input().split())
f = lambda x: x * (x - 1) // 2
print(f(N) + f(M))