Problem:


Score : 100 points

Problem Statement

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

It is known that:  

The numbers written on N of the balls are even.

The numbers written on M of the balls are odd.

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

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

Constraints

0 \leq N,M \leq 100

2 \leq N+M

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M

Output

Print the answer.

Sample Input 1

2 1

Sample Output 1

1

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

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

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

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

Thus, the answer is 1.

Sample Input 2

4 3

Sample Output 2

9

Sample Input 3

1 1

Sample Output 3

0

Sample Input 4

13 3

Sample Output 4

81

Sample Input 5

0 3

Sample Output 5

3



Sample input:
2 1


Sample output:
1

Submission status: Accepted

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

# 偶数足す偶数
# 奇数たす奇数
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
ans=0
if (n==0 and m>=2):
    ans = ans + combinations_count(m, 2)

elif (n>=2 and m== 0):
    ans = ans + combinations_count(n, 2)
else:
    if (n!=1):
        ans = ans+ combinations_count(n, 2)
    
    if (m != 1):
        ans = ans + combinations_count(m, 2)



print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(b)

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:
def compute_fact(n):
    global f
    if(n < 2):
        f = [1,1]
    else:
        f = [0 for i in range(n+1)]
        f[0] = 1
        f[1] = 1
        for i in range(2,n+1):
            f[i] = f[i-1]*i

def compute_c(n,r):
    compute_fact(n)
    ans = f[n]/(f[r] * f[n-r])
    return ans

n,m = [int(s) for s in input().split()]
if n >= 2 and m >= 2:
    print(int(compute_c(n,2) + compute_c(m,2)))
elif n >= 2:
    print(int(compute_c(n,2)))
