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

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

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

if N <= 1:
    L = 0
else:
    L = combination_count(N,2)

if M <= 1:
    O = 0
else:
    O = combination_count(M,2) 
    
num = L + O 

print(num)

Submission status: Accepted

Solution code:
import itertools,sys,collections,math,random,fractions,bisect;sys.setrecursionlimit(10**7)
sr = sys.stdin.readline; P = print; P2 = lambda x: print(*x, sep="\n")
def I(i=0): t = [int(x)-i for x in sr().split()];return t
def S(): t = sr().split(); return t if len(t) > 1 else t[0]
L1,L2,L3,L4, = [],[],[],[]
 
N, M = I()
x = itertools.combinations
print(len(list(x(range(N), 2))) + len(list(x(range(M), 2))))

Submission status: Accepted

Solution code:
import math

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


ans_n = 0
if n <= 1:
    ans_n = 0
else:
    ans_n = math.factorial(n)//(math.factorial(n-2)*math.factorial(2))

ans_m = 0
if m <= 1:
    ans_m = 0
else:
    ans_m = math.factorial(m)//(math.factorial(m-2)*math.factorial(2))
print(ans_n+ans_m)

Submission status: Accepted

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

def rc2(i):
  if i<2:
    return 0
  return (i*(i-1))//2
