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
N, M = (int(x) for x in input().split(' '))

# 要するに、N個の中から2個＋M個の中から2個なので其れを計算する。
# 「n個からm個を選択する数」は「nCr」で計算する。
if N < 2:
  k = 0
else:
  k = math.factorial(N) / (math.factorial(N-2) * 2 )

if M < 2:
  g = 0
else:
  g = math.factorial(M) / (math.factorial(M-2) * 2 )

#出力
print(int(k+g))

Submission status: Accepted

Solution code:
from scipy.misc import comb
import numpy as np
A,B=map(int,input().split())
print(int(np.round(comb(A,2))+np.round(comb(B,2))))

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:
a,b = [int(x) for x in input().split()]
print((a*a+b*b-a-b)//2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from scipy.misc import comb

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

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

answer = 0
if N >= 2:
    answer += combinations_count(N, 2)
if M >= 2:
    answer += combinations_count(M, 2)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import *
from math import *
from collections import deque
input = stdin.readline
lmi = lambda: list(map(float, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n, m = mi()
print(n*(n-1)//2 + m*(m-1)//2)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
ans_a=0
ans_b=0
for i in range(a):
    ans_a+=i
for i in range(b):
    ans_b+=i
print(ans_a+ans_b)

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

Submission status: Accepted

Solution code:
N,M=(int(x) for x in input().split())
if not 0 <= N <= 100:
    print('N is not appropreate')
elif not 0 <= M <= 100:
    print('M is not appropreate')
elif N+M < 2:
    print('num of ball is too small')
else:
    print(int((N*(N-1)+M*(M-1))/2))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
print(n*(n-1)//2+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())
answer = int(N*(N-1)/2 + M*(M-1)/2)
print(answer)

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
rs=0
if(n>2):
    for i in range(1,n+1):
        for e in range(i+1,n+1):
            rs+=1
if(n==2):rs+=1
if(m>2):
    for i in range(1,m+1):
        for e in range(i+1,m+1):
            rs+=1
if(m==2):rs+=1
print(rs)

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    print(n*(n-1)//2+m*(m-1)//2)
    #arr=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

Solution code:
I = input().split()

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

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

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

Submission status: Accepted

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

    sum_eve = (a * (a-1))/2
    sum_odd = (b * (b-1))/2

    print(int(sum_eve + sum_odd))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#ABC159A
import sys
import itertools
n, m = map(int, sys.stdin.readline().split())
#print(n, m)
L = [0 for _ in range(n)] + [1 for _ in range(m)]
L = list(itertools.combinations(L, 2))
#print(L)
total = 0
for a, b in L:
    if (a+b)%2 ==0:
        total+=1

print(total)

Submission status: Accepted

Solution code:
#ABC159A
import sys
n, m = map(int, sys.stdin.readline().split())
#print(n, m)

print(n*(n-1)//2 + m*(m-1)//2) #偶偶or 奇奇

Submission status: Accepted

Solution code:
GI = lambda: int(input()); GIS = lambda: map(int, input().split()); LGIS = lambda: list(GIS())

def main():
    N, M = GIS()
    print(int(N * (N - 1) / 2 + M * (M - 1) / 2))

main()

Submission status: Accepted

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

def n_c_2(n):
    if n < 2:
        return 0
    else:
        return n * (n - 1) // 2

print(n_c_2(N) + n_c_2(M))

Submission status: Accepted

Solution code:
def check(a, b):
  return((a+b)%2==0)
n, m = map(int, input().split())
x=sorted(list(range(1, 2*m+1, 2)) + list(range(2, 2*n+1, 2)))
c=0
for i in range(len(x)):
  for j in range(i+1, len(x)):
    if check(x[i], x[j]):
      c+=1
print(c)

Submission status: Accepted

Solution code:
# coding: utf-8

# 標準入力 <int><int>
N, M = map(int, input().split())

ans = 0

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

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

print(int(ans))

Submission status: Accepted

Solution code:
from scipy.misc import comb

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


ans = comb(N,2,exact=True) + comb(M,2,exact=True) #exact=Trueで整数値が返される
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


def P(n, r):
    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())
ans = 0
if N >= 2:
    ans += C(N, 2)
if M >= 2:
    ans += C(M, 2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(C1 + C2)

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env/ python3
#S = input()
#N = int(input())
#A, B, C = input().split()
N, M = map(int, input().split())

#N = int(input())
#A = [int(x) for x in input().split()]

#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(S[0][1])

ans = 0
if N > 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(" ")]
ans = (n*(n-1)//2) + (m*(m-1)//2)
print (ans)

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())
ans=(n*(n-1))//2
ans+=(m*(m-1))//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import numpy as np

A = np.asarray(range(max(1, N)))
B = np.asarray(range(max(1, M)))
A = A.cumsum()
B = B.cumsum()

print(A[-1] + B[-1])

Submission status: Accepted

Solution code:
import sys

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

def com(n,r):
    ans1 = 1
    ans2 = 1
    tmp = r
    while r != 0:
        ans1 = ans1 * (n)
        ans2 = ans2 * r
        n -= 1
        r -= 1

    return ans1/ans2

print(int(com(N,2)+com(M,2)))

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    a,b=INTM()
    aa=a*(a-1)/2
    bb=b*(b-1)/2
    print(int(aa+bb))
if __name__ == '__main__':
    do()

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:
N = list(map(int, input().split()))
ans = 0
for i in range(2):
  if N[i] != 0:
    ans += N[i]*(N[i]-1)//2

print(ans)

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().rstrip().split()]


def nCk(N,K):
    c,p = 1,1
    for k in range(1,K+1):
        c *= (N - k + 1)
        p *= k
    return c//p

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]

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

print(int(a+b))

Submission status: Accepted

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,M=MI()
    ans=(N*(N-1))//2+(M*(M-1))//2
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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

for i in itertools.combinations(n*[2] + m*[1], 2):
    if sum(i) % 2 == 0:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

def f(n):
    sum = 0
    for i in range(n):
        sum += i
    return sum

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

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))
print(comb(n + m, 2) - n * m)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if n==0:
    n2=0
else:
    n2=n-1

if m==0:
    m2=0
else:
    m2=m-1

print(int(n*n2/2+m*m2/2))

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:
# A = [list(map(int, input().split())) for _ in range(3)]
# k = int(input())
# B = [int(input()) for _ in range(n)]
# X = list(map(int, input().split()))
import math
a, b = map(int, input().split())


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


if a < 2 and 2 <= b:
    print(combinations_count(b, 2))
elif 2 <= a and b < 2:
    print(combinations_count(a, 2))
elif a < 2 and b < 2:
    print(0)
else:
    print(combinations_count(a, 2)+combinations_count(b, 2))

Submission status: Accepted

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

Submission status: Accepted

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


main()

Submission status: Accepted

Solution code:
import itertools

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

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

Submission status: Accepted

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

Submission status: Accepted

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

def func(n):
    num = 1
    if n == 0:
        return 0
    else:
        for i in range(1,n+1):
            num = num*i
        return num
def func1(n):
    if n < 1:
        return 0
    elif n == 2:
        return 1
    else:
        return int(func(n)/(2*func(n-2)))

print(func1(n)+func1(m))

Submission status: Accepted

Solution code:
def n_c_two(i):
  if i <= 1:
    return 0
  return i * (i-1) // 2

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

Submission status: Accepted

Solution code:
import itertools

odd, even = map(int, input().split(" "))
nums = [1] * odd + [2] * even
counter = 0

for x in itertools.combinations(nums, 2):
    if sum(x) % 2 == 0:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
import sys
import os
import collections

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
odd, even = map(int, input().split(" "))
odd_list = [1] * odd
even_list = [2] * even
nums = odd_list + even_list
counter = 0
for x in range(len(nums)):
    if x == len(nums) - 1:
        break
    else:
        for y in nums[x + 1:]:

            if (nums[x] + y) % 2 == 0:
                counter += 1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
count = 0
for i in range(1,N):
    for j in range(i,N):
        count += 1

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

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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:
# A
N, M = list(map(int, input().split()))


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

Submission status: Accepted

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

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

if N>=2 and M>=2:
    print(combinations_count(N, 2)+combinations_count(M, 2))
elif N>=2 or M>=2:
    print(combinations_count(N, 2)+combinations_count(M, 2)-1)
else:
    print(0)

Submission status: Accepted

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

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

if n > 1 and m > 1:
    print(combinations_count(n, 2) + combinations_count(m, 2))
elif n > 1:
    print(combinations_count(n, 2))
elif m > 1:
    print(combinations_count(m, 2))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import string
import collections
from collections import Counter


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


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


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


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())
print(int(N*(N-1)/2 + M*(M-1)/2))

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))
try :
    base = comb(N,2)
