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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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

def fact(n):
    if n in (0,1):
        return 1
    return n * fact(n-1)

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

Submission status: Accepted

Solution code:
import math

n, m = list(map(int, input().split(" ")))
n_c = 0
m_c = 0

if n >= 2:
  n_c = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
if m >= 2:
  m_c = math.factorial(m) // (math.factorial(m - 2) * math.factorial(2))
  
print(n_c + m_c)

Submission status: Accepted

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

s = n+m

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

print(ans)

Submission status: Accepted

Solution code:
from itertools import combinations

if __name__ == '__main__':
    n, m = tuple([int(s) for s in input().split()])

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


n, m = [0] * 2

def format_input(filename = None):
	global n, m
	if filename == None:
		n, m = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(0, 10**2)
		m = rng(max(0, 2-n), 10**1)

def get_answer():
	answer = m * (m - 1) // 2 + n * (n - 1) // 2
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Accepted

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

if num_list[0] == num_list[1] == 1:
    print(0)

else:
    ans = (num_list[0] * (num_list[0] - 1))/2 + num_list[1] * (num_list[1] - 1) / 2
    print(int(ans))

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


##########
if __name__ == "__main__":
    a()

Submission status: Accepted

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


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


main()

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

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def binary(n):
    return bin(n)[2:]

def pow_w_mod(a, x, mod):  # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % mod
        if x[i] == 1:
            y = (y * a) % mod
    return y
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

