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:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi()

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

a = 0
if n >= 2:
    a = cmb(n,2)

b = 0
if m >= 2:
    b = cmb(m,2)

print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def calc(x):
    if x >= 2:
        return math.factorial(x) / (math.factorial(x - 2) * 2)
    else:
        return 0

even = (calc(n)) + (calc(m))

print(int(even))

Submission status: Accepted

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


for i in range(n):
    count += i
for j in range(m):
    arrrr += j
count += arrrr
print(count)

Submission status: Accepted

Solution code:
#from scipy.special import comb
from math import factorial

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

if N >= 2:
  N1 = factorial(N) / factorial(2) / factorial(N - 2)
else:
  N1 = 0
if M >= 2:
  M1 = factorial(M) / factorial(2) / factorial(M - 2)
else:
  M1 = 0
print(int(N1+M1))

Submission status: Accepted

Solution code:
M, N = [int(k) for k in input().split(' ')]
import math 
res = 0

if N >= 2:
  res += (math.factorial(N) // math.factorial(2) // math.factorial(N - 2))

if M >= 2:
  res += (math.factorial(M) // math.factorial(2) // math.factorial(M - 2))

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

print(solve())

Submission status: Accepted

Solution code:
import math


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

def c_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if n > 1 and m > 1:
    print(c_count(n, 2) + c_count(m, 2))
else:
    if n <= 1 and m > 1:
        print(c_count(m, 2))
    elif n > 1 and m <= 1:
        print(c_count(n, 2))
    else:
        print(0)

Submission status: Accepted

Solution code:
from itertools import permutations, combinations,combinations_with_replacement,product

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

s = [1 for _ in range(n)]
t = [1 for _ in range(m)]

a = list(combinations(s, 2))
b = list(combinations(t, 2))

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

Submission status: Accepted

Solution code:
import math
N,M = list(map(int,input().split()))
m = 0
n = 0
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if M>1:
    m =comb(M,2)
if N>1:
    n = comb(N,2)
ans = m +n
print(ans)

Submission status: Accepted

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


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


if N <= 1 and M <= 1:
    print(0)
elif N <= 1 and M > 1:
    print(combinations_count(M, 2))

elif N > 1 and M <= 1:
    print(combinations_count(N, 2))

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

Submission status: Accepted

Solution code:
import math

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

NM = list(map(int, input().split()))

odd = 1
if (NM[1] > 1):
    odd = permutations_count(NM[1], 2)

even = 1
if (NM[0] > 1):
    even = permutations_count(NM[0], 2)

sum = 0
if (odd > 1):
    sum += int(odd / 2)
if (even > 1):
    sum += int(even / 2)

print(sum)

Submission status: Accepted

Solution code:
from itertools import combinations
from math import factorial


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


if __name__ == "__main__":
    n, m = map(int, input().split())
    print(combinations_count(n) + combinations_count(m))

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

# 偶数 + 偶数

total = permutations_count(N, 2)

# 奇数 + 奇数
total += permutations_count(M, 2)
print(total)

Submission status: Accepted

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

nC2 = N * (N - 1) // 2
mC2 = M * (M - 1) // 2

print(nC2 + mC2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

res = 0

if N != 0:
  res += int((N * (N - 1)) / 2)
if M != 0:
  res += int((M * (M - 1)) / 2)

print(res)

Submission status: Accepted

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

N, M = map(int, input().split())
result = (per_count(N, 2) + per_count(M, 2)) // 2
print(result)

Submission status: Accepted

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

oo = m*(m-1)
ee = n*(n-1)

ans = oo + ee
print(ans//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

x ,y = 0,0
if n > 1 :
    x = permutations_count(n,2)

if m > 1:
    y = permutations_count(m,2)

print(x+y)

Submission status: Accepted

Solution code:
import math
def combinations_count(n, r):
    if n <= 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
N, M = (int(i) for i in input().split())  

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

Submission status: Accepted

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

import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
if N < 2:
    base = 0
else:
    base = comb(N,2)
    
if M < 2:
    base2 = 0
else:
    
    base2 = comb(M,2)

print(base+base2)

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

    all = int(((n + m)*(n+m-1))/2)
    ki = n*m
    gu = int(all - ki)
    print(gu)


if __name__ == "__main__":
    a_159()

Submission status: Accepted

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

import math

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

a, b = 1, 1
if N > 1:
    a = combinations_count(N,2) 
else:
    a = 0
if M > 1:
    b = combinations_count(M, 2)
else:
    b = 0


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

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

print(int(ans))

Submission status: Accepted

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

if n == 1 and m ==1:
    print(0)
    exit()

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

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
count = 0
for i in range(1,a+1):
    count += a - i

for x in range(1,b+1):
    count += b - x


print(count)

Submission status: Accepted

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


c = math.factorial(n+m)//(math.factorial(2)*math.factorial((n+m) - 2))
print(c - n*m)

Submission status: Accepted

Solution code:
Even, Odd = map(int, input().split())

if Odd > 1:
    ans1 = Even * (Even-1) / 2
    ans2 = Odd * (Odd-1) / 2
else:
    ans1 = Even * (Even-1) / 2
    ans2 = 0
print(int(ans1+ans2))

Submission status: Accepted

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

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

n_cnt = 0
m_cnt = 0

if n >= 2:
    n_cnt = len(list(itertools.combinations(range(n), 2)))

if m >= 2:
    m_cnt = len(list(itertools.combinations(range(m), 2)))

print(n_cnt + m_cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num=list(map(int,input().split()))
com_1=0
com_2=0

if num[0]<=1:
    com_1=0
else:
    com_1=(num[0]*(num[0]-1))/2

if num[1]<=1:
    com_2=0
else:
    com_2=(num[1]*(num[1]-1))/2

print(int(com_1 + com_2))

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

c = combinations_count(N+M, 2)

print(c-(N*M))

Submission status: Accepted

Solution code:
n, m = 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())
ans = 0
if n<=1:
  ans += 0
else:
  ans += n * (n-1) /2
  
if m <= 1:
  ans += 0
else:
  ans += m*(m-1)/2
  
print(int(ans))

Submission status: Accepted

Solution code:
from math import factorial

def fact(n):
    r = 2
    if n - r < 0:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

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

print(fact(N)  + fact(M))

Submission status: Accepted

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

res = 0

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

print(int(res))

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())
def com(n, r):
    if n<r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(com(n,2)+com(m,2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.misc import comb
n, m = map(int,input().split())

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

Submission status: Accepted

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

sum_ = 0

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

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

print(int(sum_))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

count=0

if a>=2:
    count+=combinations_count(a,2)

if b>2:
    count+=combinations_count(b,2)

print(count)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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:
num = [int(n) for n in input().split()]

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

r = 0

for i in num:
    r += comb(i)

print(int(r))

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(e) for e in 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:
# coding: utf-8
# Your code here!
N,M=map(int,input().split())

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

Submission status: Accepted

Solution code:
from math import factorial

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

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

print(int(a+b))

Submission status: Accepted

Solution code:
import math

def combinations_count(count, r):
    if count <= 1:
        return 0

    return math.factorial(count) // (math.factorial(count - r) * math.factorial(r))

if __name__ == "__main__":
    n, m = map(int, input().split(' '))
    print(combinations_count(n, 2) + combinations_count(m, 2))

Submission status: Accepted

Solution code:
from math import factorial as f
x,y=map(int,input().split())
if(x<2):
    a=0
else:
    a=f(x)//(f(x-2)*2)
if(y<2):
    b=0
else:    
    b=f(y)//(f(y-2)*2)
print(a+b)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = 0
tables = [2*i for i in range(N)] + [2*i+1 for i in range(M)]
for i in range(len(tables)-1):
  for j in range(i+1, len(tables)):
    if not (tables[i] + tables[j]) % 2:
      cnt += 1
print(cnt)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

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 sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())
 
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:
from math import factorial

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

if N > 1 and M > 1:
	a = factorial(N) / factorial(2) / factorial(N - 2)
	b = factorial(M) / factorial(2) / factorial(M - 2)
elif N <= 1 and M > 1:
	b = factorial(M) / factorial(2) / factorial(M - 2)
	a = 0
elif M <= 1 and N > 1:
	a = factorial(N) / factorial(2) / factorial(N - 2)
	b = 0
else:
	a, b = 0, 0


print(int(a+b))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = 0
ls = [0]
for i in range(1, 110):
    ls.append(ls[i - 1] + i)
if N == 0:
    N +=1
if M == 0:
    M += 1

print(ls[N-1] + ls[M-1])

Submission status: Accepted

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

nkai = 1
nkaid = 1
mkai = 1
mkaid = 1
for i in range(n):
  nkai *= (n-i)
for i in range(n-2):
  nkaid *= (n-2-i)
for i in range(m):
  mkai *= (m-i)
for i in range(m-2):
  mkaid *= (m-2-i)

if n == 1:
  nans= 0
else:
  nans= int(nkai/(nkaid*2))
if m == 1:
  mans= 0
else:
  mans= int(mkai/(mkaid*2))


print(nans + mans)

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

Submission status: Accepted

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

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

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()))
s = int(N * (N -1) /2)
t = int(M * (M -1) /2)

print(s + t)

Submission status: Accepted

Solution code:
n, m = 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:
N,M = map(int,input().split())
# 偶数 = 偶数＋偶数 or 奇数＋奇数
print(N*(N-1)//2 + M*(M-1)//2)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


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


def cmb(n, r):
    # combination
    if n < r:
        return 0
    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 = inpl()

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

Submission status: Accepted

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

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

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

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

print(comb2(N)+comb2(M))

Submission status: Accepted

Solution code:
import math

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

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

result1 = 0
result2 = 0

if N > 1:
    result1 = combinations_count(N, 2)

if M > 1:
    result2 = combinations_count(M, 2)

print(result1 + result2)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
#N偶数,M奇数

a = N*(N-1)/2
b = M*(M-1)/2
print(str(int(a+b)))

Submission status: Accepted

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (n, m) = [int(e) for e in lines[0].split(' ')]

    return (n, m)


def solve(n, m):
    
    
    result = (n + m) * (n + m - 1) // 2 - n * m
    
    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
import math
n, m = raw_input().split()
n = int(n)
m = int(m)
if n < 2 and m < 2:
  print(0)
elif n < 2:
  print(math.factorial(m)//(math.factorial(m-2) * 2))
elif m < 2:
  print(math.factorial(n)//(math.factorial(n-2) * 2))
else:
  print(math.factorial(n)//(math.factorial(n-2)*2) + math.factorial(m)//(math.factorial(m-2)*2))

Submission status: Accepted

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

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

Submission status: Accepted

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

count = 0
if N != 0:
    count += N * (N -1) // 2
if M != 0:
    count += M * (M -1) // 2
print(count)

Submission status: Accepted

Solution code:
n, m = input().split(' ')
n = int(n)
m = int(m)
a = 0
b = 0

if n != 0:
  a = n * ( n - 1 ) / 2 
if m != 0:
  b = m * (m - 1) / 2
print(int(a + b))

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
ans = 0
# 偶数ペア
ans += n*(n-1) / 2
# 奇数ペア
ans += 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))

def main():
    n, m = map(int, input().split())
    if n >= 2:
        n_comb = comb(n,2)
    elif n < 2:
        n_comb = 0
    if m >= 2:
        m_comb = comb(m, 2)
    elif m < 2:
        m_comb = 0
    print(n_comb + m_comb)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
def cmb(n,r):
    return factorial(n) // factorial(r) // factorial(n - r)

n,m=mii()
ans=0
if n<2 and m<2:
    print(0)
elif n>=2 and m<2:
    print(cmb(n,2))
elif n<2 and m>=2:
    print(cmb(m,2))
else:
    print(cmb(n,2)+cmb(m,2))

Submission status: Accepted

Solution code:
import math

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


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

c = comb(a, 2)
d = comb(b, 2)

print(c+d)

Submission status: Accepted

Solution code:
inp = list(map(lambda x: int(x), input().split(" ")))
N = inp[0]
M = inp[1]

sum1 = N*(N-1)//2
sum2 = M*(M-1)//2

print(sum1+sum2)

Submission status: Accepted

Solution code:
def LI():
	return [ int(s) for s in input().split() ]
  
N,M = LI()

print(int(N*(N-1)/2) + int(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:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    print(N * (N-1) // 2 + M * (M-1) // 2)
    return


# 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:
a, b = map(int, input().split())
import math
def combination(n, r):
    if n <= 1:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
print(combination(a, 2) + combination(b, 2))

Submission status: Accepted

Solution code:
import math

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

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

a = 0
if N >= 2:
  a = combinations_count(N, 2)
b = 0
if K >= 2:
  b = combinations_count(K, 2)
print(a + b)

Submission status: Accepted

Solution code:
import math

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


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

Submission status: Accepted

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

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

if n >= 2:
  a = cmb(n,2)
else:
  a = 0
if m >= 2:
  b = cmb(m,2)
else:
  b = 0
print(a+b)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

ee = 0 if N < 2 else N * (N-1) // 2
oo = 0 if M < 2 else M * (M-1) // 2

ans = ee + oo

print(ans)

Submission status: Accepted

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

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())
n2=(n*(n-1))//2
m2=(m*(m-1))//2

print(n2+m2)

Submission status: Accepted

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

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

print(cmb(N, 2) + cmb(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  = [int(n) for n in input().split(' ')]

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

Submission status: Accepted

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

for i in range(n):
  for k in range(i+1,n):
    count += 1
for i in range(m):
  for k in range(i+1,m):
    count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def comb(n,k):
    if n >= k:
        return math.factorial(n) // (math.factorial(n-k) * math.factorial(k))
    else:
        return 0
ans = comb(N,2)+comb(M,2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

N, M = map(int, input().rstrip().split())
ret = 0
if N > 1:
    ret += combinations_count(N, 2)
if M > 1:
    ret += combinations_count(M, 2)
print(ret)

Submission status: Accepted

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

cg = sum([i for i in range(n-1, 0, -1)])
ck = sum([i for i in range(m-1, 0, -1)])
print(cg+ck)