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=map(int,input().split())
def comb(k, r):
  if k<2:
    return 0
  else:
    return math.factorial(k) // (math.factorial(k - r) * math.factorial(r))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
sum = 0
array = []
for i in range(N):
    array.append(0)
for i in range(M):
    array.append(1)
for i in range(N+M-1):
    for j in range(i+1,N+M):
        if((array[i]+array[j])%2 == 0):
            sum += 1

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

ans = a+b

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
count=0
a=[]
for i in range(n):
    a.append(2)
for i in range(m):
    a.append(1)
#print(a)

for i in range(n+m-1):
    for j in range(i+1,n+m):
        #print(a[i],a[j])
        if (a[i]+a[j])%2==0:
            count+=1
print(count)

Submission status: Accepted

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

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

Submission status: Accepted

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

#print('N=', N, 'M=', M)

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

print(T)

Submission status: Accepted

Solution code:
import math 

N2,M1 = map(int, input().split())
count=0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if N2!=0 and N2!=1:
    count += combinations_count(N2,2)
if M1!=0 and M1!=1:
    count += combinations_count(M1,2)

print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

n,m = map(int, input().split())
a = list(combinations(range(n),2))
b = list(combinations(range(m),2))

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]

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

N, M = LI()

if N >= 2:
    nn = combinations_count(N , 2)
else:
    nn = 0

if M >= 2:
    mm = combinations_count(M , 2)
else:
    mm = 0

print(nn + mm)

Submission status: Accepted

Solution code:
from itertools import combinations

N, M = map(int, input().split())
nlist = [] 
mlist = []

for i in range(N):
  nlist.append(i)
  
for j in range(M):
  mlist.append(j)

if N == 1 and M == 1:
  print(0)
  exit()
  
if N == 1:
  print(len(list(combinations(mlist,2))))
  exit()
  
if M == 1:
  print(len(list(combinations(nlist,2))))
  exit()
  
print(len(list(combinations(nlist,2))) + len(list(combinations(mlist,2))))

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


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


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

if n <= 1:
    ansn = 0
else:
    ansn = cmb(n, 2)

if m <= 1:
    ansm = 0
else:
    ansm = cmb(m, 2)
print(ansn + ansm)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

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

if n < 2:
  ns = 0
else:
  ns = combinations_count(n, 2)
if m < 2:
  ms = 0
else:
  ms = combinations_count(m, 2)
s = ns + ms
print(s)

Submission status: Accepted

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

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

n, m = map(int, input().split())
if n in [0, 1] and m in [0, 1]:
    ans = 0
elif n in [0, 1]:
    ans = factorial(m) // (factorial(m - 2) * factorial(2))
elif m in [0, 1]:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
else:
    ans = factorial(n) // (factorial(n - 2) * factorial(2))
    ans += factorial(m) // (factorial(m - 2) * factorial(2))
print(ans)

Submission status: Accepted

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

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

def factrial(n):
    a = 0
    for i in range(1, n+1):
        a += i
    return a

nf = 0 if n < 2 else int(factrial(n - 1))
mf = 0 if m < 2 else int(factrial(m - 1))

print(nf + mf)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 20:52:57 2020

