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:
n, m = map(int, input().split())

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

print(int(ans))

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 n <= 1:
    comb_e = 0
else:
    comb_e = comb(n, 2)
if m <= 1:
    comb_o = 0
else:
    comb_o = comb(m, 2)
ans = comb_e + comb_o
print(ans)

Submission status: Accepted

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

ansn = 0
ansm = 0
if n > 1 :
  ansn = (n * (n-1)) //2
if m > 1 :
  ansm = (m * (m-1)) //2

print(ansn + ansm)

Submission status: Accepted

Solution code:
import math

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

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

a = combinations_count(n, 2)
b = combinations_count(m, 2)

print(a+b)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
if True:
    n,m = map(int, input().split())


else:
    #偶数
    n=0
    #奇数
    m=3

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

print(int(ans))

Submission status: Accepted

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

if n == 1 :
  n == 0
if m == 1:
  m == 0
ans_n = n * (n-1) / 2
ans_m = m * (m-1) / 2
ans = int(ans_n + ans_m)
print(ans)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


n, m = MAP()

ans = 0

for x in range(0, n ):
    ans += x
for x in range(0, m ):
    ans += x

print(ans)

Submission status: Accepted

Solution code:

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

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

if n==0:
    print(combinations_count(m, 2))
elif m == 0:
        print(combinations_count(n, 2))
elif n==1 and m ==1:
    print(0)
elif n==1:
    print(combinations_count(m, 2))

elif m==1:
    print(combinations_count(n, 2))

else:
    print(combinations_count(n, 2)+combinations_count(m, 2))

Submission status: Accepted

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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

total = 0
for ni in range(1, n):
    if n <= 1:
        break
    total += ni

for mi in range(1, m):
    if m <= 1:
        break
    total += mi

print(total)

Submission status: Accepted

Solution code:
import math

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


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

c = combinations_count(n, 2)
c += combinations_count(m, 2)

print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from math import factorial
n, m = map(int, input().split())
if n < 2:
    if m < 2:
        print(0)
    else:
        ans = factorial(m) / factorial(2) / factorial(m - 2)
        print(int(ans))
else:
    if m < 2:
        ans = factorial(n) / factorial(2) / factorial(n - 2)
        print(int(ans))
    else:
        ans = factorial(n) / factorial(2) / factorial(n - 2) + factorial(m) / factorial(2) / factorial(m - 2)
        print(int(ans))

Submission status: Accepted

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

n_ans = n * (n-1) / 2
m_ans = m * (m-1) / 2

print(int(n_ans + m_ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inp = input().split(" ")
N, M = int(inp[0]), int(inp[1])
# print(N, M)

def count(number):
  if number == 1 or number == 0:
    return 0
  else:
    return number * (number - 1) / 2

print(int(count(N) + count(M)))

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
ev = a[0]
od = a[1]
if (ev<=1)and(od<=0):
  n = 0
elif ev<=1:
  n = a[1]*(a[1]-1)/2
elif od<=1:
  n = a[0]*(a[0]-1)/2
else:
  n = a[0]*(a[0]-1)/2+a[1]*(a[1]-1)/2
print(int(n))

Submission status: Accepted

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

num = 0
for i in range(N):
    for j in range(N):
        if i != j:
            num += 1
for i in range(H):
    for j in range(H):
        if i != j:
            num += 1
print(int(num/2))

Submission status: Accepted

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

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

all = [0] *n
temp = [1] *m
all.extend(temp)

count = 0
for v in itertools.combinations(all, 2):
    ans = v[0]+v[1]
    #print(ans)
    if ans%2 == 0:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
s=[]
for i in range(1,a):
    s.append(i)
x=sum(s)
t=[]
for i in range(1,b):
    t.append(i)
y=sum(t)
print(x+y)

Submission status: Accepted

Solution code:
base = input().split()
n = int(base[0])
m = int(base[1])
ansn = n*(n-1)//2
ansm = m*(m-1)//2
if n==0:
    ansn = 0
if m==0:
    ansm = 0
print(ansn+ansm)

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N,M = LI()

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

Submission status: Accepted

Solution code:
def comb2(n):
    if n < 2:
        return 0
    return int(n * (n - 1) / 2)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial
n, m = map(int, input().split())
ans = 0
if n >= 2:

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

    ans += factorial(m) // ((2) * factorial(m-2))
print(ans)

Submission status: Accepted

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

total = ((n + m) * (n + m -1)) / 2
odd = m * n
#print(n, m)
#print(total)
#print(odd)

print(int(total - odd))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int):
    import math
    def combination(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    ans = 0
    if N >= 2:
        ans += combination(N,2)
    if M >= 2:
        ans += combination(M,2)
    print(ans)
    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))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()

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:
    N_ans = 0
