Problem:
 Score : 100 points    Problem Statement  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 1 2 1      Sample Output 1 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 .       Sample Input 2 4 3      Sample Output 2 9       Sample Input 3 1 1      Sample Output 3 0       Sample Input 4 13 3      Sample Output 4 81       Sample Input 5 0 3      Sample Output 5 3

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n, m = [int(s) for s in input().strip().split()]
    result = n * (n - 1) // 2 + m * (m - 1) // 2
    print(result)




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

Solution (Python):
N, M = map(int, input().split())
res = 0
if M<2:
    res = N*(N-1)/2
elif N<2:
    res = M*(M-1)/2
else:
    res = N*(N-1)/2 + M*(M-1)/2
print(int(res))

Solution (Python):
n, m = input().split()
n = int(n)
m = int(m)
ans = (n * (n - 1) / 2) + (m * (m - 1) / 2)
print(round(ans))

Solution (Python):
n, m = [int(x) for x in input().strip().split(" ")]

import math

def c(n, r):
    if n <= 1:
        return 0
    return int(math.factorial(n) / (math.factorial(r) * math.factorial(n - r)))

print(c(n, 2) + c(m, 2))

Solution (Python):
odd, even = map(int, input().split())
sum_odd = 0
sum_even = 0

if odd != 1:
	for i in range(1, odd):
  		sum_odd += i
else: 
  sum_odd = 0

if even != 1:
  for i in range(1, even):
  	sum_even += i
else:
  sum_even = 0
  
print(sum_odd + sum_even)

Solution (Python):
import bisect, collections
 
 
 