@author: over-
"""

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

Submission status: Accepted

Solution code:
import itertools

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

list_num = [1] * M
list_2 = [2] * N

list_num.extend(list_2)

count = 0
for c in list(itertools.combinations(list_num, 2)):
    wa = sum(c)
    if wa == 2 or wa == 4:
        count += 1
print(count)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
n,m = map(int,input().split())
#n個偶数
#M個奇数
#偶数+偶数　 奇数+奇数
sum = m + n
gu = [2] * n
ki = [1] * m

num1 = list(itertools.combinations(gu,2))
num2 = list(itertools.combinations(ki,2))
result = int(len(num1)) + int(len(num2))
print(result)

Submission status: Accepted

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

ar = [0] * n + [1] * m
for s in range(len(ar)):
    for a in range(s + 1, n + m):
        if (ar[s] + ar[a]) % 2 == 0:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math

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


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


if N <= 1 and M <= 1:
    print(0)
elif N <= 1:
    print(combinations_count(M))
elif M <= 1:
    print(combinations_count(N))
else:
    print(combinations_count(N) + combinations_count(M))

Submission status: Accepted

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

if m >= 2:
    y = factorial(m) / factorial(2) / factorial(m - 2)

print(int(x+y))

Submission status: Accepted

Solution code:
M,N=map(int,input().split())
def fact(n):
	s=1
	for i in range(2,n+1):
		s=s*i
	return s

def conb(n,r):
	return fact(n)//(fact(r)*fact(n-r))

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

Submission status: Accepted

Solution code:
import math
n,m = map(int, input().split())
e = 0
o = 0
f = math.factorial
if n>=2:
    e = f(n) / f(n-2) / 2
if m>=2:
    o = f(m) / f(m-2) / 2

print(int(e+o))

Submission status: Accepted

Solution code:
import math
import sys

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

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

if n == 1 and m == 1:
  print('0')
  sys.exit()
  
if n <= 1:
  print(comb(m, 2))
  sys.exit()
  
if m <=1:
  print(comb(n, 2))
  sys.exit()

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

Submission status: Accepted

Solution code:
e,o=map(int,input().split())
sum1=0
sum2=0

if e>=2:
  sum1=e*(e-1)/2

if o>=2:
  sum2=o*(o-1)/2

print(int(sum1+sum2))

Submission status: Accepted

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

N = int(N)
M = int(M)

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

Submission status: Accepted

Solution code:
from math import factorial


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

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

result = 0

if n >= 2:
    result += math.factorial(n)/math.factorial(n-2)/math.factorial(2)
if m > 2:
    result += math.factorial(m)/math.factorial(m-2)/math.factorial(2)

print(int(result))

Submission status: Accepted

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

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

NS = [int(_) for _ in input().split()]
N = NS[0] # 偶数
M = NS[1] # 奇数

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

def solve(N, M):
    # 全部の組み合わせ - 奇数になる組み合わせ
    return combinations_count(N+M, 2) - M * N

print(solve(N, M))

Submission status: Accepted

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

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

if n >= 2:
    count += comb(n, 2)

if m >= 2:
    count += comb(m, 2)

print(count)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

# print(n)
# print(m)

count = 0
for i in range(n + m):
    for j in range(n + m):
        if i == j:
            continue
        # print("{} {}".format(i, j))
        
        if i < n and j < n:
            count += 1
        if i >= n and j >= n:
            count += 1
        
# print(count)
print(count // 2)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def main():
    n, m = map(int, input().split())
    fromN = 0
    fromM = 0
    if n > 1:
        fromN = cmb(n, 2)
    
    if m > 1:
        fromM = cmb(m, 2)
    
    print(fromN + fromM)
    return 


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 __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
from heapq import *
from fractions import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 50010
MOD = 10**9+7
spf = [i for i in range(MAXN)]
spf[0]=spf[1] = -1
def sieve():
    for i in range(2,MAXN,2):
        spf[i] = 2
    for i in range(3,int(MAXN**0.5)+1):
        if spf[i]==i:
            for j in range(i*i,MAXN,i):
                if spf[j]==j:
                    spf[j]=i
def fib(n,m):
    if n == 0:
        return [0, 1]
    else:
        a, b = fib(n // 2)
        c = ((a%m) * ((b%m) * 2 - (a%m)))%m
        d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m
        if n % 2 == 0:
            return [c, d]
        else:
            return [d, c + d]

def charIN(x= ' '):
    return(sys.stdin.readline().strip().split(x))

def arrIN(x = ' '):
    return list(map(int,sys.stdin.readline().strip().split(x)))

def ncr(n,r):
    num=den=1
    for i in range(r):
        num = (num*(n-i))%MOD
        den = (den*(i+1))%MOD

    return (num*(pow(den,MOD-2,MOD)))%MOD

def flush():
    return sys.stdout.flush()

'''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*'''
n,m = arrIN()
ans = ncr(n,2)+ncr(m,2)
print(ans)

Submission status: Accepted

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


def combinations_count(n, r):
    if n==1 or n==0:
        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:
import math

A = input().split()

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

x = int(A[0])
y = int(A[1])

if x > 1 and y > 1:
  print(combinations_count(x, 2) + combinations_count(y, 2))
else:
  if x > 1 and y <= 1:
    print(combinations_count(x, 2))
  else:
    if x <= 1 and y > 1:
      print(combinations_count(y, 2))
    else:
      print(0)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def inputs(): return [int(x) for x in input().split()]
from collections import defaultdict

n,m= inputs()
a = (n*(n-1))//2
b = (m*(m-1))//2
print(a+b)

Submission status: Accepted

Solution code:
# ABC159 A

import math

def main():
    n, m = map(int, input().split())
    
    if n >= 2 and m >= 2:
        even = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))
        odd = math.factorial(m) // (math.factorial(m-2) * math.factorial(2))
    elif m >= 2:
        even = 0
        odd = math.factorial(m) // (math.factorial(m-2) * math.factorial(2))
    elif n >= 2:
        even = math.factorial(n) // (math.factorial(n-2) * math.factorial(2))
        odd = 0
    else:
        even = 0
        odd = 0

    print(even + odd)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import combinations
def solve(N: int, M: int):
    n=[]
    m=[]
    for i in range(N):
        n.append(i)
    for i in range(M):
        m.append(i)
    o=len(list(set(list(combinations(n,2)))))
    i=len(list(set(list(combinations(m,2)))))
    print(o+i)
    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:
import itertools
N,M= map(int, input().split())

n = '2'*N
m = '1'*M
l = list(n + m)

ans = 0

for x in itertools.combinations(l, 2):
  xx = int(x[0]) + int(x[1])
  if xx%2==0:
    ans += 1
print(ans)

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:
import sys
import collections
import heapq
import math
n,m = map(int,sys.stdin.readline().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(max(n - r,0)) * math.factorial(r))
print(combinations_count(n,2)+combinations_count(m,2))

Submission status: Accepted

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


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

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

result = nC2(N) + nC2(M)
print(result)

Submission status: Accepted

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

result=sum([i for i in range(0,N)])+sum([i for i in range(0,M)])

print(result)

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 == 0:
    base1 = 0
elif n == 1:
    base1 = 0
else:
    base1 = comb(n,2)

if m == 0:
    base2 = 0
elif m == 1:
    base2 = 0
else:
    base2 = comb(m,2)

print(base1 + base2)

Submission status: Accepted

Solution code:
import math
import itertools as it


i = input().split()



n = int(i[0])
m = int(i[1])
nc = it.combinations(range(n),2)
mc = it.combinations(range(m),2)

print(len(list(nc) + list(mc)))

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:


def c(n):
    return n*(n-1)//2

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

ans = c(n) + c(m)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

n = int(n)
m = int(m)
j = 0
for i in range(1, n):
  j += i
  
for i in range(1, m):
  j += i
  
print(j)

Submission status: Accepted

Solution code:


N, M = map(int, input().split())
A = [0 for _ in range(N)]
B = [1 for _ in range(M)]
X = A + B

ans = 0
for i in range(N + M):
    for j in range(i + 1, N + M):
        if (X[i] + X[j]) % 2 == 0:
            ans += 1


print(ans)

Submission status: Accepted

Solution code:
import math

#入力
N, M = map(int, input().split())


#combination 関数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

#main
if N <=1 and M <= 1:
  print(0)

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

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

Submission status: Accepted

Solution code:
import math as m1

def ncr(n1,n2):
  f= m1.factorial
  ans = f(n1)//(f(n1-n2)*f(n2))
  return ans

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

res =0
if n<2:
  res+=0
if m<2:
  res+=0
if n>=2:
  res+=ncr(n,2)
if m>=2:
  res+=ncr(m,2)
  
print(res)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def get_ans(n):
    if n <= 1:
        return 0
    return get_ans(n - 1) + n - 1


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if N<=1 and M<=1:
    print(0)
elif N>=2 and M>=2:
    print(int(combi(N,2))+int(combi(M,2)))
elif N>=2 and M<=1:
    print(int(combi(N,2)))
elif N<=1 and M>=2:
    print(int(combi(M,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))


if n <= 1 and m <= 1:
  print(0)
elif n <= 1 and m >= 2:
  print(combinations_count(m,2))
elif n >= 2 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
N,M=map(int,input().split())

if N>=2:
    n=math.factorial(N)/math.factorial(N-2)/2
else:
    n=0
## print(n)

if M>=2:
    m=math.factorial(M)/math.factorial(M-2)/2
else:
    m=0
## print(m)
print(int(m+n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
  N, M = map(int, input().split())
  if N == 1 and M == 1:
    print(0)
  elif N == 0 or N == 1:
    print(combinations_count(M, 2))
  elif M == 0 or M == 1:
    print(combinations_count(N, 2))
  else:
    print(combinations_count(N, 2) + combinations_count(M, 2))
if __name__ == '__main__':
  	main()

Submission status: Accepted

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

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

Submission status: Accepted

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

a = len(list(itertools.combinations(range(n),2)))
b = len(list(itertools.combinations(range(m),2)))

print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def comb(n,r):
    if n<2:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

a, b = map(int, input().split())
print(comb(a,2)+comb(b,2))

Submission status: Accepted

Solution code:
n,m = map(int, input().split(" "))
result = 0
if n > 1:
    for i in range(n):
        result += n-1
        n -= 1
if m > 1:
    for t in range(m):
        result += m-1
        m -= 1
print(result)

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

Solution code:
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())
x, y = 0, 0
for i in range(1, n):
    x += i
for j in range(1, m):
    y += j
print(x + y)

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a=input().split()
(n,m)=map(int,a)
d=0
d1=0
for i in range(n):
    n-=1
    d=d+n
for j in range(m):
    m-=1
    d1=d1+m
print(d1+d)

Submission status: Accepted

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

nsum = 0
for i in range(N-1):
	nsum += i+1
msum = 0
for i in range(M-1):
	msum += i+1
print(nsum + msum)

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=list(map(int,input().split()))
if N>1:
  c1=combinations_count(N,2)
else:
  c1=0
if M>1:
  c2=combinations_count(M,2)
else:
  c2=0
print(c1+c2)

Submission status: Accepted

Solution code:
import itertools
import math

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

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

ans = 0
if N == 0 or N ==1:
    ans +=0
else:
    ans +=combinations_count(N, 2)

if M == 0 or M ==1:
    ans +=0
else:
    ans +=combinations_count(M, 2)

    
print(ans)

Submission status: Accepted

Solution code:
def comb(a, r = 2):
    if a < 2:
        return 0
    return a * (a - 1) // 2
def solve():
    n, m = map(int, input().split())
    print(comb(n, 2) + comb(m, 2))
solve()

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#Input
n, m= map(int, input().split()) #n:偶数, m:奇数

#Process
Ans = 0
for i in range(n - 1):
  Ans += (i + 1)
for i in range(m - 1):
  Ans += (i + 1)

#Output
print(Ans)

Submission status: Accepted

Solution code:
import itertools
N, Y = map(int, input().split())

count = 0

if N >= 2:
    count += len(list(itertools.combinations(range(N), 2)))

if Y >= 2:
    count += len(list(itertools.combinations(range(Y), 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:
s = input().split()
n = int(s[0])
m = int(s[1])

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

Submission status: Accepted

Solution code:
from sys import stdin

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

even_only = 0
odd_only = 0

if n > 1:
    even_only = n * (n - 1) / 2
if m > 1:
    odd_only = m * (m - 1) / 2

result = int(even_only + odd_only)
print(result)

Submission status: Accepted

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

def A159():
    N, M = [int(_) for _ in input().split()]
    if N <= 1:
        cn = 0
    else:
        # nC2
        cn = combinations_count(N, 2)
    if M <= 1:
        cm = 0
    else:
        cm = combinations_count(M, 2)
    print(cn+cm)

if __name__ == "__main__":
    A159()

Submission status: Accepted

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

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

if N >= 2:
	A=nCr(N,2)
else:
	A=0
if M >= 2:
	B=nCr(M,2)
else:
	B=0
print(A+B)

Submission status: Accepted

Solution code:
from itertools import combinations

n, m = [int(i) for i in input().split()]
c1, c2 = 0, 0
if n != 1:
    c1 = len(list(combinations(list(range(2, n * 2 + 1, 2)), 2)))
if m != 1:
    c2 = len(list(combinations(list(range(1, m * 2 + 1, 2)), 2)))
print(c1 + c2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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))
if n == 1 and m == 1:
    print(0)
elif n < 2 or m < 2:
    if n < 2:
        print(comb(m,2))
    else:
        print(comb(n,2))
else:
    n_comb = comb(n,2)
    m_comb = comb(m,2)
    print(n_comb+m_comb)

Submission status: Accepted

Solution code:
# 200322 A

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

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if __name__ == "__main__":
    N,M = list(map(int,input().split()))
    
    if N <= 1:
        Nc = 0
    else:
        Nc = cmb(N,2)
    
    if M < 2:
        Mc = 0
    else:
        Mc = cmb(M,2)
    print(Nc + Mc)

Submission status: Accepted

Solution code:
import math


def ABC159A(a):
    if a < 2:
        return 0
    else:
        return math.factorial(a)//(math.factorial(a-2)*2)


a,b = map(int, input().split())
print(ABC159A(a)+ABC159A(b))

Submission status: Accepted

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

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

    print(ans)

    return

if __name__ == "__main__":
    main()