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:
i = input().split(" ")
a,b = int(i[0]),int(i[1])
print(int(a*(a-1)/2+b*(b-1)/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.misc import comb

a,b = map(int,input().split()) #a even b odd
x = 0

x = comb(a, 2, exact=True) + comb(b, 2, exact=True)
    

print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
inp = input().split(' ')

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

ncount = 0 if n < 2 else n*(n-1)//2
mcount = 0 if m < 2 else m*(m-1)//2

print(str(ncount + mcount))

Submission status: Accepted

Solution code:
def factorial(n):
    if n > 1:
        return n * factorial(n - 1)
    else:
        return 1
        
m,n=map(int,input().split())
#n = 100
#m = 100

result = (int)(factorial(n)/(factorial(2) * factorial(n - 2)))
result += (int)(factorial(m)/(factorial(2) * factorial(m - 2)))

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if n > 1 and m > 1:
    print(n*(n-1)//2+m*(m-1)//2)
elif n <= 1:
    print(m*(m-1)//2)
else:
    print(n*(n-1)//2)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def kaijou(n):
  ans = 1
  for i in range(1,n+1):
    ans *= i
  return ans

ans = 1
ans2 = 1

if n == 1 or n == 0:
  ans = 0
elif n>2:
  ans = kaijou(n)//(2*kaijou(n-2))
elif n==2:
  ans = kaijou(n)//2

if m ==1 or m == 0:
  ans2 = 0
elif m>2:
  ans2 = kaijou(m)//(2*kaijou(m-2))
elif m==2:
  ans2 = kaijou(m)//2

print(ans+ans2)

Submission status: Accepted

Solution code:
def fact(n):
    fact = 1
    for i in range(1,n+1):
        fact *= i
    return fact

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

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


if __name__ == '__main__':
    main()

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(i) for i in input().split(" ")]
r = 0
if n > 1:
  r += comb(n, 2)
if m > 1:
  r += comb(m, 2)
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main(n,m):
    eveeve = (n*(n-1))/2 if n>=2 else 0
    oddodd = (m*(m-1))/2 if m>=2 else 0
    return int(eveeve+oddodd)

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def c(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,m=map(int,input().split())
if n>=2 and m>=2:

    ans=c(n,2)+c(m,2)
elif n<=1 and m>=2:
    ans=c(m,2)
elif m<=1 and n>=2:
    ans=c(n,2)
elif n<=1 and m<=1:
    ans=0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, combinations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n, m = LI()

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

    def C(n, r):
        return P(n, r)//math.factorial(r)
    if n > 2 and m > 2:
        print(C(n, 2) + C(m, 2))
    elif n < 2 and m < 2:
        print(0)
    elif n < 2:
        print(C(m, 2))
    elif m < 2:
        print(C(n, 2))
    return


# Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import math
def combinations_count(n,r):
    if n<r:
        return 0
    # c=n!/(r!*(n-r)!)
    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:
#n=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
import math
def combinations_count(n,k):#nCkを返す
    if k==0 or k==n:
        return 1
    elif n<k or k<0:
        return 0
    else:
        return math.factorial(n)//(math.factorial(n-k)*math.factorial(k))
print(combinations_count(n,2)+combinations_count(m,2))

Submission status: Accepted

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

def down_stream_summer(number):
    initial_adder=number-1
    summer=0
    while initial_adder>0:
        summer+=initial_adder
        initial_adder-=1
    return summer

end=down_stream_summer(n)+down_stream_summer(m)
print(end)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
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:
import sys
input = sys.stdin.readline().rstrip()
input = map(int, input.split(' '))
m, n = tuple(input)

print(sum(i for i in range(m)) + sum(i for i in range(n)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def diff_sum(n:int):
    if n>0 :
        return n + diff_sum(n-1)
    else:
        return 0
import math
n,m = list(map(int, input().split()))
print(diff_sum(n-1)+diff_sum(m-1))

Submission status: Accepted

Solution code:
import math 

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

print(s+t)

Submission status: Accepted

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


from_n = math.factorial(n)/math.factorial(2)/math.factorial(n - 2) if n >= 2 else 0
from_m = math.factorial(m)/math.factorial(2)/math.factorial(m - 2) if m >= 2 else 0
print(int(from_n + from_m))

Submission status: Accepted

Solution code:
from itertools import combinations
N,M=map(int,input().split())
even=0
odd=0

if N>1:
  even=len(list(combinations(range(N), 2)))
if M>1:
  odd=len(list(combinations(range(M), 2)))
print(even+odd)

Submission status: Accepted

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

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

print(int(a+b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

Solution code:
from sys import stdin


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import itertools

a,b = [int(i) for i in input().split()]

even = len(list(itertools.combinations(range(a),2)))
odd = len(list(itertools.combinations(range(b),2)))

print(even + odd)

Submission status: Accepted

Solution code:
# coding: utf-8
def cc(i):
    return i * (i-1) // 2

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

s = cc(n) + cc(m)
print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc159a
n,m=map(int,raw_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 >= 2:
    ans = ans + n * (n-1) / 2

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


print(int(ans))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
sum1 = 1
if N > 1:
    for i in range(2):
        sum1 = sum1 * N
        N -= 1
    sum1 /= 2
else:
    sum1=0
sum2 = 1
if M > 1:
    for i in range(2):
        sum2 *= M
        M -= 1
    sum2 /= 2
else:
    sum2 = 0
print(int(sum1+sum2))

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce


def cmb(_n, _r):
    _r = min(_n - _r, _r)
    if _r == 0:
        return 1
    return reduce(mul, range(_n, _n - _r, -1)) // reduce(mul, range(1, _r + 1))


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

count = 0
if n >= 2:
    count += cmb(n, 2)
if m > 2:
    count += cmb(m, 2)
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

Solution code:
import math

def main():
    N, M = (int(x) for x in input().split())
    a = math.factorial(N+M) // (math.factorial(N+M - 2) * math.factorial(2))
    print(a - (N*M))
if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

from sys import stdin, stderr

def Choose2(N):
   return N*(N-1)/2

def main():
   N, M = map(int, stdin.readline().split())
   res = Choose2(N) + Choose2(M)
   print(res)

   return 0

if __name__ == '__main__': main()

Submission status: Accepted

Solution code:
# A - The Number of Even Pairs
def main():
    N, M = map(int, input().split())
    print(N * (N - 1) // 2 + M * (M - 1) // 2)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(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(combinations_count(n, 2) + combinations_count(m, 2))
elif n > 1:
  print(combinations_count(n, 2))
elif m > 1:
  print(combinations_count(m, 2))
else:
  print(0)

Submission status: Accepted

Solution code:
import math
n,m = map(int, input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a = 0
b = 0
if n >=2:
    a = combinations_count(n, 2)
if m >= 2:
    b = combinations_count(m, 2)
print(a+b)

Submission status: Accepted

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

Submission status: Accepted

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

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 collections


def solve(n, m):
    evens = n*(n-1)//2
    odds = m*(m-1)//2

    return evens + odds


[n, m] = list(map(int, input().strip().split()))
print(solve(n, m))

Submission status: Accepted

Solution code:
#!python3

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


def main():
    ans = 0
    if N >= 2:
        ans += N * (N - 1) // 2
    if M >= 2:
        ans += M * (M - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
print(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
A = ans1+ans2
print(A)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

def resolve():
    N, M = map(int, input().split())
    balls = [2]*N + [1]*M
    ans = 0
    for x, y in combinations(balls, 2):
        if (x+y)%2 == 0:
            ans += 1
    return print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

print(c)

Submission status: Accepted

Solution code:
import math

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


a = input().split(" ")
n = int(a[0])
m = int(a[1])

c = combinations_count(n, 2)
c += combinations_count(m, 2)

print(c)

Submission status: Accepted

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

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

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

ans = combination(N, 2)
ans += combination(M, 2)

print(int(ans))

Submission status: Accepted

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

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter

# stdin = open("sample.txt")

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from math import factorial

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

def comb(n, r):
    if n - r < 0:
        return 0
    else:
        return factorial(n) // (factorial(n - r) * factorial(r))

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations
ne, no = map(int,input().split())
even, odd = [i for i in range(1,2*(ne+1)) if i % 2 == 0], [i for i in range(1,2*no) if i % 2 != 0]
lst = even + odd
c = 0
for i in combinations(lst,2):
    if sum(i) % 2 == 0:
        c += 1
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

all = (N+M)*(N+M-1)/2
minus = N*M
#print(all,minus)
print(int(all - minus))

Submission status: Accepted

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

Submission status: Accepted

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

n_comb = (N * (N -1)) / 2
m_comb = (M * (M -1)) / 2

output = int(n_comb) + int(m_comb)

print(output)

Submission status: Accepted

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


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest

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

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 1"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """4 3"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1 1"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """13 3"""
        output = """81"""
        self.assertIO(input, output)

    def test_入力例_5(self):
        input = """0 3"""
        output = """3"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
from sys import stdin,setrecursionlimit
n,m = map(int,stdin.readline().rstrip().split())
print(n*(n-1)//2+m*(m-1)//2)

Submission status: Accepted

Solution code:
import math


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

count = N * (N - 1) / 2 + M * (M - 1) / 2
print(math.floor(count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
sel='A'
#A
if sel=='A':
    N,M=map(int,input().split())
    ans=0
    ans+=M*(M-1)//2
    ans+=N*(N-1)//2
    print(ans)

#B
if sel=='B':
    def ispal(s):
        for i in range(len(s)//2+1):
            if s[i]!=s[-(i+1)]:
                return False
        return True

    S=input()
    if ispal(S) and ispal(S[:(N-1)//2]) and ispal(S[(N+3)//2-1:]):
        print('Yes')
    else:
        print('No')

#C
if sel=='C':
    L=int(input())
    print((L**3)/27)

#D
if sel=='D':    
    N=int(input())
    A=[int(i) for i in input().split()]
    kin=list(set(A))
    cnt={}
    for k in kin:
        cnt[k]=0
    for a in A:
        cnt[a]+=1
    SUM=0
    for k in kin:
        SUM+=cnt[k]*(cnt[k]-1)//2
    for a in A:
        if cnt[a]>=2:
            print(SUM-cnt[a]+1)
        else:
            print(SUM)
        
#E
if sel=='E':
    a=0

#F
if sel=='F':
    N,S=map(int,input().split())
    A=[int(i) for i in input().split()]

    for l in range(N):
        for r in range(l,N):
            print(tab[l][r])

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:
a = list(map(int,input().split()))
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom
x = a[0]
y = a[1]
if(x != 1) and (x != 0):
    c = (combinations_count(x, 2))
else:
    c = 0
if(y != 1) and (y != 0):
    d = (combinations_count(y, 2))
else:
    d = 0
print(c + d)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,m = LI()
    print((n*(n-1)>>1)+(m*(m-1)>>1))
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import itertools
import math

def combinations(N, R):
    return math.factorial(N) // (math.factorial(N- R) * math.factorial(R))

N,M = map(int, input().split())
res= combinations(N+M,2)
print(res - (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))
input_line = input().split()

N = int(input_line[0])
M = int(input_line[1])
counter = 0 
if N > 1:
    counter += combinations_count(N,2) 
if M > 1:
    counter += combinations_count(M,2)
        
print(counter)

Submission status: Accepted

Solution code:
import math
def j(n):
    return 0 if n == 0 or n == 1 else math.factorial(n) // (2*math.factorial(n-2))
n,m = map(int,raw_input().split())
print j(n)+j(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
def P(n,r):
    return math.factorial(n) // math.factorial(n-r)
def C(n,r):
    return P(n,r) // math.factorial(r)
n,m = map(int,input().split())
if n < 2:
    n_len = 0
else:
    n_len = C(n,2)
if m < 2:
    m_len = 0
else:
    m_len = C(m,2)
ans = n_len + m_len
print(ans)

Submission status: Accepted

Solution code:
inputText1 = input()
numberTextList = inputText1.split()
gNumber = numberTextList[0]
kNumber = numberTextList[1]
gNumbers = []
for gNum in range(int(gNumber)):
    gNumbers.append(2)

kNumbers = []
for kNum in range(int(kNumber)):
    kNumbers.append(1)

# print("end")
gNumbers.extend(kNumbers)
allNumbers = gNumbers
allNumbersCount = len(allNumbers)
successCount = 0
for num1 in range(len(allNumbers)):
    for num2 in range(len(allNumbers)):
        if num1 + num2 + 1 == allNumbersCount:
                break
        # print(num1)

        if (allNumbers[num1] + allNumbers[num1 + num2 + 1]) % 2 == 0:
            successCount += 1








print(successCount)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def j(n):
    return math.factorial(n) // (2*math.factorial(n-2))
n,m = map(int,raw_input().split())
if (n == 1 and m == 1)or(n == 0 and m == 0): 
    print 0
elif n == 1 or n == 0:
    print j(m)
elif m == 1 or m == 0:
    print j(n)
else:
    print j(n)+j(m)

Submission status: Accepted

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

s=N*M
m=N+M

d=(m*(m-1))/2

print(int(d-s))