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:
def select(a):
    d=1
    if a==1:
        return 0
    for i in range(a,a-2,-1):
        d=i*d
    return d//2
n,m=map(int,input().split())
print((select(n)+select(m)))

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 and M >= 2:
    ans = combinations_count(N, 2) + combinations_count(M, 2)
elif N >= 2:
    ans = combinations_count(N, 2)
elif M >=2:
    ans = combinations_count(M, 2)
else:
    ans = 0

print(ans)

Submission status: Accepted

Solution code:
import math


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


numbers = input().split()

evens, odds = int(numbers[0]), int(numbers[1])

# result is even if picked [even, even], [odd, odd]
combs = 0
for i in [evens, odds]:
    if i >= 2:
        combs += combinations_count(i, 2)
print(combs)

Submission status: Accepted

Solution code:
from scipy.misc import comb
N,M = (int(x) for x in input().split())
a = comb(N, 2, exact=True) + comb(M, 2, exact=True)
print(a)

Submission status: Accepted

Solution code:
import itertools

N, M = map(int, input().split())
balls = [0] * N + [1] * M
answer = sum((x + y) % 2 == 0 for x, y in itertools.combinations(balls, 2))
print(answer)

Submission status: Accepted

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

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=map(int,input().split())
res=(N*(N-1)+M*(M-1))/2
print(int(res))

Submission status: Accepted

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

    ans = 0
    for i in range(1, N):
        ans += i

    for i in range(1, M):
        ans += i

    print('{}'.format(ans))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def combination(n, r):
    if n <= 0 or n is 1:
        return 0
    return math.factorial(n) // (math.factorial(r) * math.factorial(n - r))

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

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

Submission status: Accepted

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

count = 0
for i in range(a[0]):
  count += i
 
for i in range(a[1]):
  count += i
  
print(count)

Submission status: Accepted

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

if n == 0:
    n = 1

if m == 0:
    m = 1

ans = n * (n-1) / 2 + m * (m-1) /2

print(int(ans))

Submission status: Accepted

Solution code:
import math

def inputlist(): return [int(i) for i in input().split()]

def kumiawase(num):
    r = 2
    if num != 1 and num != 0:
        return math.factorial(num) // (math.factorial(num - r) * math.factorial(r))
    else:
        return 0

def main():
    N, M = inputlist()
    print(kumiawase(N) + kumiawase(M))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def factorial(n):
    if n == 1:
        return 1
    else:
        return n * factorial(n-1)
a,b=map(int, input().split())
cnt=0
if a==2:
    cnt=1
elif a>1:
    cnt=(factorial(a)/((factorial(a-2))*2))
if b==2:
    cnt=cnt+1
elif b>1:
    cnt=(factorial(b)/((factorial(b-2))*2))+cnt
print(int(cnt))

Submission status: Accepted

Solution code:
a, b=input().split()
a=int(a)
b=int(b)
if a<=1 and b<=1:
  print("0")
else:
  if a<=1:
    k=b*(b-1)//2
    print(k)
  elif b<=1:
    k=a*(a-1)//2
    print(k)
  else:
    k=a*(a-1)//2+b*(b-1)//2
    print(k)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
n2 = n*(n-1)/2
m2 = m*(m-1)/2