def solution():
    n, m = [int(x) for x in input().strip().split(" ")]
    print(n*(n-1)//2+m*(m-1)//2)
                

def main():    
    
    for _ in range(1):
        solution()

if __name__ == "__main__":
    main()

Solution (Python):
def nc2(n):
  if n<2:
    return 0
  else:
    return (n*(n-1))//2
n,m = map(int, input().split())
print(nc2(n)+nc2(m))

Solution (Python):
import math

nums = list(map(int, input().split()))
n = nums[0] 
m = nums[1] 

if n == 0:
    print(int(m*(m-1) / 2))
elif m == 0:
    print(int(n*(n-1) / 2))

elif n == 1 and m == 1:
    print(0)
else:
    result = m*(m-1) / 2 + n*(n-1) / 2
    print(int(result))

Solution (Python):
a,b=map(int,input().split(" "))

odd=a*(a-1)/2
even=b*(b-1)/2

print(int(odd+even))

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

Solution (Python):


even, odd = map(int, input().split())

even_r = 0
odd_r = 0

for i in range(even):
  for j in range(even - i - 1):
    even_r += 1
  
for i in range(odd):
  for j in range(odd - i - 1):
  	odd_r += 1

total = even_r + odd_r

print(total)

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

if N<=1:
  print(math.floor(M*(M-1)/2))
elif M<=1:
  print(math.floor(N*(N-1)/2))
else: 
  print(math.floor((N*(N-1)/2)+(M*(M-1)/2)))

Solution (Python):
n, m = map(int, input().split())
c = 0
d = 0
for i in range(n):
  c += i
for j in range(m):
  d += j
ans = c + d
print(ans)

Solution (Python):
N, M = map(int,input().split())
import math
def comb(n, r):
    if (n-r) >= 0:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
base = comb(N,2)
base2 = comb(M,2)
print(base+base2)

Solution (Python):
i_data = input().split()
n = int(i_data[0])
m = int(i_data[1])

def kekka_hantei(i_n):
  if i_n<=1:
    return 0
  else:
    r  = 0
    for i in range(1,i_n):
      r +=i
  return r

print(kekka_hantei(n) + kekka_hantei(m))

Solution (Python):
import math

x, y = map(int, input().split(' '))
r = 0
x_comb = 0
y_comb = 0

if x <= 1:
    pass
else:
    x_comb = math.factorial(x)//(2 * math.factorial(x-2))

if y <= 1:
    pass
else:
    y_comb = math.factorial(y)//(2 * math.factorial(y-2))

print(x_comb+y_comb)

Solution (Python):
import math
n,m = map(int,input().split())
if m >= 2 and n >= 2:
    s = math.factorial(n)/(math.factorial(2)*math.factorial(n-2)) + math.factorial(m)/(math.factorial(2)*math.factorial(m-2))
elif m >= 2 and n < 2:
    s = math.factorial(m)/(math.factorial(2)*math.factorial(m-2))
elif m < 2 and n >= 2:
    s = math.factorial(n)/(math.factorial(2)*math.factorial(n-2))
else:
    s = 0
print(round(s))

Solution (Python):
import sys
import math
N,M = map(int, sys.stdin.readline().strip().split())
def combinations(n, r):
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
if (N > 1):
    count_even = combinations(N, 2)
else:
    count_even = 0
if (M > 1):
    count_odd = combinations(M, 2)
else:
    count_odd = 0
print(count_even + count_odd)

Solution (Python):
from math import factorial
N ,M = [int(x) for x in input().split()]

sumodd = 0
sumeven = 0

if N == 0 or N == 1:
    sumeven = 0
else: 
    sumeven = factorial(N) // factorial(2) // factorial(N-2)
if M == 0 or M == 1:
    sumodd = 0
else: 
    sumodd = factorial(M) // factorial(2) // factorial(M-2)
print(sumeven + sumodd)

Solution (Python):
from math import factorial
def cmb(n,r):
  if n == 0 or n == 1:
    return 0
  return factorial(n) / factorial(r) / factorial(n - r)
a,b = map(int,input().split())
print(int(cmb(a,2)+cmb(b,2)))

Solution (Python):
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
mod = 92709568269121

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

mod = 10**9+7
def factrial(N):
    fc = [1, 1] + [None] * N
    inv = [0, 1] + [None] * N
    fcInv = [1, 1] + [None] * N
    for i in range(2, N+1):
        fc[i] = i*fc[i-1]%mod
        inv[i] = mod-(inv[mod%i]*(mod//i))%mod
        fcInv[i] = fcInv[i-1]*inv[i]%mod
    return fc, fcInv
fc, fcInv = factrial(1000)

def modCom(n, k):
    return 0 if n < k else fc[n] * fcInv[k] * fcInv[n-k] % mod

print(modCom(N, 2)+modCom(M, 2))

Solution (Python):
import math
m,n=map(int,input().split())
dm,dn=0,0
if m>=2:
    dm = math.factorial(m)//math.factorial(m-2)
if n>=2:
    dn = math.factorial(n)//math.factorial(n-2)
print((dm+dn)//2)

Solution (Python):
from scipy.misc import comb

n, m = map(int, input().split())
print(comb(n, 2, exact=True)+comb(m,2, exact=True))

Solution (Python):
import itertools


def resolve():
    N, M = map(int, input().split())
    ans = 0

    if N > 1:
        ans = len(
            list(itertools.combinations(list(range(N)), 2))
        )
    if M > 1:
        ans += len(
            list(itertools.combinations(list(range(M)), 2))
        )

    print(ans)

resolve()

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

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

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

Solution (Python):
IN=input()
M=int(IN.split(" ")[0])
N=int(IN.split(" ")[1])

count=0

if M >= 2:
    x=M*(M-1)
    count=x/2

if N >= 2:
    x=N*(N-1)
    count=x/2 + count

print(int(count))

Solution (Python):
n,m=map(int,input().split())
ans=0
if n>1:
    for i in range(n-1):
        ans+=n-i-1
if m>1:
    for j in range(m-1):
        ans+=m-j-1
print(ans)

Solution (Python):
def fac(n):
    result = 1
    for i in range(n):
        result = result * (i + 1)
    return result

def cmb(n, r):
    return fac(n) // (fac(r) * fac(n - r))

data = input().split()
n = int(data[0])
m = int(data[1])

print(cmb(n, 2) + cmb(m, 2))

Solution (Python):
N,M=map(int, input().split()) 
if M == 1 or M==0:
    answer = N * (N-1)//2
elif N == 1 or N==0:
    answer = M * (M-1)//2    
else:
    answer = (N * (N-1))//2 + (M * (M-1))//2
print(answer)

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

Solution (Python):
N, M = map(int, input().split())

binomials = [0, 0, 1]
for i in range(3, 101):
    binomials.append(binomials[-1] * i // (i - 2))

ans = binomials[N] + binomials[M]

print(ans)

Solution (Python):
a = list(map(int, input().split()))


def a1():
    if a[0] == 1 or a[0] == 0:
        a[0] = 0
        return a[0]
    else:
        return a[0] * (a[0] - 1) / 2


def b1():
    if a[1] == 1 or a[1] == 0:
        a[1] = 0
        return a[1]
    else:
        return a[1] * (a[1] - 1) / 2


print(int(a1() + b1()))

Solution (Python):
from math import factorial
def combination(n, r):
    if n>=r:
        return int( factorial(n)//(factorial(n-r)*factorial(r)) )
    else:
        return 0

N, M = list(map(int, input().split()))
print(combination(N, 2) + combination(M, 2))

Solution (Python):
n, m = map(int, input().split())
frac = [1]
p = 10**9 + 7
for i in range(max(n, m)):
    frac.append(frac[i]*(i+1)%p)


def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
if n >= 2:
  a = comb(n, 2, p)
else:
  a = 0
if m >= 2:
  b = comb(m, 2, p)
else:
  b = 0
print(a + b)

Solution (Python):

def combination_formula(n, r):
    """nCrは、O(min(n-r, r))で実装する
    Notes:
        分子と分母がかなり大きな値になった場合、計算は遅くなるので注意
        求める値がmodをとった値でいい場合、フェルマーの小定理を使った方法が速い。
    """
    if r > n:
        return 0

    r = min(n-r, r)
    bunsi, bunbo = 1, 1
    for i in range(r):
        bunsi = bunsi*(n-i)
        bunbo = bunbo*(i+1)
    return bunsi//bunbo


def solve():
    N, M = list(map(int, input().split()))

    
    ans = combination_formula(N, 2) + combination_formula(M,2)
    print(ans)


if __name__ == "__main__":
    solve()

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

Solution (Python):

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


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if n != 1 and n !=0:
    a = cmb(n,2)
else:
    a = 0

if m != 1 and m !=0:
    b = cmb(m,2)
else:
    b = 0
print(a + b)

Solution (Python):
import math
N, M= list(map(int, input().split()))
'''

print(math.factorial(N)//math.factorial(N-2)//2)
print(math.factorial(M)//math.factorial(max(M-2, 1))//2)
'''
num = math.factorial(N)//math.factorial(max(N-2, 1))//2 + math.factorial(M)//math.factorial(max(M-2, 1))//2
print(num)

Solution (Python):
n,m = map(int,input().split())
ans = 0
for i in range(n):
    for j in range(i+1,n):
        ans += 1
for i in range(m):
    for j in range(i+1,m):
        ans += 1
print(ans)

Solution (Python):
n, m = map(int, input().split())
a = n * (n - 1) // 2
b = m * (m - 1) // 2

print(a + b)

Solution (Python):
N,M=map(int,input().split())
if N==0:
    print(M*(M-1)//2)
elif M==0:
    print(N*(N-1)//2)
else:
    print(N*(N-1)//2+M*(M-1)//2)

Solution (Python):
from math import factorial

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

ans = 0
if n > 1:
    ans += factorial(n) / factorial(2) / factorial(n - 2)
if m > 1:
    ans += factorial(m) / factorial(2) / factorial(m - 2)

print(int(ans))

Solution (Python):
n, m = map(int, input().split())
n_l = [i for i in range(0,n*2,2)]
m_l = [i for i in range(1,m*2,2)]
hoge = n_l + m_l
count = 0
for i in hoge:
    for j in hoge:
        if (i!=j)&((i+j)%2==0):
            count+=1
print(int(count/2))

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

Solution (Python):
N,M = map(int, input().split())

ans = (N*(N-1) + M*(M-1))/2

print(int(ans))

Solution (Python):


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

print(N*(N-1)//2 + M*(M-1)//2)

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

Solution (Python):
s = [int(i) for i in input().split()]
if (s[0] == 0 or s[0] == 1):
  s0 = 0
else:
  s0 = s[0]*(s[0]-1)/2
if (s[1] == 0 or s[1]==1):
  s1 = 0
else:
  s1 = s[1]*(s[1]-1)/2

print(int(s0+s1))

Solution (Python):
N, M = map(int, input().split())

ans = N * (N - 1) + M * (M-1)
ans = ans // 2
print(ans)

Solution (Python):
import math
a,b=map(int,input().split())
if a>3:
    a_v=math.factorial(a)//math.factorial(a-2)//math.factorial(2)
elif a==3:
    a_v=2
elif a==2:
    a_v=1
else:
    a_v=0
if b>3:
    b_v=math.factorial(b)//math.factorial(b-2)//math.factorial(2)
elif b==3:
    b_v=3
elif b==2:
    b_v=1
else:
    b_v=0
print(a_v+b_v)

Solution (Python):

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def main():
    n,m = map(int, input().split())
    diff = m * n
    print(int(combinations_count(n+m, 2)) - diff )

if __name__ == '__main__' :
    main()

Solution (Python):
import itertools

N, M = input().split(" ")
N = int(N)
M = int(M)

S = 0
S += len(list(itertools.combinations(range(N), 2)))

if M > 1:
    S += len(list(itertools.combinations(range(M), 2)))

print(S)

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

Solution (Python):
line = input().strip().split(" ")
even = int(line[0])
odd = int(line[1])

if even > 1 and odd <= 1:
    result = (even * (even - 1)) / 2
    print(int(result))
elif even <= 1 and odd > 1:
    result = (odd * (odd -1)) / 2
    print(int(result))
elif even >1 and odd > 1:
    result = (even * (even -1)) / 2 + (odd * (odd - 1)) / 2
    print(int(result))
else:
    print(0)

Solution (Python):
import sys; sys.setrecursionlimit(2147483647); input = sys.stdin.readline
from math import floor, ceil, sqrt, factorial, log
from collections import Counter, defaultdict, deque
from operator import itemgetter
INF = float('inf'); MOD = 10**9+7
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(MI())
def LIR(n): return [LI() for i in range(n)]
def IS(): return input().rstrip()
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


def main():
    N, M = MI()
    if N > 1:
        n = combinations_count(N, 2)
    else:
        n = 0
    if M > 1:
        m = combinations_count(M, 2)
    else:
        m = 0
    print(n+m)

if __name__ == '__main__':
    main()

Solution (Python):
import math
list_int = [int(e) for e in input().split()]
N = list_int[0]
M = list_int[1]

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)
N_cnt = 0 
M_cnt = 0
if N == 2:
    N_cnt = 1
elif N <= 1:
    N_cnt = 0
else:
    N_cnt = permutations_count(N, 2)/2
if M < 2:
    M_cnt = 0
elif M == 2:
    M_cnt = 1
else:
    M_cnt = permutations_count(M, 2)/2
ans_cnt = N_cnt + M_cnt
print(int(ans_cnt))

Solution (Python):

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

even = N
odd = M

ans = N




def nc(n):
    return n*(n-1) / 2


ans = nc(N) + nc(M)      

print(int(ans))

Solution (Python):
from itertools import combinations
N,M = map(int, input().split())
a = list(combinations(range(N), 2))
b = list(combinations(range(M), 2))
print(len(a)+len(b))

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

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

Solution (Python):
def main():
  n, m = list(map(int, input().split()))
  
  if n == 1 and m == 1:
    return 0
  if n+m == 2:
    return 1
  
  total = factorial(n+m) / (factorial(n+m-2) * 2)
  return int(total - (n*m))

def factorial(value):
  result = value
  for i in range(1, value-1):
    result *= (value-i)

  return result

print(main())

Solution (Python):
from math import factorial

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

if N <= 1:
  a = 0
else:
  a = factorial(N) / 2 / factorial(N - 2)
  
if M <= 1:
  b = 0
else:
  b = factorial(M) / 2 / factorial(M - 2)
  
print(int(a+b))

Solution (Python):
m,n=map(int,input().split())
ans_m=0
ans_n=0
if m != 0 and m != 1:
  ans_m = m*(m-1)/2
if n != 0 and n != 1:
  ans_n = n*(n-1)/2
print(int(ans_m + ans_n))

Solution (Python):
from math import factorial

N, M = input().split()
N = int(N)
M = int(M)

i=0
j=0
if N == 0 or N == 1:
  i += 0
else:
  i = factorial(N) / factorial(2) / factorial(N - 2)

if M == 0 or M == 1:
  j += 0
else:
  j = factorial(M) / factorial(2) / factorial(M - 2)

  
print(int(i+j))

Solution (Python):
from math import factorial


def perm(n, r):
    return factorial(n) // factorial(n - r)


def comb(n, r):
    if n < r:
        return 0
    return perm(n, r) // factorial(r)


N, M = map(int, input().split())
print(comb(N, 2) + comb(M, 2))

Solution (Python):
n, m = map(int,input().split())

print(n*(n-1)//2+m*(m-1)//2)

Solution (Python):
a = input().split()
N = int(a[0])
M = int(a[1])

answer = (N*(N-1) / 2) + (M*(M-1) / 2)

print(int(answer))

Solution (Python):
def Main(N, M):
    return N*(N-1)//2+M*(M-1)//2
                     

def main():
    N, M = map(int, input().split())
    print(Main(N, M))

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
N,M = map(int,input().split())

a= list(combinations(range(N),2))
b= list(combinations(range(M),2))
print(len(a)+len(b))

Solution (Python):
N, M = map(int, input().split())
ans = 0
for n in range(N+1):
    if(n > 1):
        ans += (n-1)
for m in range(M+1):
    if(m > 1):
        ans += (m-1)

print(ans)

Solution (Python):
x = input().split(" ")
N = int(x[0])
M = int(x[1])
T = int(N*(N-1)/2+M*(M-1)/2)
print(T)

Solution (Python):
def comb(n):
    if n < 2:
        return 0
    else:
        return n * (n - 1) // 2


N, M = map(int, input().split())
print(comb(N) + comb(M))

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

Solution (Python):

N, M = map(int, input().split())
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if N != 0:
  if N != 1:
    N_sum = combinations_count(N, 2)
  else:
    N_sum = 0
else:
  N_sum = 0
if M != 0:
  if M != 1:
    M_sum = combinations_count(M, 2)
  else:
    M_sum = 0
else:
  M_sum = 0
print(N_sum + M_sum)

Solution (Python):
N,M = map(int,input().split())
from math import factorial

if N<= 1 and M <=1:
    print(0)

elif N >= 2 and M <=1:
    ans = factorial(N) / factorial(2) / factorial(N - 2)
    print(int(ans))
        
elif N <= 1 and M >= 2:
    ans =factorial(M) / factorial(2) / factorial(M - 2)
    print(int(ans))    

else:
    ans = (factorial(N) / factorial(2) / factorial(N - 2))+factorial(M) / factorial(2) / factorial(M - 2)
    print(int(ans))

Solution (Python):
def fact(k):
    val = 1
    for i in range(2, k+1):
        val = val*i
    return val

n, m = map(int, input().split())
if n < 2:
    even_comb = 0
else:
    even_comb = fact(n) / (fact(2) * fact(n-2))
if m < 2:
    odd_comb = 0
else:
    odd_comb = fact(m) / (fact(2) * fact(m-2))
print(int(even_comb + odd_comb))

Solution (Python):
from operator import mul
from functools import reduce

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

Nans = 0
Mans = 0

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if N == 0 or N == 1:
    Nans = 0
else:
    Nans = cmb(N, 2)

if M == 0 or M == 1:
    Mans = 0
else:
    Mans = cmb(M, 2)

print(Nans + Mans)

Solution (Python):
from functools import reduce
def permu(n,r):
    return reduce(lambda a,b: a*b, range(n-r+1,n+1))
N,M = map(int, input().split())
print(int((permu(N,2)+permu(M,2))/2))

Solution (Python):
import itertools
a = list(map(int,input().split()))

s = [i for i in range(a[0])]
t = [i for i in range(a[1])]

n = list(itertools.combinations(s, 2))
m = list(itertools.combinations(t, 2))

print(len(n) + len(m))

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N !=0 and N != 1:
    a = combinations_count(N, 2)
else:
    a = 0

if M !=0 and M != 1:
    b = combinations_count(M, 2)
else:
    b = 0

print(a+b)

Solution (Python):
N, M = list(map(int, input().split()))

print(N * (N - 1) // 2 + M * (M - 1) // 2)

Solution (Python):
inputs = input().split(' ')
 
N = int(inputs[0])
M = int(inputs[1])
 
pattern_N = 0
pattern_M = 0
 
if N > 0:
  pattern_N = N * (N - 1) // 2 
  
if M > 0:
  pattern_M = M * (M - 1) // 2 
  
print(pattern_N + pattern_M)

Solution (Python):
n,m = map(int,input().split())
import itertools
def permutations_count(n,r):
    return len(list(itertools.combinations(range(n), r)))
print(permutations_count(int(n),2)+permutations_count(int(m),2))

Solution (Python):
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

if N != 1 and N != 0:
    N = combinations_count(N, 2)
else:
    N = 0
if M != 1 and M != 0:
    M = combinations_count(M, 2)
else:
    M = 0


print(N+M)

Solution (Python):
n,m = map(int, input().split())
if n <= 1:
  ans = 0
else:
  ans=n*(n-1)/2
if m <= 1:
  ams = 0
else:
  ams=m*(m-1)/2
print(round(ans+ams))

Solution (Python):
N, M = map(int, input().split(" "))

print(N*(N-1)//2 + M*(M-1)//2)

Solution (Python):
n,m =(int(x) for x in input().split())
N = 0
M = 0
if n >1:
    N = n *(n-1)/2
if m > 1:
    M = m*(m-1)/2
a = int(N + M)
print(a)

Solution (Python):
import math


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


h, w = input().split(" ")
h, w = int(h), int(w)

ans = 0
if (h > 1):
    ans += comb(h, 2)
if (w > 1):
    ans += comb(w, 2)
print(ans)

Solution (Python):
N,M=map(int,input().split())
if N>1 and M>1:
  print(int((N*(N-1)/2)+(M*(M-1)/2)))
elif N<=1:
    if M<=1:
      print(0)
    else:
        print(int(M*(M-1)/2))
else:
  print(int(N*(N-1)/2))

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

Solution (Python):
import math
n,m=map(int,input().split())
def comb(k, r):
  if k<2:
    return 0
  else:
    return math.factorial(k) // (math.factorial(k - r) * math.factorial(r))

print(comb(n,2)+comb(m,2))

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

Solution (Python):
n,m = map(int,input().split())
ans1 = n*(n-1)//2
ans2 = m*(m-1)//2
print(ans1+ans2)

Solution (Python):
N,M = map(int,input().split())
sum = 0
array = []
for i in range(N):
    array.append(0)
for i in range(M):
    array.append(1)
for i in range(N+M-1):
    for j in range(i+1,N+M):
        if((array[i]+array[j])%2 == 0):
            sum += 1

print(sum)

Solution (Python):
import itertools

n,m = map(int, input().split())
print(len(list(itertools.combinations(range(m),2))) + len(list(itertools.combinations(range(n),2))))

Solution (Python):
import math
def combinations_count(n, r):
 return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
A=0
N,M=map(int,input().split())
if N<2:
 A+=0
else:
 A+=combinations_count(N, 2)
if M<2:
 A+=0
else:
 A+=combinations_count(M, 2)
print(A)

Solution (Python):
N,M=map(int,input().split())
a = N*(N-1)//2
b = M*(M-1)//2

ans = a+b

print(ans)

Solution (Python):
n,m=map(int,input().split())
count=0
a=[]
for i in range(n):
    a.append(2)
for i in range(m):
    a.append(1)


for i in range(n+m-1):
    for j in range(i+1,n+m):
        
        if (a[i]+a[j])%2==0:
            count+=1
print(count)

Solution (Python):
N,M=map(int,input().split())

print(int(N*(N-1)/2)+int(M*(M-1)/2))

Solution (Python):
import math
a = []
a = input().split()
N = int(a[0])
M = int(a[1])



if N < 2 and M < 2:
  T = 0
if N < 2 and M > 1:
  T = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
if M < 2 and N > 1:
  T = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
if N > 1 and M > 1:
  T = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2)) + math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))

print(T)

Solution (Python):
N,M=map(int,input().split())
a = N*(N-1)//2
b = M*(M-1)//2

ans = a+b

print(ans)

Solution (Python):
import itertools

n,m = map(int, input().split())
print(len(list(itertools.combinations(range(m),2))) + len(list(itertools.combinations(range(n),2))))

Solution (Python):
import math 

N2,M1 = map(int, input().split())
count=0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N2!=0 and N2!=1:
    count += combinations_count(N2,2)
if M1!=0 and M1!=1:
    count += combinations_count(M1,2)

print(count)

Solution (Python):
from itertools import combinations

n,m = map(int, input().split())
a = list(combinations(range(n),2))
b = list(combinations(range(m),2))

print(len(a)+len(b))

Solution (Python):


import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = LI()

if N >= 2:
    nn = combinations_count(N , 2)
else:
    nn = 0

if M >= 2:
    mm = combinations_count(M , 2)
else:
    mm = 0

print(nn + mm)

Solution (Python):
from itertools import combinations

N, M = map(int, input().split())
nlist = [] 
mlist = []

for i in range(N):
  nlist.append(i)
  
for j in range(M):
  mlist.append(j)

if N == 1 and M == 1:
  print(0)
  exit()
  
if N == 1:
  print(len(list(combinations(mlist,2))))
  exit()
  
if M == 1:
  print(len(list(combinations(nlist,2))))
  exit()
  
print(len(list(combinations(nlist,2))) + len(list(combinations(mlist,2))))

Solution (Python):
import math

N,M = map(int,input().split(' '))
count = 0

if N > 1:
    count += N*(N-1)//2
if M > 1:
    count += M*(M-1)//2
print(int(count))

Solution (Python):
N, M = map(int, input().split())

print(N * (N - 1) // 2 + M * (M - 1) // 2)

Solution (Python):
import itertools

n,m = map(int, input().split())
print(len(list(itertools.combinations(range(m),2))) + len(list(itertools.combinations(range(n),2))))

Solution (Python):
from operator import mul
from functools import reduce


def cmb(n_cmb, r_cmb):
    r_cmb = min(n_cmb - r_cmb, r_cmb)
    if r_cmb == 0: return 1
    over = reduce(mul, range(n_cmb, n_cmb - r_cmb, -1))
    under = reduce(mul, range(1, r_cmb + 1))
    return over // under


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

if n <= 1:
    ansn = 0
else:
    ansn = cmb(n, 2)

if m <= 1:
    ansm = 0
else:
    ansm = cmb(m, 2)
print(ansn + ansm)

Solution (Python):
import itertools

n,m = map(int, input().split())
print(len(list(itertools.combinations(range(m),2))) + len(list(itertools.combinations(range(n),2))))

Solution (Python):

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

ans = 0
if m >= 2:
    ans += m*(m-1) // 2
if n >= 2:
    ans += n*(n-1) // 2

print(ans)

Solution (Python):

import math

n, m = map(int, input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(r)*math.factorial(n - r))

if n < 2:
  ns = 0
else:
  ns = combinations_count(n, 2)
if m < 2:
  ms = 0
else:
  ms = combinations_count(m, 2)
s = ns + ms
print(s)

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

Solution (Python):

import sys


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



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)

if __name__ == '__main__':
    main()

Solution (Python):
from math import factorial

n, m = map(int, input().split())
if n in [0, 1] and m in [0, 1]:
    ans = 0
elif n in [0, 1]:
    ans = factorial(m) // (factorial(m - 2) * factorial(2))
elif m in [0, 1]:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
else:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
    ans += factorial(m) // (factorial(m - 2) * factorial(2))
print(ans)