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:
def MI():return map(int,input().split())
def LI():return list(MI())



# n=int(input())

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

print(ans)

Submission status: Accepted

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

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

gu = (N * (N-1))/2
ki = (M * (M-1))/2

print(int(gu + ki))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,m = [int(e) for e in input().split()]
res = 0
if n >= 2:
    res += comb(n,2)
if m >= 2:
    res += comb(m,2)
print(res)

Submission status: Accepted

Solution code:
from math import *

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

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

cnt += n * (n-1) // 2
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ans = N*(N-1)//2 + 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:
# デバッグ用
GBN_DEBUG = False
GBN_DEBUG = True
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
#N = int(input())
#S, T = input().split()
N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = A = list(map(int, input().split()))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    n,m=MI()
    print(n*(n-1)//2+m*(m-1)//2)

main()

Submission status: Accepted

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

sum = 0

if x > 1:
    sum += x*(x-1) / 2
if y > 1:
    sum += y*(y-1) / 2
print(int(sum))

Submission status: Accepted

Solution code:
import math

n, m = map(int, input().split(' '))
if n >= 2:
    ret_n = n * (n - 1) / 2
else:
    ret_n = 0

if m >= 2:
    ret_m = m * (m - 1) / 2
else:
    ret_m = 0

print(int(ret_n + ret_m))

Submission status: Accepted

Solution code:
inxx = input()
inxx = inxx.split()
n = int(inxx[0])
m = int(inxx[1])
sol = (n*(n-1))//2 + (m*(m-1))//2

print(sol)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())			# "5 7" -> ["5", "7"] -> 5, 7 => N=5,K=7

a=max(0, n*(n-1)//2) + max(0,m*(m-1)//2)
print(a)

Submission status: Accepted

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

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

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

print(int(nc2(N)+nc2(M)))

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 input_int_list():
    return [int(thing) for thing in input().split(" ")]

N,M=input_int_list()
print((N*N-N+M*M-M)//2)

Submission status: Accepted

Solution code:
import math

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

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

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def nCr(n, r):
    import math
    # nCrのr>nは組み合わせが存在しないので0を返す
    # raiseすべきのこともあるかも
    if r > n:
        return 0
    return math.factorial(n) // ((math.factorial(n - r) * math.factorial(r)))

n, m = map(int, input().split())
res = 0
if n > 1:
    res += nCr(n, 2)
if m > 1:
    res += nCr(m, 2)
print(res)

Submission status: Accepted

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

def calc(s):
  if s < 2:
    return int(0)
  else:
    return int(s * (s-1) / 2)

print(calc(n) + calc(m))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans))

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

Submission status: Accepted

Solution code:
import sys
import os
import time
import collections
from collections import Counter, deque
import itertools
import math
import timeit
import random
from io import BytesIO, IOBase
 
#########################
# imgur.com/Pkt7iIf.png #
#########################
 
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
 
def divs(n, start=1):
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors
 
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
 
def flin(d, x, default=-1):
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return (default, default)
    else:
        return (left, right)
 
def ceil(n, k): return n // k + (n % k != 0)
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def prr(a, sep=' '): print(sep.join(map(str, a)))
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
 
 
# region fastio
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
	newlines = 0
 
	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = "x" in file.mode or "r" not in file.mode
		self.write = self.buffer.write if self.writable else None
 
	def read(self):
			while True:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					if not b:
							break
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines = 0
			return self.buffer.read()
 
	def readline(self):
			while self.newlines == 0:
					b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
					self.newlines = b.count(b"\n") + (not b)
					ptr = self.buffer.tell()
					self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
			self.newlines -= 1
			return self.buffer.readline()
 
	def flush(self):
			if self.writable:
					os.write(self._fd, self.buffer.getvalue())
					self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
	def __init__(self, file):
			self.buffer = FastIO(file)
			self.flush = self.buffer.flush
			self.writable = self.buffer.writable
			self.write = lambda s: self.buffer.write(s.encode("ascii"))
			self.read = lambda: self.buffer.read().decode("ascii")
			self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
 
# endregion
'''for _ in range(ii()):
    n=ii()
    a=li()
    m,k,md=0,0,0
    mn,mx=10**9+1,-10**9-1
    for i in range(n-1):
        if a[i]!=-1 and a[i+1]!=-1:
            m=max(m,abs(a[i]-a[i+1]))
    for i in range(1,n-1):
        if a[i]==-1:
            if a[i+1]!=-1:
                mn=min(mn,a[i+1])
                mx=max(mx,a[i+1])
            if a[i-1]!=-1:
                mn=min(mn,a[i-1])
                mx=max(mx,a[i-1])
    if mn==10**9+1 and mx==-10**9-1:
        print(0,0,sep=' ')
    else:
        md=(mn+mx+1)//2
        m=max(abs(mx-md),abs(mn-md),m)
        print(m,md,sep=' ')'''

