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())
print(sum(range(0,N))+sum(range(0,M)))

Submission status: Accepted

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

#偶数のボールをN個うけとる
#奇数のボールをM個うけとる
#N＋M個の中から２個だけボールを取り出す
#２つの和が偶数になる場合
# 偶数＋偶数
# 奇数+奇数

print(int(n * (n - 1)/2 + m *( m - 1)/2))
# 
#2 1
#4 3
#1 1
#13 3
#0 3

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

Submission status: Accepted

Solution code:
import math

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

x,y = map(int,input().split())
if x!=0 and x!=1:
    a = combinations_count(x, 2)
else:
    a=0
if y!=0 and y!=1:
    b = combinations_count(y, 2)
else:
    b=0

print(a+b)

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

Submission status: Accepted

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

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:
a,b=map(int,input().split())
n=(a*(a-1))//2
m=(b*(b-1))//2
if b<2 and a<2:
  print(0)
elif b<2:
  print(n)
else:
  print(n+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())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# n 偶数 m 奇数
n, m = list(map(int, input().split()))
n1=0
m1=0
# 2つ選んで偶数になる　奇数＋奇数　もしくは　偶数＋偶数

if n >= 2:
    n1 = (n * (n-1))//2

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

print(n1 + m1)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
gusu,kisu=map(int,input().split())
count=0
S=[]
for i in range(gusu):
    S.append(2)
for i in range(kisu):
    S.append(1)

for i in range(len(S)):
    for j in range(len(S)):
        if i!=j and i>j:
            if (S[i]+S[j])%2==0:
                count+=1

print(count)

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

def factorial(n):
    v = 1
    for i in range(1, n + 1):
        v *= i
    return v

def comb(a, b):
    return factorial(a) // (factorial(b) * factorial(a - b))

if (n < 2) & (m < 2):
    print('0')
elif n < 2:
    print(comb(m, 2))
elif m < 2:
    print(comb(n, 2))
