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



Sample input:
2 1


Sample output:
1

Submission status: Accepted

Solution code:
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 or N == 0:
    guu = 0
else:
    guu = combinations_count(N, 2)
if M == 1 or M == 0:
    kisu = 0
else:
    kisu = combinations_count(M, 2)
print(guu + kisu)

Submission status: Accepted

Solution code:
import math

def P(n, r):
    if n < r:
        return 0
    return math.factorial(n)//math.factorial(n-r)


def C(n, r):
    return P(n, r)//math.factorial(r)

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

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

Submission status: Accepted

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

print(sum(range(N)) + sum(range(M)))

Submission status: Accepted

Solution code:

def fac(n):
    if (n == 1 or n == 0):
        return 1
    return n * fac(n - 1)

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

Submission status: Accepted

Solution code:
from math import pow
n,m=(int(i) for i in input().split())
if(n==1):
  n=0
if(m==1):
  m=0
print(int(((pow(n,2))+(pow(m,2))-(m+n))//2))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, input().split())
    ans = n * (n - 1) // 2 + m * (m - 1) // 2
    print(ans)

Submission status: Accepted

Solution code:
import math
N,M = map(int, input().split())
a = 0
b = 0
if N != 1 and N != 0:
    a = math.factorial(N)/(2*math.factorial(N-2))
if M != 1 and M != 0:
    b = math.factorial(M)/(2*math.factorial(M-2))
print(int(a+b))

Submission status: Accepted

Solution code:
init = [int(s) for s in input().rstrip().split(' ')]
res = (init[0] * (init[0]-1))/2 + (init[1] * (init[1]-1))/2
print(int(res))

Submission status: Accepted

Solution code:
n,m=(int(x) for x in input().split())

n_dot = n*(n-1)/2
m_dot = m*(m-1)/2

answer = int(n_dot+ m_dot)
print(answer)

Submission status: Accepted

Solution code:
import itertools

N, M = map(int, input().split())
A = [0] * N + [1] * M

ans = 0
for i, j in itertools.combinations(A, 2):
  B = i + j
  if B % 2 == 0:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

def f(n, r):
    if n < 2:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

Submission status: Accepted

Solution code:
N,M=input().split()
N=int(N)
M=int(M)
if (0<=N<=100)and(0<=M<=100)and(2<=N+M):
    a=N*(N-1)/2+M*(M-1)/2
    a=int(a)
    print(a)

Submission status: Accepted

Solution code:
import math 
def ncr(m,n):
    return((math.factorial(m))/((math.factorial(n))*(math.factorial(m-n))))
nm=list(map(int,input().split()))
if(nm[0]<2 and nm[1]>=2):
    print(int(ncr(nm[1],2)))
elif(nm[0]>=2 and nm[1]<2):
    print(int(ncr(nm[0],2)))
elif(nm[0]<2 and nm[1]<2):
    print(0)
else:
    print(int(ncr(nm[0],2)+ncr(nm[1],2)))

Submission status: Accepted

Solution code:
n, m = (int(x) for x in input().split())
if n != 0:
  if m != 0:
    ans = (n * (n - 1)) // 2 + (m * (m - 1)) // 2
  else:
  	ans =  (n * (n - 1)) // 2
else:
  if m != 0:
    ans = (m * (m - 1)) // 2
  else:
    ans = 0
print(ans)

Submission status: Accepted

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

ans = 0

if n > 1:
  if n % 2 != 0:
    ans += n * (n // 2)
  else:
    ans += n * ((n-1) // 2) + n / 2 

if m > 1:
  if m % 2 != 0:
    ans += m * (m // 2)
  else:
    ans += m * ((m-1) // 2) + m / 2

print(int(ans))

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
if(N>=2):
    n = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2))
else:
    n = 0

if(M>=2):
    m = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2))
else:
    m = 0
print(n+m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M, N = map(int,input().split())
ans = 0

ans1 = M*(M-1)//2
ans2 = N*(N-1)//2

ans = ans1 + ans2
print(ans)

Submission status: Accepted

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

n1 = n - 1
m1 = m - 1

res = int((n * n1) / 2 + (m * m1) / 2)

print(res)

Submission status: Accepted

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

n = 0
m = 0
if N <= 1:
  n = 0
else:
  n = (N*(N-1))/2
if M <= 1:
  m = 0
else:
  m = (M*(M-1))/2
print(int(n + m))

Submission status: Accepted

Solution code:
import math

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


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

n = 0
m = 0
r = 2

if N>1:
    n = combinations_count(N, r)
if M>1:
    m = combinations_count(M, r)

sum = n+m
print(sum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

if N == 1 and M == 1:
  print(0)
else:
  n = 0
  if N != 0:
    for i in range(N-1):
      n += 1+i
  else:
    n = 0
  if M != 0:
    m = (M * (M-1)) / 2
  else:
    m = 0
  print(int(n + m))

Submission status: Accepted

Solution code:
from math import factorial
def combinations_count(n, r):
    if n <= 1:
        return 0
    else:   
        return factorial(n) // (factorial(n - r) * factorial(r))
N,W = map(int,input().split())
even = combinations_count(N,2)
odd = combinations_count(W,2)
print(odd+even)

Submission status: Accepted

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

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

if M < 2 and N < 2:
    print(0)
elif M < 2:
    print(comb(N,2))
elif N < 2:
    print(comb(M,2))
else:
    print(comb(N,2) + comb(M, 2))

Submission status: Accepted

Solution code:
from math import factorial

x = input().split()
N = int(x[0])
M = int(x[1])

if N <= 1 and M <= 1:
  print(0)
elif N >= 2 and M <= 1:
  print(factorial(N) // factorial(2) // factorial(N - 2))
elif N <=1 and M >=2:
  print(factorial(M) // factorial(2) // factorial(M - 2))
else:
  print(factorial(N) // factorial(2) // factorial(N - 2) + factorial(M) // factorial(2) // factorial(M - 2))

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
result_x = 0
result_y = 0
if x > 1:
    result_x = 0
    for i in range(x):
        result_x = result_x + i

if y > 1:
    result_y = 0
    for i in range(y):
        result_y = result_y + i


print(result_x + result_y)

Submission status: Accepted

Solution code:
import itertools
N,M = list(map(int,input().split()))
N_list = [i for i in range(N)]
N_result = list(itertools.combinations(N_list, 2))
M_list = [i for i in range(M)]
M_result = list(itertools.combinations(M_list, 2))
print(len(N_result + M_result))

Submission status: Accepted

Solution code:
even, odd = map(int, input().split())
s = even * (even -1) // 2
s += odd * (odd - 1) // 2
print(s)

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
a=i[0]*(i[0]-1)/2+i[1]*(i[1]-1)/2
print(int(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
print(int(math.factorial(N+M)/(math.factorial(N+M-2)*2)-N*M))

Submission status: Accepted

Solution code:
import math
import itertools
N,M = input().split()
N1=int(N)
M1=int(M)
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if N1>=2:
    n=combinations_count(N1,2)
else:
    n=0
if M1>=2:
    m=combinations_count(M1,2)
else:
    m=0
print(n+m)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    a, b = map(int, input().split())
    ans = 0

    if a > 1:
        a = a-1
        ans = (1+a)*a//2
    if b > 1:
        b = b-1
        ans =ans + (1+b)*b//2



    print(ans)

Submission status: Accepted

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

print(answer)

Submission status: Accepted

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

P = n+m

TOTAL = P*(P-1)//2
SUB = n*m

print(TOTAL - SUB)

Submission status: Accepted

Solution code:
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def comb(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

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

ans1=comb(n,2)
ans2=comb(m,2)

if n<=1:
    ans1=0
if m<=1:
    ans2=0

print(ans1+ans2)

Submission status: Accepted

Solution code:
from math import factorial
def ncr(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)

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

# n = int(input())

# a = list(map(int, input().split()))

if m < 2 :
    if n < 2:
        print(0)
    else:
        print(ncr(n,2))
else:
    if n < 2:
        print(ncr(m,2))
    else:
        print(ncr(n,2)+ncr(m,2))

Submission status: Accepted

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

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

Submission status: Accepted

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

def aPb(a,b):
    x = a
    for i in range(b-1):
        x *= (a-1-i)
    return x

print(int((aPb(n,2) + aPb(m,2))/2))

Submission status: Accepted

Solution code:
s1 = 0
s2 = 0
n,m = map(int,input().split())
for i in range(1,n):
  s1 += i
for i in range(1,m):
  s2 += i
s = s1 + s2
print(s)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def nCr(n, r):
    return (fact(n) / (fact(r)* fact(n - r)))

def fact(n):
    res = 1
    if n == 0:
        res == 1
    elif n == 1:
        res == 1
    else:
        for i in range(2, n + 1):
            res = res * i

    return res

inList = list(map(int, input().split()))
N = inList[0]
M = inList[1]
a = nCr(N, 2)
b = nCr(M, 2)
if N == M == 1:
    print(0)
else:
    print(int(a+b))

Submission status: Accepted

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

N -= 1
M -= 1

print(((N * (N + 1))//2 if N > 0 else 0) + ((M * (M + 1))//2 if M > 0 else 0))

Submission status: Accepted

Solution code:
import sys
import math
import collections
from collections import deque
#n = int(input())
n, m = map(int, sys.stdin.readline().split())
#s = input()
#x = list(map(int, sys.stdin.readline().split()))

if n <= 1:
    a = 0
else:
    a = math.factorial(n) // (math.factorial(n - 2) * 2)

if m <= 1:
    b = 0
else:
    b = math.factorial(m) // (math.factorial(m - 2) * 2)

print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
integer = list(map(int, input().split())) 
conbi = (integer[0] * (integer[0] - 1) + integer[1] * (integer[1] -1 ) ) / 2
print(int(conbi))

Submission status: Accepted

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

from operator import mul
from functools import reduce

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

a = cmb(N+M, 2)
print(a-N*M)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    n = 1
    m = 1
    for i in range(N, N-2, -1):
        n *= i
    for i in range(M, M-2, -1):
        m *= i
    print((n + m) // 2)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
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 >= 2:
	a = combinations_count(n,2)
else:
    a = 0
    
if m >= 2:
	b = combinations_count(m,2)
else:
    b = 0

print(a+b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

n,m=map(int, input().split())
a = 0
b = 0
if n > 1:
  a = cmb(n, 2)  
if m > 1:
  b = cmb(m,2)
print(a+b)

Submission status: Accepted

Solution code:
from scipy.misc import comb
n, m = map(int, input().split())
print(comb(n, 2, exact=True)+comb(m, 2, exact=True))

Submission status: Accepted

Solution code:
import math

nums = map(int,input().split())

ans=0
for n in nums:
    if n<2:
    	continue
    ans+=math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
print(ans)

Submission status: Accepted

Solution code:
elms = input().split(" ")

N= int(elms[0])
M= int(elms[1])


ev =N * (N-1)
ev= ev/2 

od = M*(M-1)
od = od/2

print(int(ev+od))

Submission status: Accepted

Solution code:
import math
def combi(n,r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def main():
    n,m = map(int,input().split())
    print(combi(n,2)+combi(m,2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

s = 0
if n > 1:
    s = math.factorial(n)/math.factorial(n-2)
if m > 1:
    s += math.factorial(m)/math.factorial(m-2)
print(int(s/2))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

ansA = 0

if N < 2 and M < 2:
    ansA = 0
if N >=2:
    ansA += ((N * (N-1)) / 2)
if M >= 2:
    ansA += ((M * (M-1)) / 2)

print(int(ansA))

Submission status: Accepted

Solution code:
n,m = list(map(int,input().split()))
s = 0
if n>=2:
	s += (n*(n-1))//2
if m>=2:
	s += (m*(m-1)//2)
print(s)

Submission status: Accepted

Solution code:
import math

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

gusu = 0
kisu = 0

if N >= 2:
    gusu = math.factorial(N) / ( math.factorial(N - 2) * 2 )

if M >= 2:
    kisu = math.factorial(M) / ( math.factorial(M - 2) * 2 )

print(int(gusu + kisu))

Submission status: Accepted

Solution code:
import math
N,M = map(int, input().strip().split())
def cmb(r,k):
  if r < k: return 0
  return math.factorial(r) // math.factorial(r-k) // math.factorial(k)
print(cmb(N,2)+cmb(M,2))

Submission status: Accepted

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

import itertools
nl=[]
ml=[]
for n in range(1,N+1):
    nl.append(n)
for m in range(1,M+1):
    ml.append(m)
nnum=len(list(itertools.combinations(nl,2)))
mnum=len(list(itertools.combinations(ml,2)))
res=nnum+mnum
print(res)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
sum = 0
for i in range(n):
  sum += i
for i in range(m):
  sum += i
print(sum)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
from functools import reduce
from operator import mul

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 >= 2 and M >= 2:

    print(cmb(N, 2) + cmb(M, 2))
elif N >= 2 :
    print(cmb(N, 2))
elif M >= 2:
    print(cmb(M, 2))
else:
    print(0)

Submission status: Accepted

Solution code:
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom
  
m, n = map(int, input().strip().split())
print((ncr(m, 2) if m >=2 else 0) + (ncr(n, 2) if n >= 2 else 0))

Submission status: Accepted

Solution code:
import itertools
import math


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


temp_n = combinations_count(n+m,2)
    
print(temp_n - (n*m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.misc import comb
n, m = [int(x) for x in input().split()]



print(int(comb(n, 2, exact=True) + comb(m, 2, exact=True)))

Submission status: Accepted

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

Submission status: Accepted

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

from math import factorial
if N > 1:
    a = factorial(N) // factorial(2) // factorial(N - 2)
else:
    a = 0

if M > 1:
    b = factorial(M) // factorial(2) // factorial(M - 2)
else:
    b = 0

print(a + b)

Submission status: Accepted

Solution code:
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    even = (N * (N - 1)) // 2
    odd = 0 if M == 1 else (M * (M - 1)) // 2
    print(even + odd)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import numpy as np

def main():
    n, m = map(int, input().split(" "))
    ans = 0
    for i in [n, m]:
        iterable = np.arange(start=1, stop=i+1, step=1).astype("str")
        ans += len(list(itertools.combinations(iterable, 2)))


    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def comb(a, r):
    if a <= 1:
        return 0
    from math import factorial
    return factorial(a) / factorial(r) / factorial(a - r)

n, m = (int(each) for each in input().split(' '))

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

Submission status: Accepted

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

a = 0
for i in range(N):
    a += i

b=0
for j in range(M):
    b += j

print(a+b)

Submission status: Accepted

Solution code:
import itertools
nm = list(map(int, input().split()))
print(len(list(itertools.combinations(range(nm[0]),2))) + len(list(itertools.combinations(range(nm[1]),2))))

Submission status: Accepted

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

if n <= 1:
  n_even = 0
else:
  n_even = n * (n-1) / 2
if m <= 1:
  m_even = 0
else:
  m_even = m * (m-1) / 2

even = n_even + m_even
print(int(even))

Submission status: Accepted

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

nums = [(i+1) * 2 for i in range(n)] + [(i * 2) + 1 for i in range(m)]

ans = 0
for i in range(len(nums)):
    for j in range(i):
        if (nums[i] + nums[j]) % 2 == 0:
            ans += 1
print(ans)

Submission status: Accepted

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
  
n,m =map(int, input().split())
if n==m==1:
    print(0)
elif n==1 or n==0:
    print(cmb(m,2))
elif m==1 or m==0:
    print(cmb(n,2))
else:
    print(cmb(n,2)+cmb(m,2))

Submission status: Accepted

Solution code:
import math
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
import numpy as np

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

# A = input()
# A = int(input())
N, M = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

cN = 0
cM = 0
if N == 0:
    cN = 0
elif N == 1:
    cN == 1
else:
    cN = permutations_count(N, 2)

if M == 0:
    cM = 0
elif M == 1:
    cM == 1
else:
    cM = permutations_count(M, 2)

print(cN + cM)

Submission status: Accepted

Solution code:
from scipy.misc import comb
N,M = map(int,input().split())
even = comb(N,2,exact=True)
odd = comb(M,2,exact=True)
print(even + odd)

Submission status: Accepted

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

import math

if n >= 2:
    cn = math.factorial(n) / math.factorial(2) / math.factorial(n - 2)
else:
    cn = 0
if m >= 2:
    cm = math.factorial(m) / math.factorial(2) / math.factorial(m - 2)
else:
    cm = 0

print(int(cn + cm))

Submission status: Accepted

Solution code:
import math

inp = list(map(int,input().split()))
N,M = inp
r1 = math.factorial(2)
if N > 1:
    N1 = math.factorial(N)
    Nr1 = math.factorial(N-2)
    a = N1/r1/Nr1
else:
    a = 0

if M > 1:
    M1 = math.factorial(M)
    Mr1 = math.factorial(M-2)
    b =M1/r1/Mr1
else:
    b = 0

kai = a + b
print(int(kai))

Submission status: Accepted

Solution code:
line = input()
n, m = line.split(" ")
n = int(n)
m = int(m)

if n < 2 and m < 2:
    print("0")
elif n < 2 and m >= 2:
    ans = 0
    for i in range(m):
        ans = ans + (i)
    print(ans)
elif n >= 2 and m < 2:
    ans = 0
    for i in range(n):
        ans = ans + (i)
    print(ans)
elif n >= 2 and m >= 2:
    ans = 0
    for i in range(n):
        ans = ans + (i)
    for i in range(m):
        ans = ans + (i)
    print(ans)

Submission status: Accepted

Solution code:
k = list(map(int, input().split()))
l = k[0] * (k[0] -1) / 2
m = k[1] * (k[1] -1) / 2
print(int(l + m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = 0
P = 0
N,M = map(int,input().split())
if N == 0:
    S = 0
else:
    for i in range(1,N):
        S += i
if M == 0:
    P = 0
else:
    for i in range(1,M):
        P += i
print(S+P)

Submission status: Accepted

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

def fn(n):
    if n <= 1:
        return 0
    return n - 1 + fn(n-1)

ans = fn(n) + fn(m)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def c(x):
  if x <= 1:
    r = 0
  else:
    r = int((x * (x-1))/2)
  return r

n, m =list(map(int, input().split()))
print(c(n)+c(m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def combination(n, r):
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)
    return a // b
print(combination(n+m, 2)-n*m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial


def combinations_count(n, r):
    if n < 2:
        return 0
    return factorial(n) // (factorial(r) * factorial(n - r))

N, M = list(map(int, input().split(' ')))
N_combinations = combinations_count(N, 2)
M_combinations = combinations_count(M, 2)

print(N_combinations +  M_combinations)

Submission status: Accepted

Solution code:
import math
import itertools
n,m = map(int,input().split())
ite = n+m

c = 0

li = []
for i in range(n):
    li.append(2)
for i in range(m):
    li.append(1)


for i in itertools.combinations(li, 2):
    sum = i[0]+i[1]

    if(sum %2 == 0):
        c += 1
    

print(c)

Submission status: Accepted

Solution code:
import math
n,m=map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(combinations_count(n+m,2)-n*m)

Submission status: Accepted

Solution code:
nm = list(map(int, input().split()))

if nm[0]<=1 and nm[1]<=1:
    print(0)
else:
    print(int((nm[0]*(nm[0]-1))/2*1+(nm[1]*(nm[1]-1))/2*1))

Submission status: Accepted

Solution code:
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

N, M = map(int, input().split(' '))
if (N >= 2) & (M >=2):
	print(cmb(N, 2) + cmb(M, 2))
elif (N < 2) & (M >=2):
	print(cmb(M, 2))
elif (M < 2) & (N >= 2):
	print(cmb(N, 2))
else:
    print(0)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==2:
  count=1
else:
  count=n*(n-1)//2
  
if m==2:
  countt=1
else:
  countt=m*(m-1)//2

print(count+countt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

if (n < 2) and (m < 2):
    tn = tm = 0
elif (n >= 2) and (m < 2):
    tn = math.factorial(n) // (math.factorial(n - 2)*2)
    tm = 0
elif (m >= 2) and (n < 2):
    tn = 0 
    tm = math.factorial(m) // (math.factorial(m - 2)*2)
else:
    tn = math.factorial(n) // (math.factorial(n - 2)*2)
    tm = math.factorial(m) // (math.factorial(m - 2)*2)

print(tn+tm)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if a <= 1:
        a2 = 0
else:
        a2 = a * (a-1) // 2
if b <= 1:
        b2 = 0
else:
        b2 = b * (b-1) // 2
print(a2 + b2)

Submission status: Accepted

Solution code:
import math

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

n,m=map(int,input().split())
if n<2 and m>=2:
    print(comb_count(m,2))
elif n>=2 and m<2:
    print(comb_count(n,2))
elif n<2 and m<2:
    print(0)
else:
    print(comb_count(n,2)+comb_count(m,2))

Submission status: Accepted

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

from math import factorial

cn = 0
cm = 0

if n >= 2:
    cn = factorial(n) // (factorial(n - 2) * factorial(2))

if m >= 2:
    cm = factorial(m) // (factorial(m - 2) * factorial(2))

print(int(cn+cm))

Submission status: Accepted

Solution code:

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

a = int(n*(n-1)/2)
b = int(m*(m-1)/2)

print(a+b)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = a[0]+a[1]

c = ((a[0]*(a[0]-1))+(a[1]*(a[1]-1)))/2
print(int(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from math import factorial

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

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

if M > 1 and N > 1:
    sum_n = combinations_count(M, 2) + combinations_count(N, 2)

elif M > 1:
    sum_n = combinations_count(M, 2)

elif N > 1:
    sum_n = combinations_count(N, 2)

else:
    sum_n = 0

print(sum_n)

Submission status: Accepted

Solution code:
import math

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

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

if(N==0 and M==0):
  print("0")
elif(N==0 and M==1):
  print("0")
elif(N==1 and M==1):
  print("0")
elif(M==0 or M==1):
  print(com(N, 2))
elif(N==0):
  print(com(M, 2))
else:
  print(com(N, 2) + com(M, 2))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin

def main():

    input = stdin.readline

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

    ans = 0

    ans += comb(N,2)
    ans += comb(M,2)

    print(ans)


def comb(n,k):
    min_k = min(k,n-k)

    if n < 2:
        return 0

    n_kaijyo = 1
    k_kaijyo = 1
    for i in range(min_k):
        n_kaijyo = n_kaijyo * (n - i)
        k_kaijyo = k_kaijyo * (i + 1)

    result = int(n_kaijyo / k_kaijyo)
    return result
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

nn = [1 for i in range(n)]
mm = [2 for i in range(m)]

nn.extend(mm)

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
sum_a = 0
sum_b = 0

if N % 2 == 0:
    sum_a = (N/2) * (N-1)
else:
    sum_a = N * ((N-1)/2)

if M % 2 == 0:
    sum_b = (M/2) * (M-1)
else:
    sum_b = M * ((M-1)/2)

sum = sum_a + sum_b

print(int(sum))