else:
    N_ans =combinations_count(N, 2)
if M == 1 or M == 0:
    M_ans = 0
else:
    M_ans = combinations_count(M, 2)

ans = N_ans + M_ans

print(str(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())

cnt = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if N > 0:
  A = N * (N-1) / 2
elif N ==0:
  A = 0

if M > 0:
  B = M * (M-1) / 2
elif M ==0:
  B = 0

out = int(A) + int(B)
print(out)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    a, b = list(map(int, input().split()))
    
    if a == 0 and b == 0:
        print(0)
        return
    
    if a == 0:
        ans = b * (b - 1) // 2
        print(ans)
        return

    if b == 0:
        ans = a * (a - 1) // 2
        print(ans)
        return
    
    ans = a * (a - 1) // 2
    ans += b * (b - 1) // 2
    print(ans)
    return

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())
#123
n,m=IA()
def f1(n):
    res=1
    for i in range(1,n+1):
        res*=i
    return res
def f(n):
    if n<2:return 0
    return f1(n)//(f1(n-2)*f1(2))

print(f(n)+f(m))

Submission status: Accepted

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

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 = list(map(int, input().split()))

ans = 0

for i in range(N):
        ans = i + ans 

for j in range(M):
        ans = j + ans 

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
total = (M**2 -M)/2 + (N**2 -N)/2
print(int(total))

Submission status: Accepted

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

if N>0 and M>0:
    a=N*(N-1)/2
    b=M*(M-1)/2
    print(int(a+b))
    
elif N>0 and M==0:
    a=N*(N-1)/2
    print(int(a))