'''for _ in range(ii()):
    n,m=mi()
    tg=n//2
    n0=n-m
    total=(n*(n+1))//2
    res=0
    if n0<n:
        if m>=tg:
            res=total-n0
        else:
            i=tg-m
            if n&1:
                nn0=2*i+1
            else:
                nn0=2*i
            res=total-((nn0*(nn0+1))//2)-(n0-nn0)
            #print(nn0,n0-nn0)
    print(res)'''
#***************************************************************************************************************************


'''def solve():
    n=int(input())
    a=list(map(int,input().split()))
    diff=len(set(a))
    if diff==1: print (int((n*(n+1))/2))
    elif diff==n: print (1)
    else:
        i=j=ans=0
        ahead=True
        distinct={}
        while j<n:
            if ahead:
                distinct[a[j]]=distinct[a[j]]+1 if a[j] in distinct else 1
                if len(distinct)==diff:
                    ahead=False
                else:
                    j+=1
            else:
                ans+=n-j
                if distinct[a[i]]>1:
                    distinct[a[i]]-=1
                else:
                    distinct.pop(a[i])
                    j+=1
                    ahead=True
                i+=1
        print (ans)
 
solve()'''

#******************************************************************************************

'''s=input()
n=len(s)
i,cntl,cntg=0,0,0
res,fl,fg=0,0,0
while(i<n):
    if s[i]=='<':
        while(i<n and s[i]!='>'):
            fl=1
            cntl+=1
            i+=1
    else:
        while(i<n and s[i]!='<'):
            fg=1
            cntg+=1
            i+=1
    if fl==1 and fg==1:
        res+=max(cntl,cntg)
        cntl-=1
        cntg-=1
        res+=cntl*(cntl+1)//2
        res+=cntg*(cntg+1)//2
        fl,fg,cntl,cntg=0,0,0,0
if fl:
    res+=cntl*(cntl+1)//2
if fg:
    res+=cntg*(cntg+1)//2
print(res)'''


#********************************************************************************************************


from math import factorial
def ncr(n,r):
    if n>=r:
        return factorial(n)//(factorial(r)*factorial(n-r))
    else:
        return 0
n,m=mi()
print(ncr(n,2)+ncr(m,2))

Submission status: Accepted

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

if n==0:
    res = m*(m-1)//2
elif m==0:
    res = n*(n-1)//2
else:
    res = n*(n-1)//2 + m*(m-1)//2

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

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

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

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc159","a",main)

Submission status: Accepted

Solution code:
# even, odd
n, m = [int(x) for x in input().split()]

# even pairs.
ee = n * (n-1) / 2
# Odd pairs.
oo = m * (m-1) / 2

print(int(ee + oo))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)


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

if __name__ == '__main__':
    main()

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

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:
"""
NTC here
"""
import sys
inp = sys.stdin.readline


def input(): return inp().strip()


flush = sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)


def iin(): return int(input())


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

# range = xrange
# input = raw_input


def main():
    def fn(n):
        return (n*(n+1))//2
    n, m = lin()
    print(fn(n-1)+fn(m-1))

main()
# threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
from scipy.misc import comb
N, M = map(int, input().split())
print(comb(N,2,exact=True)+comb(M,2,exact=True))

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


def nCr(n, r, mod=10**9+7):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod


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

Submission status: Accepted

Solution code:
import itertools as it
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(m+n)

Submission status: Accepted

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

ans = ans1 + ans2

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3.4
# -*- coding: utf-8 -*-
# abc159/abc159_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    n = N * (N - 1) // 2 if N > 1 else 0
    m = M * (M - 1) // 2 if M > 1 else 0
    print(n + m)
    return

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
guu, ki = map(int, input().split())

print(int(guu*(guu-1)/2 + ki*(ki-1)/2))

Submission status: Accepted

Solution code:
#n is even, m is odd
n,m = map(int, input().split())

#total should be even
# even = even + even(n and n)
# even = odd + odd(m and m)
total = n*(n-1)//2 + m*(m-1)//2
print(total)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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


