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())
print(n*~-n+m*~-m>>1)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
# ue,sita,uee,sitaa = 0,0,0,0
# tmpN,tmpM = 0,0
# if N != 2:
#     for i in range(N+1):
#         ue *= N-i
#         sita *= N-2-i
#     tmpN = ue/sita
# if M != 2:
#     for i in range(M+1):
#         uee *= N-i
#         sitaa *= N-2-i
#     tmpM = uee/sitaa

# print(tmpN+tmpM)

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
p = ['P']*n
k = ['I']*m
al = p+k
ans = 0
for i in range(len(al)):
    for j in range(i+1,len(al)):
        if al[i] == 'I' and al[j]=='I':ans+=1
        if al[i] == 'P' and al[j] == 'P': ans+=1
print(ans)

Submission status: Accepted

Solution code:
import itertools
N, M = map(int, input().split())
print( len([i for i in list(itertools.combinations(([2]*N)+([3]*M), 2)) if sum(i) % 2 == 0]) )

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, M = LI()

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

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

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


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


print(choice(a, 2) + choice(b, 2))

Submission status: Accepted

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

def comb(num,k):
    if num<2:
        return 0
    return math.factorial(num)/(math.factorial(k)*math.factorial(num-k))

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

print(ans)

Submission status: Accepted

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