except:
    base=0
def comb2(M, r):
    return math.factorial(M) // (math.factorial(M - r) * math.factorial(r))
try:
    base2 = comb2(M,2)
except:
    base2=0

print(base+base2)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
def kaijo(a):
    start=1
    for i in range(1,a+1):
        start*=i
    return start
def comb(a,b):
    if a==0 or a==1:
        ans=0
    elif a==2:
        ans=1
    else:
        ans=kaijo(a)/(kaijo(b)*kaijo(a-b))
        #returnは一回で
    return ans
print(int(comb(M,2)+comb(N,2)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
m, n = map(int, input().split())
print((m * (m-1) + n * (n - 1)) // 2)

Submission status: Accepted

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

N,M = imn()
ans = 0
if N > 1: ans += comb_count(N,2)
if M > 1: ans += comb_count(M,2)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
import sys,bisect,string,math,time,functools,random
def Golf():*a,=map(int,open(0))
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[];g=[[] for i in range(n)]
    for i in range(E):
        inp=LI();org_inp.append(inp)
        if index==0:inp[0]-=1;inp[1]-=1
        if len(inp)==2:
            a,b=inp;g[a].append(b)
            if not Directed:g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp;aa=(inp[0],inp[2]);bb=(inp[1],inp[2]);g[a].append(bb)
            if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,boundary=1,search=[],replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,boundary=1,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def bit_combination(k,n=2):return [[tb//(n**bt)%n for bt in range(k)] for tb in range(n**k)]
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)
def show2d(g,h,w):
    for i in range(h):show(g[i*w:i*w+w])

YN=['YES','NO'];Yn=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

n,m=LI()

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

Submission status: Accepted

Solution code:
import math

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

raw = input()
n, m = [int(i) for i in raw.split(" ")]
 
print(comb(n, 2) + comb(m, 2))

Submission status: Accepted

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

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

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

nC2, mC2 = 0, 0
if N >= 2:
    nC2 = N*(N-1)/2*1

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

print(int(nC2 + mC2))

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

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

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


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

Submission status: Accepted

Solution code:
a = input().split()

m = int(a[0])
o = int(a[1])

t = (m*(m-1))/2
s = (o*(o-1))/2

print(int(t+s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b  = [int(i) for i in input().split()]
x = 0
x = a*(a-1)//2+b*(b-1)//2
print(x)

Submission status: Accepted

Solution code:
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
print(int(N*(N-1)/2+M*(M-1)/2))

Submission status: Accepted

Solution code:
def get_combi(a):
    return (a * (a - 1)) // 2

i = input().split()

m = int(i[0])
n = int(i[1])

print(get_combi(m) + get_combi(n), end='')

Submission status: Accepted

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

Submission status: Accepted

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

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:
# https://atcoder.jp/contests/abc159/tasks/abc159_a

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

count += M * (M - 1)
count += N * (N - 1)

print(count // 2)

Submission status: Accepted

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

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 1って書かれたM個と2って書かれたN個があるよって感じのncr
# 「N+M個のうちM個のうち2個」だとわけがわからんので別の方法を考える。
# 全体から奇数になるやつを引けばいいかもしれない ncr(N+M,2)-ncr(N, 1)-ncr(M, 1) = ncr(N+M, 2)-(N*M)

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


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


print(ncr(n + m, 2) - n * m)

Submission status: Accepted

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

s = 0
for i in range(n):
  s += i
for i in range(m):
  s += i
print(s)

Submission status: Accepted

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

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

print(ans)

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

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

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

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

print(cnt)

Submission status: Accepted

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

result = int(total - odd)
print(result)

Submission status: Accepted

Solution code:
A=input()
L=A.split()

B=(int(L[0]))*(int(int(L[0])-1))/2
      
C=(int(L[1]))*(int(int(L[1])-1))/2
      
print(int(B+C))

Submission status: Accepted

Solution code:
A=input()
L=A.split()

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

x=1
for n in range(N-1,N+1):
  x*=n
x /= 2
  
y=1
for m in range(M-1,M+1):
  y*=m
y /= 2

print(int(x+y))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n, m = map(int, input().split())

# 出力
print(int(n*(n-1)/2+m*(m-1)/2))

Submission status: Accepted

Solution code:
def f(x):
    if x > 0:
        return x * (x-1) // 2
    else:
        return 0

def solve(n, m):
    return f(n) + f(m)

assert solve(2, 1) == 1
assert solve(4, 3) == 9
assert solve(1, 1) == 0

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

    ans = 0

    n_list = [i+1 for i in range(n)]
    m_list = [i+1 for i in range(m)]

    ans += len(list(combinations(n_list, 2)))
    ans += len(list(combinations(m_list, 2)))

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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