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:
from itertools import combinations
N,M = map(int,input().split())
n = [c for c in combinations(range(N),2)]
m = [c for c in combinations(range(M),2)]
print(len(n)+len(m))

Submission status: Accepted

Solution code:
def main():

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



if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# from scipy.special import comb
from scipy.misc import comb
n, m = (int(x) for x in input().split())
ans = 0
if n >= 2:
    ans += comb(n, 2, exact=True)
if m >= 2:
    ans += comb(m, 2, exact=True)
print(ans)

Submission status: Accepted

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

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

print(a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial

N, M = map(int, input().split())
a = 0
b = 0
if N >= 2:
    a = factorial(N) / factorial(2) / factorial(N - 2)
if M >= 2:
    b = factorial(M) / factorial(2) / factorial(M - 2)
print(int(b + a))

Submission status: Accepted

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

print(odd_even())

Submission status: Accepted

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

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

print(answer)

Submission status: Accepted

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

ansn = N*(N-1)//2
ansm = M*(M-1)//2

print(ansn+ansm)

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
import queue
import copy
import bisect
import heapq


def dfs(s, prev, pre):
  val[s] += Ope[s] + prev
  for i in G[s]:
    if(i == pre):
      continue
    dfs(i, val[s], s)

def bfs(sx, sy, n):
  que = deque([[sy,sx]])
  while que:
    y,x = que.popleft()
    for i,j in D:
      if(x+i<0 or y+j<0 or x+i>W-1 or y+j>H-1):
        continue
      dist = G[y+j][x+i]
      if(G[y+j][x+i] != "X"):
        if(type(G[y+j][x+i]) is str):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        elif(dist>G[y][x]+1):
          G[y+j][x+i] = G[y][x]+1
          que.append([y+j,x+i])
        

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

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#V, E, r = map(int, input().split())
#INF = V * 10001

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

if(N>1):
  ans += combinations_count(N, 2)
if(M>1):
  ans += combinations_count(M, 2)


print(int(ans))

Submission status: Accepted

Solution code:
# coding: utf-8

import math

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

N, M = map(int, input().split())
# print(N, M)
c_N = 0
c_M = 0

if N >= 2:
    c_N = comb(N, 2)
if M >= 2:
    c_M = comb(M, 2)
print(c_N + c_M)

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:
import sys
def input(): return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
even = N*(N-1)//2 if N>1 else 0
odd = M*(M-1)//2 if M>1 else 0
print(even+odd)

Submission status: Accepted

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

#偶数同士の組み合わせ、奇数同士の組み合わせそれぞれの個数

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

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

print(int(n_number + m_number))

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

Submission status: Accepted

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

ans1 = (M*(M-1))//2
ans2 = (N*(N-1))//2

ans = ans1+ans2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import sys
import 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
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()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


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


N, M = MAP()

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

# 偶数＋偶数
case_1 = N * (N-1)/2

# 奇数＋奇数う
case_2 = M*(M-1)/2

print(int(case_1 + case_2))

Submission status: Accepted

Solution code:
def cycle(x):
    result = 0
    for y in range(int(x), 0, -1):
        result += y - 1
    return result


def main():
    N, M = map(cycle, input().split(' '))
    print(N + M)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import numpy as np
import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = 0

    if N >= 2:
        res += math.factorial(N) // (math.factorial(N-2) * math.factorial(2))

    if M >= 2:
        res += math.factorial(M) // (math.factorial(M-2) * math.factorial(2))

    print(res)



main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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


if __name__ == '__main__':
    n, m = list(map(int, input().split(" ")))
    print(combinations_count(n + m, 2) - (n * m))

Submission status: Accepted

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

Submission status: Accepted

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

tmp1 = 0
tmp2 = 0

if n != 0:
    tmp1 = n * (n - 1) / 2

if m != 0:
    tmp2 = m * (m - 1) / 2

r = int(tmp1 + tmp2)
print(r)

Submission status: Accepted

Solution code:
nm_list = input().split(" ")

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

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

Submission status: Accepted

Solution code:
from math import factorial

def main():
    n, m = map(int, input().split())
    r = 0
    if n >= 2:
        r += factorial(n) / (2 * factorial(n - 2))
    if m>= 2:
        r += factorial(m) / (2 * factorial(m - 2))

    print(int(r))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

m1 = [0]*m
n1 = [0]*n
print(len(list(combinations(m1,2)))+len(list(combinations(n1,2))))

Submission status: Accepted

Solution code:
# must have sum even. This only happens for x,y both even or both odd.
# N even, so N*(N-1)/2 pairs of them (not counting order). Same for M.
N, M = map(int, input().split())
num_N = N*(N-1)//2
num_M = M*(M-1)//2
print(num_N+num_M)

Submission status: Accepted

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

A()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input().split()
Even = int(a[0])
Odd = int(a[1])
if Even < 2 :
    Evenresult = 0
else:
    Evenresult = Even * (Even -1) / 2
if Odd < 2 :
    Oddresult = 0
else:
    Oddresult = Odd * (Odd -1) / 2
print(int(Evenresult + Oddresult))

Submission status: Accepted

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


# Even case
# N+N, M+M -> nC2, mC2
ans = 0
if n == 1 and m == 1:
    ans = 0
elif n <= 1:
    ans = m * (m - 1) // 2
elif m <= 1:
    ans = n * (n - 1) // 2
else:
    ans = (m * (m - 1) + n * (n - 1)) // 2

print(ans)

Submission status: Accepted

Solution code:

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

ans = 0
if N != 0:
    ans += N*(N-1)//2
if M != 0:
    ans += M*(M-1)//2

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
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)]
mod = 10 ** 9 + 7


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

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:
import itertools
n, h = map(int, input().split())
lst = [2]*n
lst2 = [1]*h
ev = list(itertools.combinations(lst,2))
ki = list(itertools.combinations(lst2,2))
print(len(ev) + len(ki))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