def comb(n, r):
    numerator = denominator = 1
    for i in range(r):
        numerator = numerator * (n - i)
        denominator = denominator * (i + 1)
    return numerator // denominator


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

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

def comb(n, r):
    bunshi = 1
    for i in range(n-r+1,n+1):
        bunshi = bunshi*i
    bunbo = 1
    for i in range(1,r+1):
        bunbo = bunbo * i 
    return bunshi//bunbo

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

Submission status: Accepted

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

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

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())
if n <= 1 and m <= 1:
    print(0)
elif n <= 1:
    print(m * (m - 1) // 2)
elif m <= 1:
    print(n * (n - 1) // 2)
else:
    print(n * (n - 1) // 2 + m * (m - 1) // 2)

Submission status: Accepted

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

n, m = map(int, input().split())
ans = 0
if n >= 2:
    ans += cmb(n, 2)

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

print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

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

oo = N*(N-1)/2
ee = M*(M-1)/2


ans = int(oo+ee)
print(ans)

Submission status: Accepted

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

fromE = ((x[0])*(x[0]-1))//2
fromO = ((x[1])*(x[1]-1))//2

print(fromO+fromE)

Submission status: Accepted

Solution code:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
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

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n,m=map(int,input().split())
    ans=0
    if n==0:
        ans=cmb(m,2)
    elif n==1 and m==1:
        ans=0
    elif n==1 and m>=2:
        ans=cmb(m,2)
    elif n>=2 and m<=1:
        ans=cmb(n,2)
    elif n>=2 and m>=2:
        ans=cmb(n,2)+cmb(m,2)
    print(ans)


if __name__ == "__main__":

    main()

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
ans += (N*(N-1))//2 if N >= 2 else 0
ans += (M*(M-1))//2if M >= 2 else 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

x,y = map(int,input().split())
a = 0
b = 0

if x >= 2:
    a = comb(x,2)

if y >= 2:
    b = comb(y,2)

print(a+b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
from scipy.misc import comb
print(comb(n,2,exact=True)+comb(m,2,exact=True))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B=map(int, raw_input().split())
print A*(A-1)/2+B*(B-1)/2

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
#nC2+mC2
def comb(n,k):
    n1, k = n+1, min(k, n-k)
    numer = denom = 1
    for i in range(1,k+1):
        numer = numer*(n1-i)
        denom = denom*i
    return numer//denom
if N >= 2 and M >= 2:
    ans = comb(N,2)+comb(M,2)
elif N < 2 and M >= 2:ans = comb(M,2)
elif N >= 2 and M < 2:ans = comb(N,2)
else:ans = 0
print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
   N, M = MAP()
   print(len(list(combinations(range(N), 2))) + len(list(combinations(range(M), 2))))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n, m = list(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:
#!/usr/bin/env python

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

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

    print(ret)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
## 組み合わせの総数だけ知りたい
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def solve(N: int, M: int):
    answer = 0
    if N >= 2:
        answer += comb(N,2)
    
    if M >= 2:
        answer += comb(M,2)

    print(answer)

    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:
NM = input().split(" ")

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

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

print(int(a+b))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N,M=map(int,input().split())
    if N>1:
        if M>1:
            print(N*(N-1)//2+M*(M-1)//2)
        else:
            print(N*(N-1)//2)
    else:
        if M>1:
            print(M*(M-1)//2)
        else:
            print(0)



resolve()

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:
import sys
input = sys.stdin.readline

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

print(a + b)

Submission status: Accepted

Solution code:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

if n == m == 1:
    print(0)
else:
    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(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 = [list(map(int, s.split())) for s in open(0)][0]

x = 0
y = 0
if n[0] >= 1:
    x = n[0] * (n[0] - 1) / 2
if n[1] >= 1:
    y = n[1] * (n[1] - 1) / 2
print(int(x + y))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def RA():
    l = input().split()
    return list(map(lambda x: int(x), l))
    
a = RA()
n = a[0]
m = a[1]
print(int(m * (m - 1) / 2 + n * (n - 1) / 2))

Submission status: Accepted

Solution code:
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
from bisect import bisect, bisect_left, bisect_right

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

N, M = map(int,input().split())
s = N+M
print(M*(M-1)//2 + N*(N-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:
import math
from scipy.misc import comb

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

S = comb(a+b, 2, exact=True)
odd = a*b

print(S-odd)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans
ans=Comb(n,2)+Comb(m,2)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    ans=n*(n-1)+m*(m-1)
    print(ans//2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)