elif m >= 2:
    print(int(compute_c(m,2)))
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=map(int,input().split())
print(int(n*(n-1)//2)+int(m*(m-1)//2))

Submission status: Accepted

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

N = input_lst[0]
M = input_lst[1]

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

Submission status: Accepted

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

Submission status: Accepted

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

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

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





if __name__ == "__main__":
	main()

Submission status: Accepted

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

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

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

Submission status: Accepted

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

def comb(n):
  res = (n * (n - 1)) // 2
  return res

print(comb(n) + comb(m))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

a = 0
n,m = map(int,input().split())
if n>=2:
    a += combinations_count(n,2)
if m>=2:
    a += combinations_count(m,2)
print(a)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
arr_n = [(i+1) * 2 for i in range(N)]
arr_m = [i+1 for i in range(0, M*2, 2)]

count = 0
for i in range(len(arr_n)):
    count += len(arr_n[i + 1:])
for j in range(len(arr_m)):
    count += len(arr_m[j + 1:])

print(count)

Submission status: Accepted

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

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 itertools

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

cnt = 0
for v in itertools.combinations(a+b, 2):
    #print(v[0], v[1])
    if (v[0]+v[1]) % 2 == 0:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import math

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

def f(a):
    if a > 1:
        return int(math.factorial(a) / math.factorial(a-2) / 2)
    else:
        return 0

print(f(N) + f(M))

Submission status: Accepted

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

Submission status: Accepted

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

print(int(A))

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

Submission status: Accepted

Solution code:
def comb(val):
    if(val > 0):
        return int(val*(val-1) / 2)
    else:
        return 0

def main():
    args = input().rstrip().split(' ')
    N, M = int(args[0]), int(args[1])
    print(comb(N) + comb(M))
    
if __name__ == "__main__":
    main()

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())
if min(M,N)<=1:
  K=max(M,N)
  print(int(K*(K-1)/2))
else:
  print(int(M*(M-1)/2+N*(N-1)/2))

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
N=i[0]
M=i[1]

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def a(n):
    if n<2: return n
    return n+a(n-1)
sum_=0
if n>1:
    sum_+=a(n-1)
if m>1:
    sum_+=a(m-1)
print(sum_)

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:
even, odd = map(int,input().split())
print((even*~-even // 2) + (odd*~-odd // 2))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M = list(map(int,input().split()))
print(int(N * (N-1) /2 + M * (M-1) / 2))

Submission status: Accepted

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

Submission status: Accepted

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

n=combination(N,2)
m=combination(M,2)
print(n+m)

Submission status: Accepted

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

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:
import math
n,m=map(int,input().split())

print(math.floor(n * (n - 1) / 2) + math.floor(m * (m - 1)/2))

Submission status: Accepted

Solution code:
lin = input().split()
n = int(lin[0])
m = int(lin[1])
np = 0
if n >= 2:
  np = int(n * (n-1) / 2)
op = 0
if m >= 2:
  op = int(m * (m-1) / 2)
print(np+op)

Submission status: Accepted

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

print(a+b)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import factorial

inputted = list(map(int, input().split()))
N = inputted[0]
M = inputted[1]

nPk = lambda n, k: 0 if n - k < 0 else factorial(n) / (factorial(k) * factorial(n - k))

answer = nPk(N, 2) +  nPk(M, 2)
answer = int(answer)

print(answer)

Submission status: Accepted

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

# 入力
n, m = map(int, input().split())

# 主処理
result = int((n * (n-1) / 2) + (m * (m-1) / 2))

# 出力
print(result)

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:
num=input().rstrip().split(" ")
num0=int(num[0])
num1=int(num[1])
print(int(num0*(num0-1)/2+num1*(num1-1)/2))

Submission status: Accepted

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

Submission status: Accepted

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


print('%d' % i)

Submission status: Accepted

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

Submission status: Accepted

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


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


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


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


n,m  = in_ints()
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:
x = input()
s = int(x.split()[0])
t = int(x.split()[1])

s_num = s * (s-1) / (1 * 2)
t_num = t * (t-1) / (1 * 2)
sum = int(s_num + t_num)

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

p = 7+pow(10,9)
def cmb(n,r,p):
    numerator = 1
    for i in range(n-r+1, n+1):
        numerator = numerator * i % p
    denominator = 1
    for i in range(1, r+1):
        denominator = denominator * i % p
    return numerator * pow(denominator, p-2, p) % p

print(cmb(n, 2, p)+ cmb(m,2,p))

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

Submission status: Accepted

Solution code:

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

main()

Submission status: Accepted

Solution code:
import math


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

li = list(map(int, input().split()))
n = li[0]
m = li[1]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = range(1, N, 1)
b = range(1, M, 1)
print(sum(a) + sum(b))

Submission status: Accepted

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

print(int(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
even,odd= map(int,input().split())

n = 0
m = 0

for i in range(1,even):
  n += (even -i)

for _ in range(1,odd):
  m += (odd -_)
  
print(m+n)

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

Submission status: Accepted

Solution code:
# A

import math

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

a = 0

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

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

print(int(a))

Submission status: Accepted

Solution code:
def main():
    even, odd = map(int, input().split())
    cases = 0
    if even >= 2:
        cases += 1
        for i in range(3, even + 1):
            cases = cases - 1 + i
    if odd >= 2:
        cases += 1
        for i in range(3, odd + 1):
            cases = cases - 1 + i

    print(cases)


if __name__ == '__main__':
    main()

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

def kaijyou(k):
  N=1
  for i in range(k,0,-1):
    N*=i
  return N

def combinations(n,r):
  return int(kaijyou(n)/(kaijyou(r)*kaijyou(n-r)))

A=combinations(N,2)+combinations(M,2)
print(A)

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

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

odd = N*M
tama = N + M

import itertools
c = list(itertools.combinations(range(tama),2))

ans = len(c) - odd
print(ans)

Submission status: Accepted

Solution code:
from math import factorial as f
n,m=map(int,input().split())
comb_n=f(n)//(f(2)*f(n-2)) if n>1 else 0
comb_m=f(m)//(f(2)*f(m-2)) if m>1 else 0
print(comb_n+comb_m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if not (N <= 1):
    a = comb(N,2)
else:
    a = 0
if not (M <= 1):
    b = comb(M,2)
else:
    b = 0

    
print(a+b)

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

n,m=map(int,input().split())
if n>=2 and m>=2:print(cmb(n,2)+cmb(m,2))
elif n>=2:print(cmb(n,2))
elif m>=2:print(cmb(m,2))
else:print(0)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = input().split()
n = int(x[0])
m = int(x[1])
if n == 0:
  print(int(m * (m -1) /2))
elif m == 0:
  print(int(n * (n - 1) / 2))
else:
  k = m * (m -1) /2 + n * (n - 1) / 2
  print(int(k))

Submission status: Accepted

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

import math

def comb_cnt(n):
    if n >= 2 : 
        return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
    else : 
        return 0

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

print(comb_cnt(n) + comb_cnt(m))

Submission status: Accepted

Solution code:
# The Number of Even Pairs
# https://atcoder.jp/contests/abc159/tasks/abc159_a

from sys import stdin, stdout

n, m = map(int, stdin.readline().split())
ways = (n * (n - 1) + m * (m - 1)) // 2
stdout.write("%d\n" % ways)

Submission status: Accepted

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

Submission status: Accepted

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

def com(x):
    return int(x * (x - 1) / 2)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(combinations_count(N, 2)+combinations_count(M, 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:
a,b = map(int, input().split(" "))
n = a + b
print(n*(n-1)//2 - b * a)

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations as c
a,b=map(int, input().split())
a=[2*i for i in np.array(range(a))+1]
b=[i*2-1 for i in np.array(range(b))+1]
r=len(list(filter(lambda x:not x&1,np.sum(list(c(a+b, 2)),1)))) 
print(r)

Submission status: Accepted

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

Submission status: Accepted

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

sum_n = 0

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

for i in range(M):
	sum_n = sum_n + i

print(sum_n)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
firstInput=list(map(int,input().split()))
even=firstInput[0]
odd=firstInput[1]
evenSum=0
oddSum=0
if even>=2:
  nFactorial=1
  nMinusKFactorial=1
  for i in range(1,even+1): nFactorial*=i
  for i in range(1,even-1): nMinusKFactorial*=i
  evenSum=nFactorial/(2*nMinusKFactorial)
if odd>=2:
  nFactorial=1
  nMinusKFactorial=1
  for i in range(1,odd+1): nFactorial*=i
  for i in range(1,odd-1): nMinusKFactorial*=i
  oddSum=nFactorial/(2*nMinusKFactorial)
print(int(evenSum+oddSum))

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

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

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

def comb(n):
    if n == 2:
        return 1
    elif n == 1:
        return 0
    elif n > 0:
        return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
    else:
        return 0

print(comb(N)+comb(M))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# number of even balls, number of odd balls
N, M = list(map(int, input().split()))

total_choice = 0

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

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

print(int(total_choice))

Submission status: Accepted

Solution code:
# A - The Number of Even Pairs
# https://atcoder.jp/contests/abc159/tasks/abc159_a

from math import factorial

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

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

combination_count_in_N = combinations_count(N, 2) if N >= 2 else 0
combination_count_in_M = combinations_count(M, 2) if M >= 2 else 0

print(combination_count_in_N + combination_count_in_M)

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()));print((n**2-n)//2+(m**2-m)//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:
#Contest 159
x = input()
N = int(x[:x.index(" ")])
M = int(x[x.index(" ")+1:])
def factorial(number):
	if number>2:
		return number*factorial(number-1)
	elif not number==0:
		return number
	else:
		return 1
def choose2(number):
	if number>=2:
		return factorial(number)/(2*factorial(number-2))
	else:
		return 0

print(int(choose2(N)+choose2(M)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
print(int((m*(m-1))/2) + int((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:
import numpy as np


##get int
first_input = list(map(lambda x:int(x), input().split(" ")))
#second_input = list(map(lambda x:int(x), input().split(" ")))

##get float
#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

N = first_input[0]
M = first_input[1]

num_list = [0]*N+[1]*M

gusu_count = 0
for i in range(len(num_list)):
    for j in range(i+1,len(num_list)):
        if num_list[i]==num_list[j]:
            gusu_count = gusu_count+1

print(gusu_count)

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

print(int(X*(X-1)/2 + Y*(Y-1)/2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 19 11:55:12 2020

@author: 17664
"""
even, odd = map(int, input().split())

print(int((even*(even-1)/2 + odd*(odd-1)/2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(A+B)

Submission status: Accepted

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    print((n * (n - 1) // 2 + (m * (m - 1)) // 2))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def comb(a, b):
  if a < b:
    return 0
  c = fact(a)
  d = fact(b)
  e = fact(a-b)
  return c//(d*e)

def fact(a):
  if a == 0:
    return 1
  return a*fact(a-1)

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

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

x=0
y=0
if N>=2:
    x=combinations_count(N, 2)
if M>=2:
    y=combinations_count(M, 2)

print(x+y)

Submission status: Accepted

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

'''
2 1
'''

# n1 偶数
n1, n2 = map(int, input().split())

# 奇数＋奇数 /  偶数+偶数
print(int(n1 * (n1-1) / 2 + (n2 * (n2-1))/2))

Submission status: Accepted

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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
A = list(map(int, input().split()))
N = A[0]
M = A[1]
 
# 偶数＋偶数
pattern_1 = N*(N-1)/2
 
# 奇数＋奇数
pattern_2 = M*(M-1)/2
 
print(int(pattern_1 + pattern_2))