n,m = map(int,input().split())
ans = 0
if n != 1 and n != 0:
    ans += cmb(n,2)
if m != 1 and m != 0:
    ans += cmb(m,2)
print(ans)

Submission status: Accepted

Solution code:


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

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

Submission status: Accepted

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

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

print(n+m)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n, m = map(int, input().split())

    l = [2] * n + [1] * m

    ans = 0
    for i in range(len(l)):
        for j in range(len(l)):
            if i != j and i < j and (l[i] + l[j]) % 2 == 0:
                ans += 1

    print(ans)

Submission status: Accepted

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

    if n < 2 and m < 2:
        print(0)
        exit()

    if n < 2:
        print(m*(m - 1)//2)
        exit()

    if m < 2:
        print(n*(n - 1)//2)
        exit()

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

if __name__ == "__main__":
    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 = list(map(int, input().split()))

if N > 2:
    a = combinations_count(N, 2)
elif N == 2:
    a = 1
else:
    a = 0

if M > 2:
    b = combinations_count(M, 2)
elif M == 2:
    b = 1
else:
    b = 0

print(a+b)

Submission status: Accepted

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

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

if m < 2:
    two = 0
else:
    two = m * (m-1) // 2
print(one + two)

Submission status: Accepted

Solution code:
import math

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

ans1 = 0
ans2 = 0
if n > 1:
    ans1 = cmb(n, 2)
if m > 1:
    ans2 = cmb(m, 2)

print(ans1+ans2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import factorial

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

Submission status: Accepted

Solution code:
#/usr/bin/env python
def main():
    N, M = list(map(int, input().split()))
    print(int(N * (N - 1) / 2 + M * (M - 1) / 2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

if N > 1:
  count += nCr(N, 2)
if M > 1:
  count += nCr(M, 2)

print(count)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
count1 = 0
count2 = 0

for i in range(a):
  for j in range(a-1):
    count1 = count1 + 1
for l in range(b):
  for m in range(b-1):
    count2 = count2 + 1
print((count1+count2)//2)

Submission status: Accepted

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


cnt = 0
if N > 1:
    cnt += (N * (N-1)) // 2
if M > 1:
    cnt += (M * (M-1)) // 2

print(cnt)

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

Submission status: Accepted

Solution code:
N,M=(int(x) for x in input().split())
#N=int(input())
#A=list(map(int, input().split()))

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

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

print(a+b)

Submission status: Accepted

Solution code:
x,y = map(int,input().split())

# even + even
ans = x*(x-1) / 2

# odd + odd
ans += y*(y-1) / 2

print(int(ans))

Submission status: Accepted

Solution code:
h, w = map(int,input().split())

out = 0

for i in range(h):
  out += i
for i in range(w):
  out += i
  
print(out)

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:
from  itertools import combinations
N, M = map(int, input().split())
N = range(N)
M = range(M)
count_n = len(list(combinations(N,2))) if len(N) >=2 else 0
count_m = len(list(combinations(M,2))) if len(M) >=2 else 0

print(count_n+count_m)

Submission status: Accepted

Solution code:
def nCr(n, r): 
  
    return (fact(n) // (fact(r)  
                * fact(n - r))) 
  
# Returns factorial of n 
def fact(n): 
  
    res = 1
      
    for i in range(2, n+1): 
        res = res * i 
          
    return res 


e, o = map(int, input().split())

ans = nCr(e, 2) + nCr(o, 2)
print(ans)

Submission status: Accepted

Solution code:
data = input()

g, k = [int(i) for i in data.split()]

result = (g * (g-1) /2 + k * (k-1)/2)

print(int(result))

Submission status: Accepted

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

# process
ans = 0
if N != 0:
    ans += N*(N-1)//2

if M != 0:
    ans += M*(M-1)//2

# output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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())
n = 0
m = 0

if N >= 2:
    n = combinations_count(N, 2)
if M >= 2:
    m = combinations_count(M, 2)

print(n + m)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if N > 1:
	cN = math.factorial(N) // (2 * math.factorial(N - 2))
else:
	cN = 0

if M > 1:
	cM = math.factorial(M) // (2 * math.factorial(M - 2))
else:
	cM = 0

print(cN + cM)

Submission status: Accepted

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

print(res)

Submission status: Accepted

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

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

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

print(int(gusu + kisu))

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

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

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

print(ans)

Submission status: Accepted

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

ans = 0

for j in range(1,m):
    ans += j

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

print(ans)

Submission status: Accepted

Solution code:
"""def power(x, y): 
    res = 1
    x=x
    while (y > 0): 
        if ((y & 1) == 1) : 
            res = (res * x) 
        y = y >> 1
        x = (x * x)
    return res""" 
"""def fact(n):
    if(n==0):
        return 1
    if(n==1):
        return 1
    return fact(n-1)+fact(n-2)"""

import math
#import combinations
#t=int(input())
#for _ in range(t):
#n=int(input())
#arr=list(map(int,input().split()))
n,m=map(int,input().split())
#count=0
ans=(m*(m-1))//2 + (n*(n-1))//2
print(ans)

Submission status: Accepted

Solution code:
import sys
from math import factorial
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, M = i_l()

a = 0
b = 0
if N > 1:
    a = factorial(N) / factorial(2) / factorial(N - 2)

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

print(int(a+b))

Submission status: Accepted

Solution code:
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [list(input().split()) for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    from itertools import combinations
    n,m = map(int, input().split())
    print(n*(n-1)//2+m*(m-1)//2)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=0
if n!=0:
  ans+=n*(n-1)//2
if m!=0:
  ans+=m*(m-1)//2
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:
# -*- coding: utf-8 -*-
###########　入力
# 整数の入力
N, M = list(map(int, input().split()))

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

###########　出力
print(output)

Submission status: Accepted

Solution code:
import sys
import math
n,m = map(int, sys.stdin.readline().split())

def combinations_count(n, r):
    if n-r < 0: return 0
    return math.factorial(n) // (math.factorial(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())

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

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

print(int(ans))

Submission status: Accepted

Solution code:
import math
N,M=map(int,input().split())
if N>=2 and M>1:
    print(int(math.factorial(N)/(math.factorial(2)*math.factorial(N-2))+math.factorial(M)/(math.factorial(2)*math.factorial(M-2))))
    exit()
if N>=2:
    print(int(math.factorial(N)/(math.factorial(2)*math.factorial(N-2))))
elif M>1:
    print(int(math.factorial(M)/(math.factorial(2)*math.factorial(M-2))))
else:
    print(int(N//2+M//2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ab=input().split()
a=int(ab[0])
b=int(ab[1])
count=0
if a<=1 and b<=1 :
  count=0

elif b>1 and a<=1 :
  count=b*(b-1)/2

elif a>1 and b<=1 :
  count=a*(a-1)/2

elif a>1 and b>1 :
  count=a*(a-1)/2+b*(b-1)/2

print(int(count))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力

a = input()
# スペース区切りの整数の入力
H,W=a.split(" ")
N=int(H)
M=int(W)
retnum=0
for i in range(N):
    retnum+=i
retnum+=M*(M-1)/2
print(int(retnum))

Submission status: Accepted

Solution code:
#from scipy.special import comb
N,M=map(int,input().split())
ans=int(M*(M-1)/2+N*(N-1)/2)
print(ans)

Submission status: Accepted

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

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()) #n個偶数、m個奇数 

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

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

print(int(total))

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 = map(int, input().split(' '))
count = 0
if n >= 2:
    count += math.factorial(n) / 2 / math.factorial(n - 2)
if m >= 2:
    count += math.factorial(m) / 2 / math.factorial(m - 2)
print(int(count))

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
S = input().split()
N = int(S[0])
M = int(S[1])

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

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    s = input().rstrip().split(' ')
    N = int(s[0])
    M = int(s[1])

    print(XC2(N)+XC2(M))

Submission status: Accepted

Solution code:
import math

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

n, m = map(int, input().split())
if n < 2 :
    n = 0
else :
    n = combinations_count(n, 2)

if m < 2 :
    m = 0
else :
    m = combinations_count(m, 2)

print(n+m)

Submission status: Accepted

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

N_pattern = N*(N-1)/2 if N > 1 else 0
M_pattern = M*(M-1)/2 if M > 1 else 0

print(int(N_pattern+M_pattern))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,k= list(map(int, input().split()))
from math import factorial
if n>1:
    a=factorial(n)//factorial(2)//factorial(n-2)
else:
    a=0
if k>1:
    b=factorial(k)//factorial(2)//factorial(k-2)
else:
    b=0
print(a+b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!python3.4.3
import math

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)
  
N, M = map(int, input().split(' '))

result = 0

if N > 1:
  result += permutations_count(N, 2)

if M > 1:
  result += permutations_count(M, 2)

print(result // 2)

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

Submission status: Accepted

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


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


print(c2(n) + c2(m))