import math
print(math.comb(N, 2)+math.comb(M, 2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from scipy.special import comb
m,n = map(int,input().split())
print(int(comb(m,2)+comb(n,2)))

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

Submission status: Accepted

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

X = N * (N - 1) * (1/2)
Y = M * (M - 1) * (1/2)

print(int(X + Y))

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

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
print(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 = (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 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(ans)

Submission status: Accepted

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

from math import factorial

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

print("{}".format(combination(N, 2) + combination(M, 2)))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

def solve(n):
    if n == 0:
        return 1
    return n * solve(n - 1)

if n <= 1:
    n_ans = 0
else:
    n_ans = solve(n) // (solve(n - 2) * 2)
if m <= 1:
    m_ans = 0
else:
    m_ans = solve(m) // (solve(m - 2) * 2)
ans = n_ans + m_ans
print(ans)

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:
# -*- coding: utf-8 -*-

# combinationを使う

import math

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

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

counter = 0

if n >= 2:
    counter = counter + comb(n, 2)

if m >= 2:
    counter = counter + comb(m, 2)

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import scipy.misc
N, M = map(int, input().split())
ansN = 0
ansM = 0
if N != 1:
    ansN = N*(N-1)/2
if M != 1:
    ansM = M*(M-1)/2
ans = int(ansN+ansM)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    N,M=map(int,input().split())
    if N>=2 and M>=2:
        print((N*(N-1))//2+(M*(M-1)//2))
    elif N>=2:
        print((N*(N-1))//2)
    elif M>=2:
        print((M*(M-1)//2))
    else:
        print(0)
            
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

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

if (n>1)&(m>1):
	print(combinations_count(n, 2)+combinations_count(m, 2))
elif n>1:
    print(combinations_count(n, 2))
elif m>1:
    print(combinations_count(m, 2))
else:
    print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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 itertools
import functools
import math
from collections import Counter
from itertools import combinations

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

ans = 0
if N >= 2:
    ans += len(list(itertools.combinations(range(N), 2)))
if M >= 2:
    ans += len(list(itertools.combinations(range(M), 2)))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
if N < 2:
    A = 0
else:
    A = int(N * (N - 1) / 2)
if M < 2:
    B = 0
else:
    B = int(M * (M - 1) / 2)

print(A + B)

Submission status: Accepted

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

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

if n == 1 or n == 0:
  a = 0
else:
  a = int(n*(n-1)/2)

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

print(a+b)

Submission status: Accepted

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

if N < 2:
  A = 0
else:
  A = int(N*(N-1)/2)
if M < 2:
  B = 0
else:
  B = int(M*(M-1)/2)

print(A+B)

Submission status: Accepted

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

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

print(int(x))

Submission status: Accepted

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

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

print(choose_2(n) + choose_2(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 = [int(i) for i in input().split()]
p = ['P']*n
k = ['I']*m
al = p+k
ans = 0
for i in range(len(al)):
    for j in range(i+1,len(al)):
        if al[i] == 'I' and al[j]=='I':ans+=1
        if al[i] == 'P' and al[j] == 'P': ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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<=1) and (B<=1)):
    print(0)
    exit()
if (B<=1):
    print(combinations_count(A,2))
    exit()
if (A<=1):
    print(combinations_count(B,2))
    exit()
print(combinations_count(A,2)+combinations_count(B,2))

Submission status: Accepted

Solution code:
# ----------- gcd ----------- #
def gcd(x, y):
    k, l = x, y
    if y < 0:
        k, l = -k, -l
    while l:
        k, l = l, k % l
    return k
    
def extgcd(a, b, c):
    if b == 0:
        return c // a, 0
    if b < 0:
        a, b, c = -a, -b, -c
    x, y, u, v, k, l = 1, 0, 0, 1, a, b
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return c * x, c * y

# --------- IsPrime --------- #
def IsPrime(n):
    if n == 1:
        return False
    p = 2
    while p * p <= n:
        if n % p == 0:
            return False
        p += 1
    return True

# --- fraction calculator --- #
def fracsum(f1, f2, sign = 1):
    fs = [f1[0]*f2[1]+sign*f1[1]*f2[0], f1[1]*f2[1]]
    g = gcd(fs[0], fs[1])
    fs[0] //= g
    fs[1] //= g
    return fs
def fracprod(f1, f2):
    fs = [f1[0]*f2[0], f1[1]*f2[1]]
    g = gcd(fs[0], fs[1])
    fs[0] //= g
    fs[1] //= g
    return fs

# ------ factorization ------ #
def factorization(n):
    D = {}
    a = n
    p = 2
    while a != 1:
        cnt = 0
        while a % p == 0:
            cnt += 1
            a //= p
        if cnt != 0:
            D[p] = cnt
        p += 1
        if p * p > n and a != 1:
            D[a] = 1
            break
    return D
def divisors_list(D):
    F = [1]
    for i in D:
        mL = F[:]
        dp = i
        for j in range(D[i]):
            for k in mL:
                F.append(dp*k)
            dp *= i
    F.sort()
    return F

def doubling(n, m, modulo=0):
    y = 1
    base = n
    tmp = m
    while tmp:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo
def bic(n): # count time divided by 2
    cnt = 0
    while n % 2 == 0:
        cnt += 1
        n //= 2
    return cnt
def powlimit(n):
    y = 1
    cnt = 0
    while y < n:
        y *= 2
        cnt += 1
    return y, cnt
def CRT(n, a, b): # x = a[i] mod b[i]
    r = a[0]
    bas = b[0]
    x, y = 0, 0
    for i in range(1, n):
        x, y = extgcd(bas, -b[i], a[i] - r)
        r += bas * x
        bas *= b[i]
    return r % bas

# making lists of mod and prim. root
def mod_maker(cnt, num):
    bin_list = [1 for _ in range(cnt+1)]
    for i in range(cnt, 0, -1):
        bin_list[i-1] = 2*bin_list[i]
    L = []
    pm = []
    bas = doubling(2, cnt)
    ccnt = 0
    j = 1
    while ccnt < num:
        if IsPrime(j*bas+1):
            x = j*bas+1
            L.append(j*bas+1)
            ccnt += 1
            st = 1
            flg = 0
            while not flg:
                flg = (doubling(st, bin_list[0], x) == 1)
                for k in range(cnt):
                    flg *= (doubling(st, bin_list[k+1], x) != 1)
                if flg:
                    pm.append(st)
                    break
                st += 1
        j += 2
    return L, pm

def NTT(f, n, cn, num, inverse=False):
    if n == 1:
        return f
    if n == 2:
        return [(f[0]+f[1])%mod[num], (f[0]-f[1])%mod[num]]
    dn = n // 2
    fe = [f[2*i+0] for i in range(dn)]
    fo = [f[2*i+1] for i in range(dn)]
    fe = NTT(fe, dn, cn-1, num, inverse)
    fo = NTT(fo, dn, cn-1, num, inverse)
    seed = inverse * prim[num][cn] + (1 - inverse) * invp[num][cn]
    grow = 1
    xf = [0 for _ in range(n)]
    for i in range(dn):
        right = fo[i] * grow % mod[num]
        xf[i+0*dn] = (fe[i] + right) % mod[num]
        xf[i+1*dn] = (fe[i] - right) % mod[num]
        grow *= seed
        grow %= mod[num]
    return xf

# ----------- NTT test zone ----------- #
N, M = map(int, input().split())
A = [N, M]
n = 2
pl, bn = powlimit(2*n+2)
A = A[:] + [0]*(pl-n)
convolution_time = 2 # convolution level (number of 'mod's)
binary_count = 20
mod, primod = mod_maker(binary_count, convolution_time)
prim = [[doubling(primod[j], doubling(2, binary_count-i), mod[j]) for i in range(binary_count)] for j in range(convolution_time)]
invp = [[inved(prim[j][i], mod[j]) for i in range(binary_count)] for j in range(convolution_time)]

X1 = [NTT(A, pl, bn, j) for j in range(convolution_time)]
X2 = [NTT(A, pl, bn, j) for j in range(convolution_time)]
XX = [[X1[j][i]*X2[j][i]%mod[j] for i in range(pl)] for j in range(convolution_time)]
Y = [NTT(XX[j], pl, bn, j, 1) for j in range(convolution_time)]
Z = [0 for _ in range(pl)]
ipl = [inved(pl, mod[j]) for j in range(convolution_time)]
for j in range(convolution_time):
    for i in range(pl):
        Y[j][i] *= ipl[j]
        Y[j][i] %= mod[j]
for i in range(pl):
    Z[i] = CRT(convolution_time, [Y[j][i] for j in range(convolution_time)], mod)
print((Z[0]+Z[2]-N-M)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import combinations

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

a=["A" for i in range(0,N)]
b=["B" for i in range(0,M)]

tmp1=(len(list(combinations(a,2))))
tmp2=(len(list(combinations(b,2))))

print(tmp1+tmp2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

if (n > 1):
  cn = math.factorial(n) / (2 * math.factorial(n - r))
else:
  cn = 0
  
if (m > 1):
  cm = math.factorial(m)  / (2 * math.factorial(m - r))
else :
  cm = 0
  
print(int(cn+cm))

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,W = map(int,input().split())
total1 = 0
total2 = 0
if N>1:
  total1 = N*(N-1)//2
else:
  total1 = 0

if W>=2:
  total2 = W*(W-1)//2
else:
  total2 = 0
print(total1+total2)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
n, m = M()
print(n*(n-1)//2 + m*(m-1)//2)

Submission status: Accepted

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

def factorial(n):
    p = 1
    for i in range(n, 0, -1):
        p *= i
    return p


def comb(n, k):
    return factorial(n) // (factorial(k) * factorial(n-k))


res = comb(M, 2) + comb(N, 2)

print(res)

Submission status: Accepted

Solution code:
# 159   ########## dbt

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

def factorial(a):
    p = 1
    for i in range(a, 0 , -1):
        p *= i
    return p

def combo(b, num):
    ans = factorial(b) // (factorial(num) * factorial(b - num))
    return ans

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

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

Submission status: Accepted

Solution code:
# A - The Number of Even Pairs
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((N*(N-1)//2)+(M*(M-1)//2))

Submission status: Accepted

Solution code:
import math
N,M=(map(int,input().split()))
a=0
if N>=2:
    x=math.factorial(N)/(math.factorial(N-2)*2)
    a=a+x
if M>=2:
    y=math.factorial(M)/(math.factorial(M-2)*2)
    a=a+y
if a!=0:
    print(int(a))
else:
    print('0')

Submission status: Accepted

Solution code:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
M,N=map(int,input().split())
print(N*(N-1)//2+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())
if N==0 or N==1:
    if M==0 or M==1:
        print(0)
        exit(0)
    else:
        print(combinations_count(M, 2))
        exit(0
        )
if M==0 or M==1:
    if N==0 or N==1:
        print(0)
        exit(0)
    else:
        print(combinations_count(N, 2))
        exit(0)
        

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

Submission status: Accepted

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

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

Submission status: Accepted

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

print(int(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,y = [int(x) for x in input().split()]
def c(m):
      if (m>=2):
            return m*(m-1)//2
      else:
            return 0
if (x<2 and y<2):
      print(0)
else:
      print(c(x)+c(y))

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:
import math
N, M = list(map(int, input().split()))
n_pairs = math.factorial(N) // (2*math.factorial(N-2)) if N > 1 else 0
m_pairs = math.factorial(M) // (2*math.factorial(M-2)) if M > 1 else 0
print(n_pairs + m_pairs)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

def comb(n, r):
    if n<r:
        return 0
    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())
# odd+odd
odd_odd = comb(M,2)
# even+even
even_even = comb(N,2)

print(odd_odd+even_even)

Submission status: Accepted

Solution code:
def tri_num(num):
    num -= 1
    return int(num * (num + 1) / 2)


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def keisan(x):
  ret_val=0
  for i in range(1,x):
    ret_val+=i
  return ret_val

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

Submission status: Accepted

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

for i in range(n):
  for i2 in range(i,n):
    if i != i2:
      l.append([i,i2])

for i in range(m):
  for i2 in range(i,m):
    if i != i2:
      l.append([i,i2])
print(len(l))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce

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

if n < 2:
    ans_1 = 0
else:
    ans_1 = factorial(n, 2)
if m < 2:
    ans_2 = 0
else:
    ans_2 = factorial(m, 2)
print(ans_1+ans_2)

Submission status: Accepted

Solution code:
def main():
    N, M = (int(i) for i in input().split())
    ans = N*(N-1)//2 + M*(M-1)//2
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m = map(int, input().split())

g = n*(n-1)/2
k = m*(m-1)/2

print(int(g+k))

Submission status: Accepted

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

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

print(math.floor(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(int(ans))

Submission status: Accepted

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

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

print(even + odd)

Submission status: Accepted

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

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())
 
even = n * (n-1)/2
odd = m * (m-1)/2
 
print(int(even + odd))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M  = (int(x) for x in input().split())
Even = N*(N-1)//2
Odd  = M*(M-1)//2
print(Even+Odd)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
def num(x):
  if x<2:
    return 0
  else:
    return int(x*(x-1)/2)
print(num(n)+num(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 = list(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())
if m == 1 and n == 1:
    print(0)
elif m < 2:
    print(n*(n-1)//2)
elif n < 2:
    print(m*(m-1)//2)
else:
    print(n*(n-1)//2 + m*(m-1)//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

#偶数+偶数
result = n * (n - 1) // 2
#奇数+奇数
result += m * (m - 1) // 2
print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

if n>=2 and m>=2:
  ans = math.factorial(n)/math.factorial(n-2)/math.factorial(2) + math.factorial(m)/math.factorial(m-2)/math.factorial(2)

elif n<2 and m>=2 :
  ans =  math.factorial(m)/math.factorial(m-2)/math.factorial(2)

elif m<2 and n>=2:
  ans = math.factorial(n)/math.factorial(n-2)/math.factorial(2)

else:
  ans = 0

print(int(ans))

Submission status: Accepted

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

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

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

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

def combination(n,r):
  if n < 0 or r < 0 or n-r<0:
    return 0
  return step(n) // (step(r) * step(n-r))

res = combination(n,2) + combination(m,2)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9


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