else:
    print(comb(n, 2) + comb(m, 2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#A
n,m=map(int,input().split())
if n<=1:
    n_ans=0
else:
    n_ans=n*(n-1)/2

if m<=1:
    m_ans=0
else:
    m_ans=m*(m-1)/2
    

print(int(n_ans+m_ans))

Submission status: Accepted

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

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

print(pairs)

Submission status: Accepted

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


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


if __name__ == '__main__':
    solve()

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())
a = 0
n = n - 1
m = m - 1

while n > 0:
    a = a + n
    n = n - 1

while m > 0:
    a = a + m
    m = m - 1

print(a)

Submission status: Accepted

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

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

if (N==0 or N==1) and (M==0 or M==1):
  print(0)
elif (N==0 or N==1) and (M!=0 and M!=1):
  print(int(math.factorial(M)/math.factorial(M-2)/math.factorial(2)))
elif (M==0 or M==1) and (N!=0 and N!=1):
  print(int(math.factorial(N)/math.factorial(N-2)/math.factorial(2)))
else:
  print(int(math.factorial(N)/math.factorial(N-2)/math.factorial(2)+math.factorial(M)/math.factorial(M-2)/math.factorial(2)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, y = map(int, input().split())

x_sum = x*(x-1)//2
y_sum = y*(y-1)//2
print(x_sum+y_sum )

Submission status: Accepted

Solution code:
import itertools


n_even, n_odd = map(int, input().split())

# nC2 なので、combinations使わなくてもいいと思う
count1 = n_even * (n_even - 1) // 2
count2 = n_odd * (n_odd - 1) // 2

print(count1 + count2)

# itertools.combinations を使ってもOK
count1 = len(list(itertools.combinations(range(n_even), r=2)))
count2 = len(list(itertools.combinations(range(n_odd), r=2)))

Submission status: Accepted

Solution code:
import itertools


n_even, n_odd = map(int, input().split())

# 偶数になるのは、(偶数+偶数) と (奇数+奇数)
count1 = len(list(itertools.combinations(range(n_even), r=2)))
count2 = len(list(itertools.combinations(range(n_odd), r=2)))

print(count1 + count2)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# kCa = k(k-1)/a もっとデカくなるとk(k-1)(k-2)(k-3)/a/(a-1)(a-2)
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:
n,m=map(int,input().split());print((n*(n-1)+m*(m-1))//2)

Submission status: Accepted

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

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

print(int(p))

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:
def combination(n):
    return n * (n-1) // 2

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

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

def cmb(n,r):
    #n<10^4で最速s
    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 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n>=2:print(cmb(n,2))
elif m>=2:print(cmb(m,2))
else:print(0)

Submission status: Accepted

Solution code:
a = input().split()
b = int(a[0])
c = int(a[1])
if b == 1 and c == 1:
    print(0)
elif b>=2 and c>=2:
    d = b-1
    e = c-1
    f = b*d/2
    g = c*e/2
    print(int(f+g))
elif b<=1 and c>=2:
    d = c-1
    f = c*d/2
    print(int(f))
elif b>=2 and c<=1:
    d = b-1
    f = b*d/2
    print(int(f))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)


def solve(N: int, M: int):
    ret = 0
    if N > 1:
        ret += N * (N - 1) // 2
    if M > 1:
        ret += M * (M - 1) // 2
    print(ret)
    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:
n,m=map(int,input().split())
print(int((n*(n-1)+(m*(m-1)))/2))

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:
print(sum(map(lambda i: int(i)*(int(i)-1)//2, input().split())))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def comb(x,y):
    return math.factorial(x)//(math.factorial(x-y)*math.factorial(y))
n,m = map(int,input().split())

ans1=0
ans2=0
if n > 1:
    ans1=comb(n,2)
if m > 1:
    ans2=comb(m,2)
print(ans1+ans2)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

num_of_even, num_of_odd = map(int, input().split())

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

if num_of_even == 1 and num_of_odd == 1:
    print('0')
else:
    print(combinations_count(num_of_odd, 2) + combinations_count(num_of_even, 2))

Submission status: Accepted

Solution code:
g, k = map(int, input().split())

a = g * (g - 1) / 2
b = k * (k - 1) /2

print(int(a + b))

Submission status: Accepted

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

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

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

ans = 0

for n in nm:
    ans += (n * (n - 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:
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 combinations_count(a, b):
    return math.factorial(a+b) // (2 * math.factorial(a+b-2))

print(combinations_count(n, m)-(n*m))

Submission status: Accepted

Solution code:
from itertools import combinations
n,m = map(int,input().split())
ki = n*m
a = len(list(combinations(range(n+m),2)))
print(a-ki)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

    ans1 = math.factorial(n) // (math.factorial(n-2) * 2) if n > 1 else 0
    ans2 = math.factorial(m) // (math.factorial(m-2) * 2) if m > 1 else 0
    print(ans1 + ans2)
resolve()

Submission status: Accepted

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

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

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

print(int(a + b))

Submission status: Accepted

Solution code:
from scipy.misc import comb
print(int(sum(comb(list(map(int,input().split())),2, exact = False))+0.5))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans // 2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def decSum(x):
    sum = 0
    for i in range(x):
        sum += i
    return sum


combined = input().split(" ")
even = int(combined[0])
odd = int(combined[1])

print(decSum(even) + decSum(odd))

Submission status: Accepted

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

Even = [ i for i in range(N)] 
Odd = [ j for j in range(M)]

print(sum(Odd) + sum(Even))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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

if N == 1:
    c1 = 0
else:
    c1 = len(list(itertools.combinations(range(N), 2)))

if M == 1:
    c2 = 0
else:
    c2 = len(list(itertools.combinations(range(M), 2)))

c3 = c1 + c2
print(c3)

Submission status: Accepted

Solution code:
n,m = list(map(int, input().split()))
# 偶数を二つ選ぶ組み合わせの数＋奇数を二つ選ぶ組み合わせの数
print(m*(m-1)//2 + n*(n-1)//2)

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:
import math
def kumiawase(n):
  a = 1
  b = 1
  for i in range(1, n+1):
    a = i * a
  for i in range(1, n - 2+1):
    b = i * b
  c = math.floor(a /(b * 2))
  return c
if __name__ == "__main__":
  x = input().split()
  n = int(x[0]) # 偶数
  m = int(x[1]) # 奇数
  a = kumiawase(n)
  b = kumiawase(m)
  print(a + b)

Submission status: Accepted

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

Submission status: Accepted

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

total = 0

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

print(total)

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:
from functools import reduce

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
ans = "No"
# pi  = math.pi

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

even = 0
for ni in range(N):
    for nj in range(ni, N):
        if ni != nj:
            even += 1

odd = 0
for mi in range(M):
    for mj in range(mi, M):
        if mi != mj:
            odd += 1

ans = even + odd

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

Submission status: Accepted

Solution code:
import math

ARGS=input().split()
N=int(ARGS[0])
M=int(ARGS[1])
R=2

COMB=0
if N >= R:
    COMB=math.factorial(N) // math.factorial(N - R) // math.factorial(R)
if M >= R:
    COMB+=math.factorial(M) // math.factorial(M - R) // math.factorial(R)

print(str(COMB))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

def inv(a): return pow(a, MOD-2, MOD)

def comb(n,r):
    ans = 1
    for i in range(r):
        ans *= n-i
        ans *= inv(r-i)
        ans %= MOD
    return ans

n,m = imap()
ans = comb(n,2) + comb(m,2)
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product#accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
def run():
    N, M = map(int, sysread().split())
    print(N*max(N-1,0)//2 + M*max(M-1, 0)//2)
if __name__ == "__main__":
    run()

Submission status: Accepted

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

M2=(M*(M-1))/2 #MC2
N2=(N*(N-1))/2
A=M2+N2
A=int(A)
print(A)

Submission status: Accepted

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

Submission status: Accepted

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

if n != 0:
    pn = (n**2 - n) // 2
else:
    pn = 0

if m != 0:
    pm = (m**2 - m) // 2
else:
    pm = 0

print(pn + pm)

Submission status: Accepted

Solution code:
# coding: utf-8
import math
gu, ki = map(int, input().split())
# 偶数+偶数と奇数+奇数の組み合わせを数える
if gu <= 1:
    sum_gu = 0
elif gu == 2:
    sum_gu = 1
else:
    sum_gu = math.factorial(gu) / (math.factorial(gu-2)*2)

if ki <= 1:
    sum_ki = 0
elif ki == 2:
    sum_ki = 1
else:
    sum_ki = math.factorial(ki) / (math.factorial(ki-2)*2)

print(int(sum_gu+sum_ki))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product
A,B=map(int,input().split())

a=[2 for i in range(A)]+[1 for i in range(B)]
b=list(combinations(a,2))
ans=0
for i in b:
    tmp=sum(i)
    if tmp%2==0:
        ans+=1
print(ans)

Submission status: Accepted

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

ans = (n * (n - 1) + 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:
N, M = map(int, input().split())

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

ans=0

if M<=1:
    if N<=1:
        ans = 0
    else:
        ans = N*(N-1)/2
elif N<=1:
    ans = M*(M-1)/2

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

print(int(ans))

Submission status: Accepted

Solution code:
h, m = map(int, input().split())
h_method = h*(h-1)//2
m_method = m*(m-1)//2

print(h_method + m_method)

Submission status: Accepted

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

X = N + M 

print(int(X))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s=input().split()
n=int(s[0]);
m=int(s[1]);
a=n*(n-1)/2+m*(m-1)/2
a=int(a)
print(a)

Submission status: Accepted

Solution code:
import sys
 
mod = 10**9+7 
 
 
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]  
        self.invModulos = [0, 1]  
        self.invFactorial_ = [1, 1]  
 
    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]
 
    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]
 
    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]
 
 
class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)
 
    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
 
 
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m
n,k=map(int,input().split())
s=Combination(mod)
ans=s.ncr(n,2)+s.ncr(k,2)
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: <encoding name> -*-

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

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

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 >= 2) and (M >= 2):
    C_e = combinations_count(N, 2)
    C_o = combinations_count(M, 2)
    print(C_e + C_o)
elif (N < 2) and (M >= 2):
    C_e = 0
    C_o = combinations_count(M, 2)
    print(C_e + C_o)
elif (N >= 2) and (M < 2):
    C_e = combinations_count(N, 2)
    C_o = 0
    print(C_e + C_o)
else:
    print(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:
from operator import mul
from functools import reduce

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

def main():
    N,M = map(int, input().split())
    ans = combinations_count(M,2) + combinations_count(N,2)
    print(ans)

main()

Submission status: Accepted

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

main()

Submission status: Accepted

Solution code:
import sys
def ISI(): return map(int, sys.stdin.readline().rstrip().split())

n, m = ISI()
cnt =0
for i in range(n):
	if i>0:	cnt += i
for j in range(m):
	if j>0: cnt += j
print(cnt)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
n, m = map(int, input().split())
r = []
i = 0
j = -1
c = 0
for _ in range(n):
    i += 2
    r.append(i)
for _ in range(m):
    j += 2
    r.append(j)
r.sort()
for k in list(combinations(r, 2)):
    if sum(k) % 2 == 0:
        c += 1

print(c)

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

Submission status: Accepted

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

Submission status: Accepted

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

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