Problem:


Score : 100 points

Problem Statement

We have N+M balls, each of which has an integer written on it.

It is known that:  

The numbers written on N of the balls are even.

The numbers written on M of the balls are odd.

Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even.

It can be shown that this count does not depend on the actual values written on the balls.

Constraints

0 \leq N,M \leq 100

2 \leq N+M

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

2 1

Sample Output 1

1

For example, let us assume that the numbers written on the three balls are 1,2,4.

If we choose the two balls with 1 and 2, the sum is odd;

If we choose the two balls with 1 and 4, the sum is odd;

If we choose the two balls with 2 and 4, the sum is even.

Thus, the answer is 1.

Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3



Sample input:
2 1


Sample output:
1

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
M,N = map(int, input().split())
A = 0
B = 0
C = M
D = 0
E = 0
F = N
while A < C:
    B += M -1
    M -= 1
    A += 1

while D < F:
    E += N -1
    N -= 1
    D += 1
print(B + E)

Submission status: Accepted

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

from operator import mul
from functools import reduce

def bb(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 m==1 and n==1:
    print(0)
    exit()

if m>1 and n>1:
    print(bb(n,2)+bb(m,2))
elif m>1:
    print(bb(m,2))
else:
    print(bb(n,2))

Submission status: Accepted

Solution code:
import itertools
e, o = map(int, input().split())
new = []
for x in range(1, e+1):
    new.append(2*x)
for x in range(1, o*2):
    if x%2==1:
        new.append(x)
counter = 0
for x in itertools.combinations(new, 2):
    if int(x[0]+x[1]) %2 == 0:
        counter +=1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
A,B = list(map(int,input().split()))
import math
if A == 0 and B != 0:
  D = math.factorial(B-2)
  F = math.factorial(B) // 2// D
  print(F)
  exit()
if A != 0 and B == 0:
  C = math.factorial(A-2)
  E = math.factorial(A) // 2// C
  print(E)
  exit()
if A == 0 and B == 0:
  print(0)
  exit()
elif A == 1 and B != 1:
  D = math.factorial(B-2)
  F = math.factorial(B) // 2// D
  print(F)
  exit()
elif A != 1 and B == 1:
  C = math.factorial(A-2)
  E = math.factorial(A) // 2// C
  print(E)
  exit()
elif A == 1 and B == 1:
  print(0)
  exit()
C = math.factorial(A-2)
D = math.factorial(B-2)
E = math.factorial(A) // 2// C
F = math.factorial(B) // 2// D
print(E+F)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc152/tasks/abc152_a
n, m = map(int, input().split())
n_total_perm = 1
m_total_perm = 1
for j in range(n,n-2,-1):
    n_total_perm *= j

for k in range(m,m-2,-1):
    m_total_perm *= k

total_even = int((n_total_perm/2) + (m_total_perm/2))
#if n < 2:
#    total_even = 0

print(total_even)

Submission status: Accepted

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

a = len(list(itertools.combinations(range(N), 2)))
b = len(list(itertools.combinations(range(M), 2)))
print(a + b)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
s=0
if(n>=2):
  for i in range(n):
    s+=i
    
if(m>=2):
  for i in range(m):
    s+=i
print(s)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
 
def cmb(n,r):
    if r > n:
        return 0
    if r == 0 or r == n:
        return 1
    if r == 1:
        return n
    return cmb(n-1,r) + cmb(n-1,r-1)
 
ret = cmb(N,2) + cmb(M,2)
print(ret)

Submission status: Accepted

Solution code:
import math
a,b=map(int, input().split())
answer = 0

if a > 1 :
    answer += math.factorial(a) / (math.factorial(a - 2)*2)

if b > 1:
    answer += math.factorial(b) / (math.factorial(b - 2)*2)

print(int(answer))

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
def combinations(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


N, M = map(int, input().split())
result = 0
if N >= 2:
    result += combinations(N, 2)
if M >= 2:
    result += combinations(M, 2)
print(int(result))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7


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


def inpl(): return list(map(int, sys.stdin.readline().split()))


def inpl_str(): return list(sys.stdin.readline().split())


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

Submission status: Accepted

Solution code:
from itertools import combinations

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

a = list(combinations(range(N), 2))
b = list(combinations(range(M), 2))
print(len(a)+len(b))

Submission status: Accepted

Solution code:
import math
N,M =map(int,input().split())
if N==1 :
    N1=0
elif N==0:
    N1=0
else:
    N1=(math.factorial(N))//(math.factorial(N-2)*2)
    
if M==1:    
    M1=0
    
elif M ==0:
    M1=0
else:
    M1=(math.factorial(M))//(math.factorial(M-2)*2)
    
print(str(N1+M1))

Submission status: Accepted

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

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

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

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

    print(M_number)

else:
    N_number=combinations_count(N, 2)
    M_number=combinations_count(M, 2)

    print(N_number+M_number)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def comb2(n):
    return int(n*(n-1)/2)

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

print(comb2(n)+comb2(m))

Submission status: Accepted

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

for i in range(N):
    con += i

for j in range(M):
    con += j

print(con)

Submission status: Accepted

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


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

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

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(s) for s in input().split(" ")]
Ans1=M*(M-1)/2
Ans2=N*(N-1)/2
print(int(Ans1+Ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def comb(a):
    if a < 2:
        return 0
    else:
        return a * (a-1) // 2


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

Submission status: Accepted

Solution code:
import math


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



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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

x+= a[1] * (a[1]-1) * (1/2)

print(int(x))

Submission status: Accepted

Solution code:
import itertools


def pattern_sum_is_even_number(input_n, input_m):
    even_num = [i*2 for i in range(1, input_n+1)]
    odd_num = [i*2+1 for i in range(1, input_m+1)]

    even_num.extend(odd_num)
    all_num_combination = itertools.combinations(even_num, 2)
    sum_is_even_combinations = 0
    for n in all_num_combination:
        if (n[0] + n[1]) % 2 == 0:
            sum_is_even_combinations += 1
    return sum_is_even_combinations


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(pattern_sum_is_even_number(n, m))

Submission status: Accepted

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

ans = 0
for i in range(N):
    ans += i
if M == 1:
  pass
  
  
    
    
else:
  for _ in range(M):
      ans += _

print(ans)

Submission status: Accepted

Solution code:
def nCr(n, r): 
	return (fact(n) // (fact(r) 
				* fact(n - r))) 

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

n,m=map(int,input().split())
if(n==1 and m!=1):
  print(nCr(m,2))
elif(n!=1 and m==1):
  print(nCr(n,2))
elif(n==1 and m==1):
  print("0")
else:
  print(int(nCr(n,2)+nCr(m,2)))

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
def comb(x):
    return x*(x-1)/2

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

Submission status: Accepted

Solution code:

import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline



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


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """
    if n<r:
        return 0
    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator


N,M=acinput()

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

Submission status: Accepted

Solution code:
import math
n = input().split(' ')
s = [int(s) for s in n]
def combination(x):
    if x >= 2:
        return math.factorial(x) // (math.factorial(x - 2) * math.factorial(2))
    else:
        return 0
print(combination(s[0]) + combination(s[1]))

Submission status: Accepted

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

Submission status: Accepted

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

o=1
while o<=m*2:
    if o%2!=0:
        l.append(o)

    o+=2


e=2
while e<=n*2:
    if e%2==0:
        l.append(e)

    e+=2


re=0


for i in range(0,len(l)):
    j=i+1
    while j<len(l):
        s=l[i]+l[j]
        if s%2==0:
            re+=1
            

        j+=1

print(re)

Submission status: Accepted

Solution code:
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#coding:utf-8
import itertools

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

ansN = len(list(itertools.combinations(range(N), 2)))
ansM = len(list(itertools.combinations(range(M), 2)))

ans = ansN + ansM
print(ans)

Submission status: Accepted

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

cnt_even = (N*(N-1))/2
cnt_odd = (M*(M-1))/2
cnt = int(cnt_even + cnt_odd)

print(cnt)

Submission status: Accepted

Solution code:
import sys
from math import factorial
input = sys.stdin.readline

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

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

# 偶数＆偶数
if n > 2:
    ans1 = factorial(n) / factorial(2) / factorial(n - 2)
elif n == 2:
    ans1 = 1
elif n <= 1:
    ans1 = 0

# 奇数 & 奇数
if m > 2:
    ans2 = factorial(m) / factorial(2) / factorial(m - 2)
elif m == 2:
    ans2 = 1
elif m <= 1:
    ans2 = 0

print(int(ans1 + ans2))

Submission status: Accepted

Solution code:
import math


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

ans_N=0
ans_M=0
if N != 0:
	ans_N=(N*(N-1))//2
if M != 0:
	ans_M=(M*(M-1))//2

print(ans_N+ans_M)

Submission status: Accepted

Solution code:
import math

data = input()
data = data.split()
n = data[0]
m = data[1]
v1 = 0
v2 = 0

if int(n) > 1:
	v1 = (math.factorial(int(n)) // (math.factorial(int(n) - 2) * math.factorial(2)))

if int(m) > 1:
    v2 = (math.factorial(int(m)) // (math.factorial(int(m) - 2) * math.factorial(2)))

print(v1+v2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial

x,y=map(int,input().split())
if x>1:
    a = factorial(x) / factorial(2) / factorial(x - 2)
else: a=0
if y>1:
    b = factorial(y) / factorial(2) / factorial(y - 2)
else: b=0
print(int(a+b))

Submission status: Accepted

Solution code:
from itertools import combinations

N, M = [int(n) for n in input().split()]
print(len([c for c in combinations(range(N), 2)])+len([c for c in combinations(range(M), 2)]))

Submission status: Accepted

Solution code:
guusuu, kisuu = map(int, input().split())
guusuuhairetu = [i for i in range(2, guusuu * 2 + 1, 2)]
kisuuhairetu = [i for i in range(1, kisuu * 2, 2)]
count = 0
haiiretu = guusuuhairetu + kisuuhairetu
hairetu2 = guusuuhairetu + kisuuhairetu
for i in hairetu2:
    haiiretu.remove(i)
    for u in haiiretu:
        if (i + u) % 2 == 0:
            count += 1
print(count)

Submission status: Accepted

Solution code:
from itertools import combinations

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

a = list(combinations(range(N), 2))

b = list(combinations(range(M), 2))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def cmb(n, r):
    if n < r:
        return 0
    a = 1
    for i in range(n, n - r, -1):
        a *= i
    b = 1
    for i in range(1, r + 1):
        b *= i
    return int(a / b)


N, M = [int(i) for i in input().split()]
ans = cmb(N, 2) + cmb(M, 2)

print(ans)

Submission status: Accepted

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

def cal(x):
	if x < 2:
		return 0
	else:
		x = x*(x-1) // 2
		return x

ans = cal(n) + cal(m)
print(ans)

Submission status: Accepted

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

ans = 0
for i in range(1,n):
    ans += i

if m > 1:
    for i in range(1,m):
        ans += i
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

if math.factorial(M)!=1:
  cnt+=math.factorial(M)//(2*math.factorial((M-2)))

print(cnt)

Submission status: Accepted

Solution code:
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

def re(n):
  if n < 2:
    return 1
  return n*re(n-1)

def c(n,r):
  return re(n)//re(n-r)//2

a,b = miinps()

ans = 0

ans += c(a,2)
ans += c(b,2)

print(ans)

Submission status: Accepted

Solution code:
k=0
import math
def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
a,b=map(int,input().split())
if b<2:
    if b==1:
        j=0
    else:
        j=b
else:
    j=combinations_count(b, 2)
for i in range(a):
    k=k+i
h=j+k
print(h)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#スペース区切りの整数の入力
N,M = map(int, input().split())

ans_n = 0
if(N < 2):
  ans_n = 0
else:
  for i in range(N-1):
    ans_n = (i+1) + ans_n
    #print(ans_n)
  
ans_m = 0
if(M < 2):
  ans_m = 0
else:
  for i in range(M-1):
    ans_m = (i+1) + ans_m
    #print(ans_m)
  
print(ans_n+ans_m)

Submission status: Accepted

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

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

print(odd + even)

Submission status: Accepted

Solution code:
from itertools import combinations

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

def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    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 and not M <= 1:
    print(nCr(M,2))
elif not N <= 1 and M <= 1:
    print(nCr(N,2))
else:
    print(nCr(N, 2) + nCr(M,2))

Submission status: Accepted

Solution code:
from itertools import combinations
MOD = 10**9+7
nn, m = map(int, input().split())
def nCr(n, r, mod):
	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
ansn = 0
if nn < 2:
	ansn = 0
else:
	ansn = nCr(nn,2,MOD)
if m < 2:
	ansm = 0
else:
	ansm = nCr(m,2,MOD)

print (ansn + ansm)

Submission status: Accepted

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

odd = [i for i in range(1, M*2+2, 2)]
even = [i for i in range(2, N*2+2, 2)]

for k in range(M):
  ans = ans + k

for g in range(N):
  ans = ans + g
print(ans)

Submission status: Accepted

Solution code:
#スペース区切りの整数入力
N, M  = map(int, input().split())


if N >= 2:
    N_even = N*(N - 1)/2
else:
    N_even = 0

if M >= 2:
    M_even = M*(M-1)/2
else:
    M_even = 0

print(int(N_even + M_even))

Submission status: Accepted

Solution code:
import itertools
n,m = map(int,input().split())
o = 0
o += len(list(itertools.permutations([i for i in range(n)], 2)))/2
o += len(list(itertools.permutations([i for i in range(m)], 2)))/2
print(int(o))

Submission status: Accepted

Solution code:
import math

def resolve():

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

    nc=0
    mc=0
    if n >=2:
        nc=math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
    if m>=2:
        mc=math.factorial(m) // (math.factorial(m - 2) * math.factorial(2))

    print(nc+mc)

resolve()

Submission status: Accepted

Solution code:
import math


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

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

total = nCr(N,2) + nCr(M,2)

print(total)

Submission status: Accepted

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


if N!=0:
  for i in range(1,N+1):
    l_n.append(i*2)
else:
  l_n.append(0)


if M!=0:
  now=1
  for i in range(M):
    l_m.append(now)
    now+=2
else:
  l_m.append(0)

now_n=0
now_m=0
cnt=0

# print(l_n)
if N==0 and M==0:
  print(0)
else:
  for i in range(len(l_n)):
    for j in range(len(l_n)):
      if i<j:
        now_n=l_n[i]+l_n[j]
        if now_n%2==0:
          cnt+=1


if N==0 and M==0:
  print(0)
else:
  for i in range(len(l_m)):
    for j in range(len(l_m)):
      if i<j:
        now_m=l_m[i]+l_m[j]
        if now_m%2==0:
          cnt+=1
  print(cnt)

Submission status: Accepted

Solution code:
N,M=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

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

Submission status: Accepted

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

l_n = [i for i in range(1, n+1)]
l_m = [i for i in range(1, m+1)]


print(len([k * j for i, k in enumerate(l_n) for j in l_n[i + 1:]]) 
    + len([k * j for i, k in enumerate(l_m) for j in l_m[i + 1:]]))

Submission status: Accepted

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

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    solver()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def cmb(n, r):
    if n<2:
        return 0

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

def main():
    import sys
    N,M=list(map(int,sys.stdin.readline().split()))
    print(cmb(M,2)+cmb(N,2))


main()

Submission status: Accepted

Solution code:
import itertools
n, m = [int(i) for i in input().split()]
a = []
num = 1
for i in range(1, n+1):
  a.append(i*2)
for i in range(1, m+1):
  a.append(num)
  num = num + 2
c = []
c = list(itertools.combinations(a, 2))
goukei = 0
for i in range(len(c)):
  if sum(c[i]) % 2 == 0:
    goukei += 1
print(goukei)

Submission status: Accepted

Solution code:
import numpy as np

NM=np.array(input().split(" "),dtype=np.int64)

N=NM[0]
M=NM[1]

result=0

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

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

print(int(result))

Submission status: Accepted

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

for i in range(n):
  l.append(2)
for i in range(m):
  l.append(1)

for v in itertools.combinations(l, 2):
  if sum(v)%2 == 0:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N,M=map(int,input().split())
c=0
for (a,b) in itertools.combinations(list(range(2,201,2))[:N]+list(range(1,200,2))[:M],2):
    c += 1 if (a+b)%2==0 else 0
print(c)

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:
import itertools
n, m = map(int, input().split())
n = list(itertools.combinations(range(n), 2))
m = list(itertools.combinations(range(m), 2))
print(len(n) + len(m))

Submission status: Accepted

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



print(int(n_count+m_count))