print(round(n2+m2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-*-

from sys import stdin
import itertools


def main():
    N, M = list( map(int, stdin.readline().split()) )

    O = ['遇' for i in range(N)]
    O.extend(['奇' for i in range(M)])

    A = list(itertools.combinations(O, 2))

    cnt = 0
    for i in A:
        if i.count("遇") in [0, 2]:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def combination(n, x, mod=10**9+7):
    # nCx
    # 組み合わせ
    # ex) combination(5, 2) = 10
    factorial = [1] * (n+1)
    t = 1
    for i in range(1, n+1):
        t = (t * i) % mod
        factorial[i] = t
    tmp = factorial[n]
    tmp = (tmp * pow(factorial[x], mod-2, mod)) % mod
    tmp = (tmp * pow(factorial[n-x], mod-2, mod)) % mod
    return tmp

N,M=map(int,input().split())
ans=0
if N>1:
  ans+=combination(N,2)
if M>1:
  ans+=combination(M,2)
print(int(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  #「A B」みたいなスペース空いた入力のとき
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N < 2:
    a = 0
else:
    a = comb(N, 2)

if M < 2:
    b = 0
else:
    b = comb(M, 2)
print(a+b)

Submission status: Accepted

Solution code:
import itertools

N, M = [int(x) for x in input().split()]

Nlist = [0]*N
Mlist = [0]*M
for n in range(N):
    Nlist[n] = (n+1) * 2

for m in range(M):
    Mlist[m] = (m+m+1) * 1
count = 0
for x in itertools.combinations(Nlist, 2):
    if (x[0] + x[1]) % 2 == 0:
        count = count + 1
for x in itertools.combinations(Mlist, 2):
    if (x[0] + x[1]) % 2 == 0:
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

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


def comb(x):
    if x == 0:
        return 0
    if x == 1:
        return 0
    return x * (x - 1) // 2


print(comb(N) + comb(M))

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

if M == 0 and N == 0:
    print(0)
elif M == 1 and N == 1:
    print(0)
elif M <= 1:
    print(cmb(N, 2))
elif N <= 1:
    print(cmb(M, 2))
else:
    a = cmb(M, 2)
    b = cmb(N, 2)
    print(a + b)

Submission status: Accepted

Solution code:
even,odd = map(int,input().split())
counter = 0
if even >= 2:
    for i in range(even):
        if i == 0:
            continue
        counter += i
if odd >= 2:
    for i in range(odd):
        if i == 0:
            continue
        counter += i
print(counter)

Submission status: Accepted

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

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

def binom(n,k):
  if n==0 or n==1:
    return 0
  else:
    return fac(n) // (fac(n-k) * fac(k))

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

Submission status: Accepted

Solution code:
import math

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

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

if n >= 2:
    x = permutations_count(n, 2)
else:
    x = 0
if m >= 2:
    y = permutations_count(m, 2)
else:
    y = 0
print((x + y)//2)

Submission status: Accepted

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

a = M*(M-1)/2
b = N*(N-1)/2

print(a+b)

Submission status: Accepted

Solution code:
import math

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


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

Submission status: Accepted

Solution code:
inp = list(map(int, input().split()))
result = 0
if inp[0] >1:
    result += inp[0] * (inp[0]-1) / 2
if inp[1] >1:
    result += inp[1] * (inp[1]-1) / 2
    
print(int(result))

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())
ans=0
if N>=2:
    ans+=cmb(N,2)
if M>=2:
    ans+=cmb(M,2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
M,N=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())

x = n + m


x = n + m
z = math.factorial(x) / (2 * math.factorial(x-2))
q = n*m
print(int(z-q))

Submission status: Accepted

Solution code:
import math
H, W = map(int, input().split())

a = (H * (H-1))/2
b = (W * (W-1))/2

print(int(a+b))

Submission status: Accepted

Solution code:
from math import factorial
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())

if N - 2 >= 0:
    a = cmb(N,2)
else:
    a = 0


if M - 2 >= 0:
    b = cmb(M,2)
else:
    b = 0

print(int(a)+int(b))

Submission status: Accepted

Solution code:
import math


def ncr(n, k):
    return math.factorial(n) / (math.factorial(k) * math.factorial(n - k))


n, m = map(int, input().split())
c1, c2 = 0, 0
if n > 1:
    c1 = ncr(n, 2)
if m > 1:
    c2 = ncr(m, 2)
print(int(c1 + c2))

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=map(int,input().split())
a=(m*(m-1)+n*(n-1))//2
print(a)

Submission status: Accepted

Solution code:
from math import factorial
N,M=map(int,list(input().split(" ")))
s=0
if N>=2:
    s+=factorial(N)//(factorial(N-2)*2)
if M>=2:
    s+=factorial(M)//(factorial(M-2)*2)
print(s)

Submission status: Accepted

Solution code:
import math
n, m = input().split()
m = int(m)
n = int(n)
if n == 1 or n == 0:
	nNum = 0
else:
	nNum = math.factorial(n) / (math.factorial(n-2) * math.factorial(2))
if m == 1 or m == 0:
	mNum = 0
else:
	mNum = math.factorial(m) / (math.factorial(m-2) * math.factorial(2))
print(int(mNum + nNum))

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())

L=0
    
for n in range(N):
    L+=n
    
    
for m in range(M):
    L+=m
    
print(L)

Submission status: Accepted

Solution code:
import itertools
r = 2
N, M = map(int, input().split())
Nmath = len(list(itertools.combinations(range(N), r)))
Mmath = len(list(itertools.combinations(range(M), r)))

print(int(Nmath+Mmath))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
even = 0
if n >= 2:
    for i in range(1, n):
        even += i
if m >= 2:
    for i in range(1, m):
        even += i

print(even)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

from decimal import *

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	N,M = inputMap()

	if N < 2 and M < 2:
		print(0)
		sys.exit()

	ans = 0
	if N > 1:
		ans += cmb(N, 2)
	if M > 1:
		ans += cmb(M, 2)

	print(ans)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
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

def int_sqrt2(n):
    def f(prev):
        while True:
            m = (prev + n / prev) / 2
            if m >= prev:
                return prev
            prev = m

    return f(int(math.sqrt(n) * (1 + 1e-10)))

# nCr mod m
# rがn/2に近いと非常に重くなる
def combination(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

# mを法とするaの乗法的逆元
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# nHr mod m
# 問題によって、combination()を切り替えること
def H(n, r, mod=10**9+7):
	# comb = Combination(n+r-1, mod)
	# return comb(n+r-1, r)
    return combination(n+r-1, r, mod)

class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.misc import comb
gusu, kisu = input().split()
gusu = int(gusu) # 個数
kisu = int(kisu) # 個数
gusu_num = comb(gusu, 2, exact=True)
kisu_num = comb(kisu, 2, exact=True)
print(gusu_num + kisu_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

# スペース区切りの整数の入力
b, c = map(int, input().split())
# 文字列の入力
def combinations_count(n, r):
    return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

print(int(combinations_count(b+c, 2)-b*c))

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
ans_ki = 0
ans_gu = 0
# 奇数奇数
if M > 1:
    ans_ki = (math.factorial(M) / (2 * math.factorial(M - 2)))
else:
    pass
# 偶数偶数
if N > 1:
    ans_gu = (math.factorial(N) / (2 * math.factorial(N - 2)))
else:
    pass
ans = round(ans_ki + ans_gu)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def main():
    N, M = [int(i) for i in input().split()]

    result = 0
    if N >= 2:
        c = math.factorial(N) // (math.factorial(2) * math.factorial(N - 2))
        result += c
    if M >= 2:
        c = math.factorial(M) // (math.factorial(2) * math.factorial(M - 2))
        result += c
    print(result)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = []
b = []
if M == 0:
    for i in range(1,(2*N)+1):
        if i%2==0 and i>0:
            a.append(i)
elif N == 0:
    for i in range(1,(2*M)+1):
        if i%2==1:
            b.append(i)
else:
    for i in range(1,501):
        if i%2==0 and i>0:
            a.append(i)
        else:
            b.append(i)
c = a[:N] + b[:M]
l = []
num = 1
for i in range(len(c)-1):
    for j in range(num,len(c)):
        res = c[i] + c[j]
        l.append(res)
    num+=1

k=[i for i in l if i%2==0]
print(len(k))

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 m >= 2:
    odd = combinations_count(m, 2)
elif m == 0 or m == 1:
    odd = 0

if n >= 2:
    even = combinations_count(n, 2)
elif n == 1:
    even = 1
elif n == 0:
    even = 0

answer = odd + even
if m == 1 and n == 1:
    answer = 0

print(answer)

Submission status: Accepted

Solution code:
from itertools import combinations

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

a = len(list(combinations(range(n+m),2)))

if (n == 2 and m == 0) or (n == 0 and m == 2):
    print(2)
    exit()

else:
    print(a-(n*m))

Submission status: Accepted

Solution code:

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

resn=n*(n-1)/2
resm=m*(m-1)/2

print(int(resn+resm))

Submission status: Accepted

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

Submission status: Accepted

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

def comb(n, r):
    res = 1
    for i in range(n-r+1, n+1):
        res *= i
    for i in range(2, r+1):
        res /= i
    return res

nn = comb(N, 2)
mm = comb(M, 2)

ans = int(nn + mm)

print(ans)

Submission status: Accepted

Solution code:
def combinations_count(n, r):
    if n >= r:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0
        
import math

a,b = map(int,input().split())

print(combinations_count(a,2) + combinations_count(b,2))

Submission status: Accepted

Solution code:
import math


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


N, M = map(int, input().split())
if M < 2 and N < 2:
    Count = 0
elif M < 2:
    Count = comb(N, 2)
elif N < 2:
    Count = comb(M, 2)
else:
    Count = comb(N, 2) + comb(M, 2)
print(Count)

Submission status: Accepted

Solution code:
from math import factorial

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

def comb2(n):
    if n > 1:
        return factorial(n) // factorial(2) // factorial(n - 2)
    else:
        return 0
    
s = 0    
for i in [N, M]:
    s += comb2(i)

print(s)

Submission status: Accepted

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

if n - 2 < 0:
    a = 0
else:
    a = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
if m - 2 < 0:
    b = 0
else:
    b = math.factorial(m) // (math.factorial(m - 2) * math.factorial(2))
print(a + b)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
s, o, ans = 0, 1, 0
se = []
if 0 <= n <= 100 and 0<= m <= 100 and 2 <= n+m:
    for i in range(1, n+1):
        se.append(s)
        s += 2
    for i in range(1, m+1):
        se.append(o)
        o += 2
    for x in se:
        for y in range(len(se)):
            if (x + se[y]) % 2 == 0 and x!=se[y]:
                ans += 1 
    print(int(ans/2))

Submission status: Accepted

Solution code:
import copy
import math
import collections
def comb(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
#A

N, M = list(map(int, input().split()))
a, b = 0, 0
if N >= 2:
    a = comb(N, 2)
if M >= 2:
    b = comb(M, 2)
ans = a + b
print(ans)

Submission status: Accepted

Solution code:
import sys
import itertools

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

if (N<0 or 100<N ):
    sys.exit()
if ( M<0 or 100<M ):
    sys.exit() 
if ( N+M<2 ):
    sys.exit()

even = list(itertools.combinations(range(N),2))
odd  = list(itertools.combinations(range(M),2))

print (len(even) + len(odd))

Submission status: Accepted

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

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

if a < 2 and b < 2:
    print(0)

if a < 2 and b >= 2:
    print((b * (b + 1))//2 -b)

if a >= 2 and b < 2:
    print((a * (a + 1))//2 -a)

Submission status: Accepted

Solution code:
import sys
X,Y = map(int,input().split())
if(X == 1 and Y == 1):
    print(0)
    sys.exit()
elif(Y == 1):
    print(int(X/2))
    sys.exit()
elif(X == 0 and Y ==2):
    print(1)
    sys.exit()
print(int((X * (X-1))/2 + int((Y * (Y-1))/2 )))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math

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

if(N==2) :
  n = 1
elif(N<=1) :
  n = 0
else :
  n = math.factorial(N) // ( math.factorial(2) * math.factorial(N - 2) )
  
if(M==2) :
  m = 1
elif(M<=1) :
  m = 0
else :
  m = math.factorial(M) // ( math.factorial(2) * math.factorial(M - 2) )

print(n + m)

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 = [int(i) for i in input().rstrip().split(' ')]
_r = math.factorial(2)
patternN = 0
patternM = 0

if N > 1:
    # even(偶数)
    _N = math.factorial(N)
    even = math.factorial(N-2)
    patternN = int(_N / even / _r)

if M > 1:
    # odd(奇数)
    _M = math.factorial(M)
    odd = math.factorial(M-2)
    patternM = int(_M / odd / _r)

print(patternN + patternM)

Submission status: Accepted

Solution code:
nm = [int(i) for i in input().split()]

result = (nm[0] * (nm[0] - 1)) // 2
result += (nm[1] * (nm[1] - 1)) // 2

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 入力
N, M = map(int, input().split())
# 演算
cnt = 0
l = list(range(0, N*2, 2)) + list(range(1, M*2, 2))
for i, n in enumerate(l):
  for m in l[i+1::]:
    if (n + m) % 2 == 0:
      cnt += 1
# 出力
print(cnt)

Submission status: Accepted

Solution code:
from math import *


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

Submission status: Accepted

Solution code:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''


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

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

print(a*(a-1)//2 + b*(b-1)//2)

Submission status: Accepted

Solution code:
import math
e,o = map(int,input().split())
if e < 2:
    e_cases = 0
else:
    e_cases = math.factorial(e)/math.factorial(e-2)/2
if o < 2:
    o_cases = 0
else:
    o_cases = math.factorial(o)/math.factorial(o-2)/2
print(int(e_cases+o_cases))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import factorial
n,m = map(int,input().split())

if n == 0:
   N = 0
elif n == 1:
    N = 0
else:
    N = factorial(n)/factorial(2)/factorial(n-2)
if m == 0:
   M = 0
elif m == 1:
    M = 0
else:
    M = factorial(m)/factorial(2)/factorial(m-2)

print(int(N+M))

Submission status: Accepted

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

def fact(num):
    result = 1
    while num > 1:
        result *= num
        num -= 1
    return result

if M!=0 or M!=1:
    result += fact(M) // (fact(2) * fact(M-2))

if N!=0 or N!=1:
    result += fact(N) // (fact(2) * fact(N-2))

print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def binom(n,r):
    if n<r or n<0:
        return 0

    result=1
    for i in range(r):
        result*=(n-i)
        result//=(i+1)
    return result

inputs=[int(c) for c in input().split()]
n=inputs[0]
m=inputs[1]
print(binom(n,2)+binom(m,2))

Submission status: Accepted

Solution code:
print(sum(list(map(lambda x:int((float(x)-0.5)**2),input().split())))//2)

Submission status: Accepted

Solution code:
N, M = input().strip().split()
N, M = [int(N), int(M)]


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

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    n -= 1
    m -= 1
    e = 0
    while n > 0:
        e += n
        n -= 1
    while m > 0:
        e += m
        m -= 1
    print(e)
 
main()

Submission status: Accepted

Solution code:
def total(x):
	if x == 1:
		return 0
	else:
		x = x - 1
		return (x * (x + 1))/2
ln = list(map(int, input().split(" ")))
print(int(total(ln[0]) + total(ln[1])))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
n = n * (n - 1) // 2 # 偶数は偶数とペア
m = m * (m - 1) // 2 # 奇数は奇数とペア
print(n + m)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
d=a*(a-1)//2
e=b*(b-1)//2
while d>0:
  d=d-1
  c=c+1
while e>0:
  e=e-1
  c=c+1
print(c)

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:
import math

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

def calculation(number):
    factorial = math.factorial(number)
    combination = factorial/math.factorial(number-2)
    result = math.floor(combination/2)
    return result

if m == 1 or m == 0:
    if n == 1 or n == 0:
        print("0")
    else:
        print("{}".format(calculation(n)))
else:
    if n == 1 or n == 0:
        print("{}".format(calculation(m)))
    else:
        print("{}".format(calculation(n)+calculation(m)))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    arr = list(map(int,input().rstrip().split()))
    cou = 0
    cou_n = 0
    cou_m = 0
    i =1
    j    =1
    N = arr[0]
    M = arr[1]
    n =[]
    m = []
    while cou_n  != N:
        if i % 2 == 0:
            n.append(i)
            cou_n += 1
        i += 1

    while cou_m != M:
        if j % 2 != 0 :
            m.append(j)
            cou_m +=1
        j += 1
    f = n + m
# print(n)
# print(m)
    f.sort()

#start permutation
    for i in range(len(f)):
        for j in range(i+1,len(f)):
            if ((f[i] + f [j]) % 2) == 0:
                cou +=1
    print(cou)