print(rc2(n)+rc2(m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


n, m = map(int, input().split())
c  = 0 if n <= 1 else math.factorial(n)//(2*math.factorial(n-2))
c += 0 if m <= 1 else math.factorial(m)//(2*math.factorial(m-2))
print(c)

Submission status: Accepted

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

a=0 
b=0

# 偶数+偶数
if n==0 or n==1: a==0
else :a=(n*(n-1))/2

if m==0 or m==1: b==0
else :b=(m*(m-1))/2

print(int(a+b))

Submission status: Accepted

Solution code:
import itertools as it

if __name__ == "__main__":
    N, M = map(int, input().split())
    n = len(list(it.combinations(["0" for _ in range(N)], 2)))
    m = len(list(it.combinations(["0" for _ in range(M)], 2)))
    print(n+m)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def n_sum(n):
  x = 1
  ans_sum = 0
  while x <= n:
    ans_sum += x
    x += 1

  return ans_sum


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

new_n = n - 1
new_m = m - 1
print(n_sum(new_n) + n_sum(new_m))

Submission status: Accepted

Solution code:
import itertools

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

nn = [2 for _ in range(0, n)]
mm = [1 for _ in range(0, m)]
nn.extend(mm)

ans = [True for (a, b) in itertools.combinations(nn, 2) if (a + b) % 2 is 0].__len__()
print(ans)

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

Submission status: Accepted

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

def nCr(n, r):
    r = min(r, n-r)
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator

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

Submission status: Accepted

Solution code:
t = input().split()

N = int(t[0])
M = int(t[1])

A = (N * (N -1)) // 2
B = (M * (M -1)) // 2


ans = A + B
print(ans)

Submission status: Accepted

Solution code:
import math
n, m = map(int, input().split())
def comp2(num):
    return math.factorial(num) // (math.factorial(max(num-2, 1)) * 2)
print(comp2(n) + comp2(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:
N,M = map(int,input().split())
al = N + M
souwa = al*(al - 1)/2
ki = N * M
gu = int(souwa - ki)
print(gu)

Submission status: Accepted

Solution code:
# coding: utf-8

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

def npr(n, r):
    a = 1
    while r != 0:
        a *= n
        n -= 1
        r -= 1
    return a

def ncr(n, r):
    return npr(n, r) // npr(r, r)

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

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

Submission status: Accepted

Solution code:
# coding:utf-8
import math

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

N, M = map(int, input().split(' '))
if N <= 1:
    print(0) if M <= 1 else print(N + comb(M, 2))
elif M <= 1:
    print(comb(N, 2))
else:
    print(comb(N, 2) + comb(M, 2))

Submission status: Accepted

Solution code:
import itertools

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

if N == 1 or N == 0:
    a = 0
else:
    a = cmb(N,2)
if M == 1 or M == 0:
    b = 0
else:
    b = cmb(M,2)
print(a+b)

Submission status: Accepted

Solution code:
import math
def nCr(n,r):
    return math.factorial(n) / math.factorial(r) / math.factorial(n-r) if n>1 else 0
N,M=list(map(int,input().split(' ')))
print(int(nCr(N,2)+nCr(M,2)))

Submission status: Accepted

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

ball_numbers = [2 * i for i in range(N)]
ball_numbers.extend([2 * i + 1 for i in range(M)])

count = 0
for i, num1 in enumerate(ball_numbers):
    for j, num2 in enumerate(ball_numbers):
        if i == j:
            continue
        if (num1 + num2) % 2 == 0:
            count += 1
print(count // 2)

Submission status: Accepted

Solution code:
import itertools
n,m=map(int,input().split())
N=[i for i in range(1,n+1)]
M=[i for i in range(1,m+1)]
n_com=itertools.combinations(N,2)
m_com=itertools.combinations(M,2)
print(len(list(n_com))+len(list(m_com)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

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


n = list(itertools.combinations(list(range(N)),2));
m = list(itertools.combinations(list(range(M)),2));

print(len(n) + len(m))

Submission status: Accepted

Solution code:
import sys
# sys.stdin = open('input.txt')

import math

n,m = map(int, input().split())
def c(n):
    return int(math.factorial(n) / math.factorial(n-2) / math.factorial(2))

if n == 1 and m == 1:
    print(0)
elif n <= 1:
    print(c(m))
elif m <= 1:
    print(c(n))
else:
    print(c(n)+c(m))

Submission status: Accepted

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

print(int(ans))

Submission status: Accepted

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

if N >= 3:
  num = sta(N)/(sta(2)*sta(N-2))
if N == 2:
  num = 1
if N <= 1:
  num = 0

if M >= 3:
  mum = sta(M)/(sta(2)*sta(M-2))
if M == 2:
  mum = 1
if M <= 1:
  mum = 0

print(int(num + mum))

Submission status: Accepted

Solution code:

def n(N):
    if N == 0 or N == 1:
        return 0
    else:
        return N * (N - 1) / 2


var = [int(s) for s in input().split()]

N=var[0]
M=var[1]

print(int(n(N) + n(M)))

Submission status: Accepted

Solution code:
a,b=list(map(int,input().split()))
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c=0
if a!=1 and a!= 0:
    c+=comb(a,2)
if b!=1 and b!=0:
    c+=comb(b,2)
print(c)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [0]*n
b = [1]*m
ans = a+b
count = 0
for i in range(0,n+m):
    for j in range(i+1,n+m):
        if (ans[i]+ans[j])%2==0:
            count += 1
print(count)

Submission status: Accepted

Solution code:

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

if n[0] <= 1 and n[1] <= 1:
    print(0)
else:
    ans = 0
    for i in range(n[0]):
        ans += i
    for i in range(n[1]):
        ans += i
    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(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def tmp(n):
    return n * (n - 1) / 2


def main():
    line = input().strip()
    n, m = [int(v) for v in line.split(' ')]

    ans_n = tmp(n) if n > 1 else 0
    ans_m = tmp(m) if m > 1 else 0
    ans = ans_n + ans_m
    print(int(ans))


if __name__ == '__main__':
    main()

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:
from math import factorial as f
x,y=map(int,input().split())
if(x<2):
    a=0
else:
    a=f(x)//(f(x-2)*2)
if(y<2):
    b=0
else:    
    b=f(y)//(f(y-2)*2)
print(a+b)

Submission status: Accepted

Solution code:
import math

n,m = map(int, input().split())
n_p = 0
if 2 <= n:
    n_p = math.factorial(n) // (2*(math.factorial(n-2)))

m_p = 0
if 2 <= m:
    m_p = math.factorial(m) // (2*(math.factorial(m-2)))

print(n_p + m_p)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def calcPair(ballNum):
    if ballNum -1 <= 0:
        return 0
    else:
        return int(ballNum * (ballNum -1) / 2)

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

Submission status: Accepted

Solution code:
from math import factorial

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

if n > 2 and m > 2:
    print(
        factorial(n) // (factorial(n - 2) * factorial(2))
        + factorial(m) // (factorial(m - 2) * factorial(2))
    )
elif n < 2 and m < 2:
    print(0)
elif n < 2:
    print(factorial(m) // (factorial(m - 2) * factorial(2)))
elif m < 2:
    print(factorial(n) // (factorial(n - 2) * factorial(2)))

Submission status: Accepted

Solution code:
import sys
import math

n, m = [int(s) for s in sys.stdin.readline().strip().split()]

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

Submission status: Accepted

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

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

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

print(int(p))

Submission status: Accepted

Solution code:
def comb(n, r):
    nc = n
    for rc in range(1, r):
        nc -= 1
        n = n*nc
        r = r*rc

    return n/r


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


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

Submission status: Accepted

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

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

print (a + b)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def fac2(n):
    if n < 2:
        return 0
    ans = n * (n-1) //2
    return ans



N, M = map(int, input().split())
print(fac2(N) + fac2(M))

Submission status: Accepted

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

Submission status: Accepted

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

n_even2 = N * (N-1) / 2
n_odd2 = M * (M-1) / 2

print(int(n_even2+n_odd2))

Submission status: Accepted

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

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

b = M * N

print(int(a - b))

Submission status: Accepted

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

result = 0
if (N < 2 and M < 2):
  result = 0
else:
  a = N*(N-1)//2
  b = M*(M-1)//2
  result = a + b

print(result)

Submission status: Accepted

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

print(len(list(combinations(range(n),2))) + len(list(combinations(range(m),2))))

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:
val = input().split(' ')
n = int(val[0])
m = int(val[1])

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

print(int(result))

Submission status: Accepted

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

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

print(n+m)

Submission status: Accepted

Solution code:
from math import factorial

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

comb_n = 0
comb_m = 0

if n > 1:
    comb_n = (factorial(n) // factorial(n - 2)) // factorial(2)

if m > 1:
    comb_m = factorial(m) // factorial(m - 2) // factorial(2)

print(comb_n + comb_m)

Submission status: Accepted

Solution code:
import itertools
import math

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

N, M = list(map(int, input().strip().split()))
# NC2 + MC2
print(combinations_count(N, 2) + combinations_count(M, 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

even,odd = map(int,input().split())
if even != 1 or odd != 1:
    numa = cmb(even,2)
    numb = cmb(odd,2)
    if even == 1 or even == 0:
        numa = 0
    if odd == 1 or odd == 0:
        numb = 0
    print(numa+numb)
else:
    print(0)

Submission status: Accepted

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


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


def main(n, m):
    cnt = 0

    if m <= 1:
        cnt += n * (n - 1) / 2
    else:
        cnt += n * (n - 1) / 2
        cnt += m * (m - 1) / 2

    return int(cnt)


print(main(N, M))

Submission status: Accepted

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

sum = 0
sum2 = 0
for i in range(m):
    sum += i

for i in range(n):
    sum2 += i

print(sum + sum2)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

N, M = read_ints()
# ぐぐ→き
# きぐ→き
# きき→ぐ

# 偶数と奇数を選ぶ数を全体から引けば良い

tmp = [2] * N + [1] * M
ans = 0
for a, b in combinations(tmp, r=2):
    ans += (a + b) % 2 == 0
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

n = math.factorial(N) // (math.factorial(N - 2) * math.factorial(2)) if N > 1 else 0
m = math.factorial(M) // (math.factorial(M - 2) * math.factorial(2)) if M > 1 else 0

print(n + m)

Submission status: Accepted

Solution code:
import math

a = [int(x) for x in input().split(" ")]
n = a[0]
m = a[1]
ans = 0
if n >= 2 :
    ans += math.factorial(n) // (2 * math.factorial(n - 2))
if m >= 2 :
    ans += math.factorial(m) // (2 * math.factorial(m - 2))
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')

N, M = MI()

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

Submission status: Accepted

Solution code:
import math

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

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

if nums[0] <= 1 and nums[1] <= 1:
  print(0)
elif nums[1] <= 1:
  print(comb(nums[0], 2))
elif nums[0] <= 1:
  print(comb(nums[1], 2))
else:
  print(comb(nums[0], 2) + comb(nums[1], 2))

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
n = a[0]
m = a[1]

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial

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

if a <= 1 and b <= 1:
    print(0)
    exit()
if a < 2:
    result = combinations_count(b,2)
elif b < 2:
    result = combinations_count(a,2)
elif b > 1:
    result = combinations_count(a,2) + combinations_count(b,2)
else:
    result = combinations_count(a,2)
print(result)

Submission status: Accepted

Solution code:
import math

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

def combinations_count(n, r):

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

print(combinations_count(a, 2) + combinations_count(m, 2))

Submission status: Accepted

Solution code:
#A - The Number of Even Pairs
N,M= map(int, input().split())

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if n >= 2:
    odd = math.factorial(n) // math.factorial(n-2) // 2
else:
    odd = 0
if m >= 2:
    even = math.factorial(m) // math.factorial(m-2) // 2
else:
    even = 0

print( odd + even )

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = list(map(int, input().split()))
n = s[0]
m = s[1]

total = 0

#偶数+偶数
total += n * (n-1) / 2

#奇数+奇数
total += m * (m-1) / 2

print(int(total))

Submission status: Accepted

Solution code:
import math
import sys 
n,m = map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
cnt = 0
# 奇数+奇数
if n>=2:
    cnt += combinations_count(n,2)
# 偶数*偶数
if m>=2:
    cnt += combinations_count(m,2)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def combination_2(n):
    if n < 2:
        return 0
    else:
        return int(n * (n - 1) / 2)


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

print(combination_2(n)+combination_2(m))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if M>=2:
  b = factorial(M) / factorial(2) / factorial(M - 2)

print(int(a+b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python

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

a = 0
if n < 0:
    a += 0
else:
    a += (n * (n-1) // 2)

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

print(a)

Submission status: Accepted

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

# 偶偶　奇奇
ans = int(N * (N - 1) // 2) + int(M * (M - 1) // 2)
print(int(ans))

Submission status: Accepted

Solution code:
import math
N, M = map(int, input().split())
if N >= 2:
  pn = math.factorial(N) // math.factorial(N - 2)
else:
  pn = 0
if M >= 2:
  pm = math.factorial(M) // math.factorial(M - 2)
else:
  pm = 0
total = pn // 2 + pm // 2
print(total)

Submission status: Accepted

Solution code:
data = input().split(" ")
 
N = int(data[0])
M = int(data[1])
 
ans = N*(N-1)/2
ans += M*(M-1)/2
 
print(int(ans))

Submission status: Accepted

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

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

total = int(total)

print(total)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

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


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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)

n,m = map(int,input().split())
a = n - 1
b = m - 1
ans = 0

if m <= 1:
    ans = n*a/2
else:
    ans = n*a/2 + m*b/2

print(str(int(ans)))

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))
base1 = 0
base2 = 0
if n >= 2:
    base1 = comb(n,2)
if m >= 2:
    base2 = comb(m,2)
ans = base1 + base2
print(ans)

Submission status: Accepted

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

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import itertools
L, R = map(int,input().split())
a = len(list(itertools.combinations(range(L), 2))) + len(list(itertools.combinations(range(R), 2)))
print(a)

Submission status: Accepted

Solution code:
nm = input("")
n = int(nm.split(' ')[0])
m = int(nm.split(' ')[1])

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def fac(x):
    a=1
    for i in range(2,x+1):
        a*=i
    return(a)
def npr(x,x1):
    return fac(x)//(fac(x-x1)*fac(x1))
n,m=map(int,input().split())
ans=npr(n,2)+npr(m,2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

a1 = n * (n-1) // 2
a2 = m * (m-1) // 2

a1 = max(0, a1)
a2 = max(0, a2)

print(a1 + a2)

Submission status: Accepted

Solution code:
from math import factorial

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


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

answer = 0

if N >= 2:
  answer += comb(N, 2)
else:
  answer += 0

if M >= 2:
  answer += comb(M, 2)
else:
  answer += 0

print(int(answer))

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:
dat = list(map(int,input().split(' ')))
n=dat[0]
m = dat[1]

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