def combination(n, r, mod=10**9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res

n, m = map(int, input().split())
#a = combination(n+m, 2, mod=10**9 + 7)

if n < 2:
    b = 0 
else:
    b = combination(n, 2, mod=10**9 + 7)

if m < 2:
    c = 0
else:
    c = combination(m, 2, mod=10**9 + 7)
print(b+c)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

#print(N,M)
comb_N=0
comb_M=0
if N>=2:
  comb_N = (N*(N-1))/2
if M>=2:
  comb_M = (M*(M-1))/2

print(int(comb_N+comb_M))

Submission status: Accepted

Solution code:
import math


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

def comb(x, y):
    if x - y < 0:
        return 0
    return math.factorial(x) // (math.factorial(y) * math.factorial(x - y))


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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
N,M = list(map(int,input().split()))

def comb(n, r):
    if n > 1:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
    else:
        return 0

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

Submission status: Accepted

Solution code:
str = input()

list_in = str.split()

even = int(list_in[0])
odd = int(list_in[1])

num_patterns = (even * (even-1) / 2)
num_patterns += (odd * (odd-1) / 2)

print(int(num_patterns))

Submission status: Accepted

Solution code:
import sys

n, m = map(int, sys.stdin.readline().split())

def main():
    res = n * (n - 1) // 2 + m * (m - 1) // 2
    return res

if __name__ == "__main__":
    ans = main()
    print(ans)

Submission status: Accepted

Solution code:
# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

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

def In():
    return map(int, stdin.readline().split())

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

P = 1000000007
n, m = In()
c = 0
if n > 1:
    c += (n*(n-1))//2
if m > 2:
    c += (m*(m-1))//2
print(c)

Submission status: Accepted

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

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

if N > 1 and M > 1:
	print(cmb(N, 2) + cmb(M, 2))
elif N > 1:
    print(cmb(N, 2))
elif M > 1:
    print(cmb(M, 2))
else:
    print(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = sum(range(n))
ans +=sum(range(m))
print(ans)

Submission status: Accepted

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

import math

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

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
print(sum(range(0,n))+sum(range(0,m)) if 1 < m else sum(range(0,n)))

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

Submission status: Accepted

Solution code:

import math
import itertools
import statistics
n, m = list(map(int, input().split()))
"""
if n%2==0 and m%2==0:
    # 2 4   1 3 5 7
    print((n+m)*(n+m-1)/2)
elif n%2==0 and m%2!=0:
"""



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

Submission status: Accepted

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

n = inputs[0]
m = inputs[1]

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
ev = a[0]
od = a[1]
if (ev==0)and(od==0):
  n = 0
elif ev==0:
  n = a[1]*(a[1]-1)/2
elif od==0:
  n = a[0]*(a[0]-1)/2
else:
  n = a[0]*(a[0]-1)/2+a[1]*(a[1]-1)/2
print(int(n))

Submission status: Accepted

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

N_pair = N * (N-1) / 2
M_pair = M * (M-1) / 2

ans = N_pair + M_pair

print(int(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N > 0 or M > 0:
    a = N - 1
    b = M - 1
else:
    a = 0
    b = 0
print((a * (a + 1)) // 2 + (b * (b + 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
ans = 0
n,m=map(int,input().split())
if n>1:
  ans += cmb(n,2)
if m>1:
  ans += cmb(m,2)
print(ans)

Submission status: Accepted

Solution code:
#


def main():
    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(count)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=input().strip().split(" ")
n,m=[int(n),int(m)]
k=n*(n-1)//2
p=m*(m-1)//2

print(k+p)

Submission status: Accepted

Solution code:
from math import factorial

M, N = [int(x) for x in input().split()]
ans = 0
if M > 1:
    ans += factorial(M) // (factorial(M - 2) * 2)

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)


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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from itertools import combinations 
N, M = map(int, input().split())
ans = len(list(combinations(range(N), 2))) + \
      len(list(combinations(range(M), 2)))
if N == 1 and M == 1:
    print(0)
else:
    print(ans)

Submission status: Accepted

Solution code:
from math import factorial

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

Submission status: Accepted

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

if N<=1:
    countN = 0

    if M <=1:
        countM = 0
    else:
        countM = (M*(M-1))/2


elif N>=2:
    countN = (N*(N-1))/2

    if M <=1:
        countM = 0
    else:
        countM = (M*(M-1))/2

print(int(countN + countM))

Submission status: Accepted

Solution code:
import itertools

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

l = []

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

ll = itertools.combinations(l, 2)

ans = 0
for i in ll:
    if (i[0]+i[1])%2 == 0:
        ans += 1

print(ans)

Submission status: Accepted

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

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

print(X)

Submission status: Accepted

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

Submission status: Accepted

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

nN = N * (N-1) // 2
nM = M * (M-1) // 2

print(nN + nM)

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):
    return math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))

if N >=2:
    a = comb(N)
else:
    a = 0

if M  >=2:
    b = comb(M)
else:
    b = 0

print(a+b)

Submission status: Accepted

Solution code:

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

x = (n*(n-1))/2
y = (m*(m-1))/2

print(int(x+y))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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

x = 0

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

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

Submission status: Accepted

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

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


    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

import math
import sys


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


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


def LS():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()


def S():
    return sys.stdin.buffer.readline().rstrip().decode('utf-8')


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


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


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


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


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


def MSRL(n):
    return [[int(j) for j in list(S())] for i in range(n)]

# ----------------------------------------------------------------


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


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

    if n + m < 2:
        print(0)
        sys.exit

    ans = 0
    if n >= 2:
        ans += combinations_count(n, 2)
    if m >= 2:
        ans += combinations_count(m, 2)

    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
# import numpy as np
from functools import reduce
# import statistics
import decimal
import heapq
import collections
import itertools

sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

x, y = map(int, input().split())

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

ans = 0

ans += combinations_count(x, 2)
ans += combinations_count(y, 2)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3
n,m=map(int,input().split())
# even+even or odd+odd 
nC2 = n* (n-1) /2 
mC2 = m* (m-1) /2 
Ans = nC2 + mC2 
print(int(Ans))

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

Solution code:
import math

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

# 両方ともNから選ぶ
a = 0
if N > 1:
    a = int(math.factorial(N) / (math.factorial(N-2)*2))

# 両方ともMから選ぶ
b = 0
if M > 1:
    b = int(math.factorial(M) / (math.factorial(M-2)*2))

print(a + b)

Submission status: Accepted

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

ans1 = 0
ans2 = 0

if n > 1:
  ans1 = n*(n-1)//2
  
if m > 1:
  ans2 = m*(m-1)//2
  
print(ans1+ans2)

Submission status: Accepted

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

def comb2(x):
    return x * (x - 1) / 2

print(int(comb2(N) + comb2(M)))

Submission status: Accepted

Solution code:
def x(i):
	r = 0
	while i != 0:
		i-=1
		r+= i
	return r

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

Submission status: Accepted

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

a = (N*(N-1))/2
b = (M*(M-1))/2
# print(a)
# print(b)
print(int(a+b))

Submission status: Accepted

Solution code:
import math
n,m = map(int,input().split())
if n < 2 and m <2:
    print(0)
elif n < 2 and m >= 2:
    print((math.factorial(m) // ((math.factorial(2))*(math.factorial(m-2)))))
elif m <2 and n >=2:
    print((math.factorial(n) // ((math.factorial(2))*(math.factorial(n-2)))))
else:
    print((math.factorial(m) // ((math.factorial(2))*(math.factorial(m-2))))+((math.factorial(n) // ((math.factorial(2))*(math.factorial(n-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:
f=[1]
for i in range(1,101):
    f.append(i*f[i-1])

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

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())
res = 0
res += combinations_count(N, 2) if(N >= 2) else 0
res += combinations_count(M, 2) if(M >= 2) else 0
print(res)

Submission status: Accepted

Solution code:
import operator as op
from functools import reduce

def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer // denom

n,m = map(int,input().strip().split())
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(m,2) + ncr(n,2))

Submission status: Accepted

Solution code:
import sys

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

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

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from collections import Counter

input = sys.stdin.readline


def I():
    return int(input())


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


def LI():
    return list(MI())


inf = float("inf")
mod = 10 ** 9 + 7


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=0
d=0
for i in range(a):
    for j in range(i+1,a):
        c+=1
for i in range(b):
    for j in range(i+1,b):
        c+=1
    
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import math


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


A, B = [int(x) for x in stdin.readline().rstrip().split()]
# A,B = [int(x) for x in stdin.readline().rstrip().split()]
# U = stdin.readline().rstrip().split()
# print(S)
if A < 2:
    c = 0
else:
    c = combinations_count(A, 2)
if B<2:
    d=0
else:
    d = combinations_count(B, 2)
print(c+d)

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

x = 0
for i in range(n + m):
    for j in range(n + m):
        if i == j:
            continue
        x1 = i < n
        x2 = j < n
        if (x1 and x2) or (not x1 and not x2):
            x += 1
print(x // 2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

sum = 0
if N==0 or N==1:
	sum+=0
else:
	sum+=(N*(N-1))/2
if M==0 or M==1:
	sum+=0
else:
	sum+=(M*(M-1))/2
print(int(sum))

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 = (int(i) for i in input().split())
print(int(n*(n-1)/2+m*(m-1)/2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    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= int(input())
    M, N = map(int, input().split())
    # A=[0]*N
    # B=[0]*N
    # for i in range(N):
    #     A[i],B[i] = map(int,input().split())
    # for i in range(N):
    #     print(B[i])
    # if N==0 or M == 0:
        
    # else:
    a = cmb(M+N, 2)-M*N
    print(a)
    
main()

Submission status: Accepted

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

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

x = combinations_count(M + N, 2)

print(x - M * N)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
import math

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


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

a = combinations_count(N, 2) if N > 1 else 0
b = combinations_count(M, 2) if M > 1 else 0

print(a + b)

Submission status: Accepted

Solution code:
from scipy.misc import comb
n, m = [int(i) for i in input().split()]

nc2 = comb(n, 2, exact=True)
mc2 = comb(m, 2, exact=True)

print(nc2 + mc2)

Submission status: Accepted

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


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

print(int(a+b))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Ans = conbination_2(N) + conbination_2(M)

print(Ans)

Submission status: Accepted

Solution code:
# class Solution:
#     def solve(self, a, b, c, s):
#         return str(a + b + c) + " " + s


def main():
    inp = lambda: [int(x) for x in input().split()]
    n, m = inp()
    ans = n * (n-1) // 2 + m * (m-1) // 2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

n = N*(N-1)//2

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

ans = n+m

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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())
res=0
if n>1:
    res+=n*(n-1)
if m>1:
    res+=m*(m-1)
print(res//2)

Submission status: Accepted

Solution code:
import math

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

N, M = map(int, input().split())
res = 0
if 2 <= N:
  res += comb(N, 2)
if 2 <= M:
  res += comb(M, 2)
print(res)

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

Submission status: Accepted

Solution code:
import itertools

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

N = [2 for x in range(n)]
M = [1 for x in range(m)]

count = []
for v in itertools.combinations(N + M, 2):
    count.append(sum(v) % 2 == 0)
print(sum(count))

Submission status: Accepted

Solution code:
import numpy as np
a = [int(i) for i in list(input().split())]
b = int((a[0]*(a[0]-1) +a[1]*(a[1]-1))/2)

print(b)

Submission status: Accepted

Solution code:
#!/user/bin/env python3
# -*- conding: utf-8 -*-

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

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

    print(int(ee + oo))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

def cal(x):
    return x*(x-1)//2

print(cal(N)+cal(M))

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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



print(int(a+b))

Submission status: Accepted

Solution code:
from itertools import combinations as comb


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

    n_list = list(range(n))
    m_list = list(range(m))
    n_pair = list(comb(n_list, 2))
    m_pair = list(comb(m_list, 2))
    ans = len(n_pair) + len(m_pair)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N,M = map(int,input().split())
nCr = {}
def cmb(n, r):
    if n == 0:
        return 0
    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)]

a = cmb(N,2)
b = cmb(M,2)
print(a+b)

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

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

Submission status: Accepted

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

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

print(round(answer))

Submission status: Accepted

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

Submission status: Accepted

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

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

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