elif N==0 and M>0:
    b=M*(M-1)/2
    print(int(b))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, m = list(map(int, readline().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
line = input().rstrip().split(' ')
n = int(line[0])
m = int(line[1])

ans = n * (n - 1) / 2

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
def comb(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n)/math.factorial(n-r)/math.factorial(r)
def solve(N: int, M: int):
    print(int(comb(N, 2) + comb(M, 2)))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import factorial

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

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

print(kazu)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
if a[0]==1:
  n=0
else:
  n=a[0]*(a[0]-1)/2

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

Submission status: Accepted

Solution code:
import itertools
N,M=list(map(int,input().split()))
l=[]
t=1
for i in range(N):
   l.append(t)
   t+=2
t=2
for i in range(M):
   l.append(t)
   t+=2
count=0
for v in itertools.combinations(l,2):
    #print(v[0],v[1])
    if (v[0]+v[1])%2==0:
        count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

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

ans = 0

if n >= 2:
    ans = ans + cmb(n, 2)

if m >= 2:
    ans = ans + cmb(m, 2)
    
print(ans)

Submission status: Accepted

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

x=l[0]*(l[0]-1)/2+l[1]*(l[1]-1)/2
print(round(x))

Submission status: Accepted

Solution code:
from sys import stdin
import math
import fractions

n, m = [int(x) for x in stdin.readline().rstrip().split()]

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

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:
inp = list(map(int, input().split()))
n = inp[0]
m = inp[1]

g = n * (n - 1) / 2
k = m * (m - 1) / 2

print(int(g + k))

Submission status: Accepted

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

    Nlist = [0] * N
    Mlist = [1] * M

    Nlist.extend(Mlist)

    count = 0
    for i in range(0, len(Nlist)):
        for j in range(i+1, len(Nlist)):
            if (Nlist[i] + Nlist[j]) % 2 == 0:
                count += 1

    print(count)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

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

ans = 0
ans_n = 0
ans_m = 0

if 1 < n :
    ans_n = combinations_count(n, 2)

if 1 < m :
    ans_m = combinations_count(m, 2)

ans = ans_n + ans_m

print(ans)

Submission status: Accepted

Solution code:
import itertools

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

even = [i for i in range(10**3) if i % 2 == 0]
odd =  [i for i in range(10**3) if i % 2 != 0]
lst = even[:N]+odd[:M]
count=0
for i in itertools.combinations(lst,2):
    if sum(list(i)) % 2 == 0:
        count+=1
print(count)

Submission status: Accepted

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

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ll = 0
if n > 1:
  ll = comb(n, 2)
rr = 0
if m > 1:
  rr = comb(m, 2)
print(ll + rr)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
from operator import itemgetter
from sys import stdin
#input = sys.stdin.readline#こっちの方が入力が早いが使える時に使っていこう
from math import factorial
N=3
M=3
i=0
j=0
k=0

number_list=list(map(int, input().split(" ")))
N=number_list[0]
M=number_list[1]
#print(N,M)
if N >=2:
    i=factorial(N) / factorial(2) /factorial(N-2)
else:
    i=0

if M>=2:
    j=factorial(M) / factorial(2) /factorial(M-2)
else:
    j=0
print(int(i+j))
#N=int(input())
#A=int(input())
#B=int(input())
#print(N)
"1行1つの整数を入力を取得し、整数と取得する"


#number_list=list(map(int, input().split(" ")))#数字の時
#print(number_list)
"12 21 332 とか入力する時に使う"
"1行に複数の整数の入力を取得し、整数として扱う"

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#メモ
for i in number_list:#こっちの方がrage使うより早いらしい
    print(number_list[i-1])

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'''
x=[]
y=[]
for i in range(N):
    x1, y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
print(x)
print(y)
"複数行に2数値を入力する形式 x座標とy座標を入力するイメージ"
'''

'''
mixlist=[]
for i in range(N):
    a,b=input().split()
    mixlist.append((int(a),b))
print(mixlist)
"複数行にintとstrを複合して入力するやつ，今回はリスト一つで処理している"
'''

'''
#array=[input().split()for i in range(N)]
#print(type(array[0][0]))
#print(array)
"正方行列にstr型の値を入力"
'''

#brray=[list(map(int, input().split(" ")))for i in range(N)]
#print(type(brray[0][0]))
#print(brray)
'''
入力
1 2
4 5
7 8
出力結果
[[1, 2], [4, 5], [7, 8]]
'''
"列数に関して自由度の高いint型の値を入力するタイプの行列"
#以下に別解を記載
#N, M = [int(i) for i in input().split()]
'''
table = [[int(i) for i in input().split()] for m in range(m)]

print(type(N))
print(N)
print(type(M))
print(M)

print(type(table))
print(table)
'''




#s=input()
#a=[int(i) for i in s]
#print(a[0])
#print([a])
#単数値．桁ごとに分割したい．入力と出力は以下の通り
#イメージとして1桁ごとにリストに値を入れているかんじ

'''
入力
1234
出力
1
[[1, 2, 3, 4]]
'''




'''
word_list= input().split(" ")
print(word_list[0])
"連続文字列の入力"
"qw er ty とかの入力に使う"
"入力すると空白で区切ったところでlistの番号が与えられる"
'''



'''
A, B, C=stdin.readline().rstrip().split()#何個でもいけることが多い
print(A)
"リストではなく独立したstr型を入れるなら以下のやり方でOK"
'''


#a= stdin.readline().rstrip()
#print(a.upper())
"aという変数に入っているものを大文字にして出力"




#なんかうまく入力されるけど
#a=[[int(i) for i in 1.strip()]for 1 in sys.stdin]
#a = [[int(c) for c in l.strip()] for l in sys.stdin]]
#print(a)
#複数行の数値を入力して正方行列を作成

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:
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 20:55:28 2020

@author: naoki
"""

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

option = 0
if N>1:
    #print(list(itertools.combinations(range(N), 2)))
    option += len(list(itertools.combinations(range(N), 2)))
if M>1:
    option += len(list(itertools.combinations(range(M), 2)))
print(option)

Submission status: Accepted

Solution code:
import math
def comp(n, r):

    return math.factorial(n) // (math.factorial(abs(n-r))*math.factorial(r))
n, m = map(int, input().split())
print(comp(n, 2) + comp(m, 2))

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N,M = LI()
if N <= 1:
    n = 0
else:
    n = math.factorial(N)//((math.factorial(N-2))*(math.factorial(2)))
if M <= 1:
    m = 0
else:
    m = math.factorial(M)//((math.factorial(M-2))*(math.factorial(2)))
print(n+m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from sys import stdin


def get_result(data):
    N, M = data
    ans = N * (N-1) / 2 + M * (M-1) / 2 
    return int(ans)


if __name__ == '__main__':
    data = list(map(int, stdin.readline().split(' ')))
    result = get_result(data)
    print(result)

Submission status: Accepted

Solution code:
# N：偶数 M：奇数
N,M = map(int,input().split())
a = 0
b = 0
for i in range(N):
    a += i

for i in range(M):
    b += i

print(a+b)

Submission status: Accepted

Solution code:
import itertools


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

if n >= 2:
    ans1 = len(list(itertools.combinations(range(n), 2)))
else:
    ans1 = 0

if m >= 2:
    ans2 = len(list(itertools.combinations(range(m), 2)))
else:
    ans2 = 0
print(int(ans1 + ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k=map(int,input().split())
def cmb(n, r):
    if n<2:
        return 0
    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
print(cmb(n,2)+cmb(k,2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  n, m = input_list()
  if n < 2:
    nk = 0
  else:
    nk = combinations_count(n, 2)
  if m < 2:
    mk = 0
  else:
    mk = combinations_count(m, 2)
  print(nk+mk)
  
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

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

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

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce
main()

Submission status: Accepted

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

Submission status: Accepted

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

nc2 = n*(n-1)/2 
mc2 = m*(m-1)/2

if n == 1 or n == 0:
    nc2 = 0
if m == 1 or m == 0:
    mc2 = 0
print(int(nc2+mc2))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
base = comb(5,3)
m, n = map(int, input().split())
if m > 1 and n > 1:
    ans = comb(n, 2) + comb(m, 2)
elif n > 1:
    ans = comb(n, 2) 
elif m > 1:
    ans = comb(m, 2)
else:
    ans = 0
print(ans)

Submission status: Accepted

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

a, b = MAP()

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def combination(n, m):
    perm = 1
    dup = 1
    for i in range(m):
        perm *= (n-i)
        dup *= (m-i)
    return perm // dup
    

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

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

Submission status: Accepted

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

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:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

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

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
def fact(n):
  if n < 2: return 1
  return n*fact(n-1)

def nc2(n):
  if n < 2: return 0
  return fact(n)//(fact(n-2)*2)

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

Submission status: Accepted

Solution code:
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 >= 2 and m >= 2:
     print(cmb(n,2) + cmb(m,2))
if n < 2 and m < 2:
    print(0)
if n < 2 and m >= 2:
    print(cmb(m, 2))
if n >= 2 and m < 2:
    print(cmb(n, 2))

Submission status: Accepted

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

mysum = 0

if N >= 2:
    mysum += (N*(N-1))//2
if M >=2 :
    mysum += (M*(M-1))//2

print(mysum)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, factorial
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

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


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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


# Returns factorial of n
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:
import math
import sys


scan = sys.stdin.readline


def comb(n, k):
    return math.factorial(n) // (math.factorial(k) * math.factorial(n - k)) if n >= k else 0


def main():
    n, m = map(int, scan().rstrip().split())

    comb_even = comb(n, 2)
    comb_odd = comb(m, 2)

    print(comb_even + comb_odd)


if __name__ == '__main__':
    main()