peterverebics/CodeNet_Python_118 huggingface dataset:
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))

max = max(A)
min = min(A)

print(max - min)
K,N=map(int,input().split())
A=list(map(int,input().split()))
d=0
for i in range(N-1):
  if d == 0 and A[i+1]-A[0] >= K/2:
    d=d+A[i]-A[0]+K-A[i+1]-A[0]
if d == 0:
  d=d+A[N-1]-A[0]
print(d)
K, N=map(int,input().split())
List=list(map(int,input().split()))
Newlist=list(List[i+1]-List[i]for i in range(N-1))
Newlist.append(List[0]+K-List[N-1])
print(max(Newlist))
k, n = map(int, input().split())
a = list(map(int, input().split()))
s = []
count = 0
for i in a:
  if i > k / 2:
    s.append((k - a[count]) * -1)
  else:
    s.append(a[count])
  count += 1
ans_1 = abs(min(s)) + abs(max(s))
counts = 0
for j in a:
  if i > k:
    s.append((k - a[counts]) * -1)
  else:
    s.append(a[counts])
  counts += 1
ans_2 = max(a) - min(a)
ans = min(ans_1, ans_2)
print(ans)
K,N=list(map(int,input().split()))
A=list(map(int,input().split()))
ans=0
ans=max(A)-min(A)
if 0 in A:
    ans =ans-(K-max(A))
print(ans)
K, N = map(int,input().split())
A = list(map(int, input().split()))

l = [0] * N
hoge = 0

for n in range(N):
  l[n] = A[n]-hoge
  hoge = hoge + l[n]
  
l = l + [K-A[N-1]]

print(sum(l)-max(l))
k, n = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()

if a[0] == 0 and len(a) <= 3:
    print(max(a[1:])-min(a[1:]))
    exit()
elif a[0] == 0 and len(a) > 3:
    print(max(a))
    exit()
else:
    print(max(a) - min(a))
K, N = map(int, input().split())
A = list(map(int, input().split()))
x = max(A)
B = list(map(lambda x: K - x, A))
y = min(B)
z = x - y
print(z)
k, n = map(int, input().split())

An = list(map(int, input().split()))

Ank = [0] + An[:] + [k]

node = [Ank[i+1] - Ank[i]  for i in range(len(Ank) - 1)]

print(sum(node) - max(node))
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    ans = A[-1] - A[0]
    for i in range(N-1):
        d = A[i + 1] - A[i]
        ans = max(ans, d)
    print(K - ans)

if __name__ == '__main__':
    main()
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
temp=a[0]+a[n-1]
for i in range(1,n):
  temp=max(temp,a[i]-a[i-1])
print(k-temp)
K, N = map(int, input().split())
Alst = list(map(int, input().split()))
zero = Alst[0] + K
M = 0
now = Alst[0]
for i in Alst:
    dis = i - now
    if dis > M:
        M = dis
    now = i

last = zero - now
if last > M:
    M = last

print(M)
# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]

for i in range(N-1):
    ans.append(A[i+1]-A[i])
ans.append(abs(A[0] - (K - A[-1])))
print(sum(ans) - max(ans))
k,n=map(int, input().split())
a=list(map(int, input().split()))
ans = a[0]+k-a[n-1]
for start in range(n-2):
    ans = max(ans,a[start+1]-a[start])
    
print(k-ans)
k, n = map(int, input().split())

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

a.append(k)

big = 0
big_count = a[0]

for i in range(n):
    b = a[i + 1] - a[i]
    print(b)
    if b > big_count:
        print('ここ')
        big_count = b
        big = i

if big == 0:
    ans = a[n - 1] - a[0]
else:
    ans = a[i - 1] + (k - a[i])

print(ans)
(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)
# k=k-d
c=abs(a[-1]-a[0]-d)
l.append(c)
l=sorted(l)
l1=sum(l)
print(l1-l[-1])
K, N = map(int, input().split())
A = list(map(int, input().split()))

x = [abs(A[i] - A[i+1]) for i in range(N-1)] + [K - max(A)]

x.pop(x.index(max(x)))

print(sum(x))
K, N = map(int, input().split())
a = list(map(int, input().split()))

low = 0
high = 0

low = min(a)
high = max(a)

print(high - low)
K,N=map(int,input().split())
mylist=list(map(int,input().split()))

if max(mylist)-min(mylist)>K/2:
    #0より大きいminを取得
    #それにK-maxを足す
    if mylist[0]==0:
        print(mylist[1]+K-max(mylist))
    else:
        print(mylist[0]+K-max(mylist))

else:
    print(max(mylist)-min(mylist))
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
a.sort()
amin = a[n-1] - a[0]
for i in range(n):
  if a[i] < k//2:
    b[i] = a[i] + k
  else:
    b[i] = a[i]
b.sort()
bmin = b[n-1] - b[0]
print(a,b)
print(min(amin,bmin))
K,N=map(int,input().split())
A=list(map(int,input().split()))
a=sorted(A)
X=a[N-1]-a[0]
Y=K-a[N-1]+a[N-2]
print(min(X,Y))
syu,n=map(int,input().split())
a=[int(i) for i in input().split()]
clock=a[n-1]-a[0]
han_clock=min(a[1]-a[0],(a[n-1]-a[1]))+(a[0]+syu-a[n-1])
print(min(clock,han_clock))
class atcorder:
    
    K,N=map(int,input().split())
    A=list(map(int,input().split()))
    ans=0
    i=N-1
    if A[i]-A[i-1]<20-A[i]+A[0]:
        for n in range(i):
            ans+=A[i-n]-A[i-n-1]
    else:
        ans+=20-A[i]-A[0]
        for n in range(i-1):
            ans+=abs(A[n]-A[n+1])
    print(ans)
k,n=map(int, input().split())
A=list(map(int, input().split()))
B=[0]*(n-1)
t=0
for i in range(n-1):
    B[i]=A[i+1]-A[i]
if B[n-2]>k-A[n-1]:
    B[n-2]=k-A[n-1]
B.sort()
for i in range(len(B)):
    t+=B[i]
print(t)
k,n = map(int, input().split())
a = list(map(int, input().split()))
dis = [0]*n
for i in range(n):
    if i == n-1:
        dis[i] = k + a[0] - a[i]
    else:
        dis[i] = a[i+1] - a[0]

print(k - max(dis))
K,N = map(int,input().split())

A = list(map(int,input().split()))

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)
K, N = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if(A[i+1]-A[i] < K-A[i+1]):
        ans += A[i+1]-A[i]    
    else:
        ans += K-A[i+1]
print(ans)
k,n = map(int,input().split())
a_list = list(map(int,input().split()))

a_list_sorted = sorted(a_list)

distance_1 = a_list_sorted[-1] - a_list_sorted[0]

a_list_sorted_minus = list(map(lambda x: x - k, a_list_sorted))
min_tmp = 100000000
for i in range(len(a_list_sorted_minus)):
    if a_list_sorted_minus[i] > -(k / 2):
        if a_list_sorted_minus[i] < min_tmp:
            min_tmp = a_list_sorted_minus[i]
            index = i

distance_2 = a_list_sorted[index-1] - min_tmp

print(min(distance_1, distance_2))
K, N, *A = map(int, open(0).read().split())

A.append(K)

B = [b - a for a, b in zip(A, A[1:])]
print(sum(B) - max(B))
k, n = map(int,input().split())

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

# x = distance between the first and last house
x = (a[-1] - a[0])
# y = k - x (the "other" distance) 
y = (k - x)

if x < y:
  print (x)
elif y < x:
  print (y)
else:
  print (x)
#X = int(input().strip())

K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = 0
ind = 0
ans = 0

for i in range(N-1):
  _m = A[i+1] - A[i]
  if _m > m:
    m = _m
    ind = i+1
    last = i

_m = K - A[N-1]
if _m > m:
  m = _m
  ind = 0
  last = N-1

#print(m)
#print(ind)
#print(last)
i = ind
while i != last:
  #print(ans)
  if i < N-1:
    ans += A[i+1] - A[i]
    i += 1
  else:
    ans += K - A[i]
    i = 0

print(ans)
k, n = map(int, input().split())
a = list(map(int, input().split()))
sa = [k] * n
for i in range(1, n):
    sa[i - 1] = min(k - a[i-1], a[i] - a[i - 1])
print(sa)
sa.sort()
sum = sum(sa) - sa[-1]
print(sum)
k,n=map(int,input().split())
A=list(map(int,input().split()))

ans=[]
ans.append(A[-1]-A[0])
for i in range(n):
  A[i]=(A[i]+k//2)%k
A.sort()
ans.append(A[-1]-A[0])
print(min(ans))
import numpy as np
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))
A_diff = np.diff(A)
asc = np.sum(A_diff)
desc = asc - abs(A[-1] - A[-2]) + (N - A[-1] + A[0])  
print(min([asc, desc]))
k, n = (int(i) for i in input().split())
a = list(map(int, input().split()))

i=0
m=0
while i < n-1:
  if (a[i+1]-a[i]) > m:
    m=a[i+1]-a[i]
  i += 1

if a[0]==0: 
  a[0]=k
if abs(a[n-1]-a[0]) > m:
  m=abs(a[n-1]-a[0])
print(str(k-m))
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
for i in range(0, N-1):
  if i < N-1:
    B[i]=A[i+1]-A[i]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))
K,N=list(map(int, input().split()))
A=list(map(int, input().split()))
A2=[A[i+1]-A[i] for i in range(2)]
A2.append(A[0]+(K-A[-1]))
ans = sum(A2)- max(A2)
print(ans)
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
L = []
for i in range(N):
  if(i != N-1):
    L.append(A[i+1] - A[i])
  else:
    L.append(K - A[i])
sumL = sum(L)
maxL = max(L)
print(sumL - maxL)
K, N = map(int, input().split())
A = list(map(int, input().split()))

ans = sum(A)

ans -= max((A[(i + 1) % N] - A[i]) % K for i in range(N))

print(ans)
k,n=map(int,input().split())
a=list(map(int,input().split()))

x=0
for i in range(n-1):
 p=a[i+1]-a[i]
 if p >= x:
  x=p
  
print(k-x)
K, N = map(int, input().split())

A = list(map(int, input().split()))

c = abs(A[1] - A[N-1])

for i in range(N-1):
  d = abs(A[i] - A[i+1])
  if c < d:
    c = d
  else:
    c = c
    
print(K-c)
a = input()
b = input()
a = a.split()
K = int(a[0])
N = int(a[1])
b = b.split()
if b[0] == 0:
  c = int(b[len(b) - 1]) - int(b[1])
  d = (K - int(int(b[len(b) - 1]))) + (int(b[len(b) - 2]) - int(b[1]))
  if c >= d:
    print(d)
  else:
    print(c)

else:
  c = int(b[len(b) - 1]) - int(b[0])
  d = (K - int(int(b[len(b) - 1]))) + (int(b[len(b) - 2]) - int(b[0]))
  if c >= d:
    print(d)
  else:
    print(c)
f=list(map(int,input().split()))
k=f[0];n=f[1]
dists=list(map(int,input().split()))
prev=0
maxdist=0
for d in range(len(dists)):
  maxdist=max(maxdist,abs(prev-dists[d]))
  prev=dists[d]
a=max(maxdist,maxdist-dists[len(dists)-1]+dists[0])  
ans=k-a
print(ans)
ddd = [input() for i in range(2)]
eee = ddd[0].split()
fff = ddd[1].split()
longest_distance = int(eee[0]) - int(fff[-1])
for i in range(len(fff) - 1):
    distance = int(fff[i+1]) - int(fff[i])
    if longest_distance < distance:
        longest_distance = distance
shortest_road = int(eee[0]) - longest_distance
print(shortest_road)
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
a.sort()
amin = a[n-1] - a[0]
for i in range(n):
  if a[i] < k//2:
    b[i] = a[i] + k
  else:
    b[i] = a[i]
b.sort()
bmin = b[n-1] - b[0]
print(min(amin,bmin))
n, m = [int(x) for x in input().strip().split(" ")]

import math

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

print(c(n, 2) + c(m, 2))
import math
n,m=map(int,input().split())
print( math.factorial(n+m) // (math.factorial(n+m-2) * math.factorial(2))-n*m)
N, M = map(int, input().split())
print(int(N*(N-1)/2 + M*(M-1)/2))
#!/usr/bin/env python3
import math

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

nans = (n * (n - 1)) // 2
mans = (m * (m - 1)) // 2

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

n1 = n - 1
m1 = m - 1

res = int((n * n1) / 2 + (m * m1) / 2)

print(res)
# coding: utf-8
# Your code here!

N, M = [int(i) for i in input().split()]

cnt = 0
cnt += (N*(N-1))//2
cnt += (M*(M-1))//2
    
print(cnt)
import math
n, m = map(int, input().split())
# 組み合わせの全通り
all_pattern = math.factorial(n+m) // (math.factorial(n+m - 2) * math.factorial(2))
print(all_pattern - n*m)
n, m = [int(elem) for elem in input().split()]
print(n * (n-1) // 2 + m * (m-1) // 2)
n, m = map(int, input().split())

print(int(n * (n - 1) / 2 + m * (m - 1) / 2))
import math
N,M=map(int,input().split())
s=N*(N-1)/2
m=M*(M-1)/2
print(math.floor(s+m))
n,m=map(int,input().split())

print(int(n*(n-1)/2+m*(m-1)/2))
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)
n,m=map(int,input().split())
a=0
b=0
if n!=1:
    a=(n*(n-1))/2
if m!=1:
    b=(m*(m-1))/2
c=int(a+b)
print(c)
import sys
import collections
import heapq
import math
n,m = map(int,sys.stdin.readline().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(max(n - r,0)) * math.factorial(r))
print(combinations_count(n,2)+combinations_count(m,2))
n,m=map(int,input().split())
print(n*(n-1)//2+m*(m-1)//2)
def main():
    n, m = map(int, input().split())

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


if __name__ == '__main__':
    main()
def c(n):
    return n*(n-1)//2

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

ans = c(n) + c(m)

print(ans)
from itertools import combinations
N,M = map(int,input().split())

a= list(combinations(range(N),2))
b= list(combinations(range(M),2))
print(len(a)+len(b))
N,M=map(int,input().split())
ans=(M+N)*(M+N-1)/2-(M*N)
print(int(ans))
N, M = map(int, input().split())

print(N * (N - 1) // 2 + M * (M - 1) // 2)
from operator import mul
from functools import reduce

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

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

if n >= 2:
    ans = ans + cmb(n, 2)

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

print(int(N * (N - 1) / 2 + M * (M - 1) / 2))
#coding:utf-8
import itertools

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

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

ans = ansN + ansM
print(ans)
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  
n,m = map(int,input().split())

su = combinations_count(n+m, 2)
mm = n*m
ans = su-mm

print(str(ans))
n, m = [int(x) for x in input().split()]

result = 0

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

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

print(int(result))
n,m = map(int,input().split())
an = n * (n-1)/2
am = m * (m-1)/2
answer = an + am
print(int(answer))
import math

a,b=map(int,input().split())
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

count=0

if a>=2:
    count+=combinations_count(a,2)

if b>2:
    count+=combinations_count(b,2)

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

print(int(n*(n-1)/2+m*(m-1)/2))
n, m = map(int, input().split())
print(n*(n-1)//2+m*(m-1)//2)
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()
import math
n, m = list(map(int, input().split()))
print(math.floor(n * (n - 1) / 2 + m * (m - 1) / 2))
N, M = map(int, input().split())

a = N * (N-1) // 2
b = M * (M-1) // 2

print(a+b)
n,m = map(int,input().split())
ans = 0
ans += n*(n-1)//2
ans += m*(m-1)//2
print(ans)
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 入力はstringで入る．
# intにしたければ int(input())
# floatで受け取ると 1.0 になる．

# 入力 : N M
N,M = map(int,input().split())

print(int(N*(N-1)/2+M*(M-1)/2))
n,m=map(int,input().split())
if n<=1 and m<=1:
  ans=0
if n<=1 and m>=2:
  ans=m*(m-1)//2
if m<=1 and n>=2:
  ans=n*(n-1)//2
if m>=2 and n>=2:
  ans= n*(n-1)//2+(m*(m-1)//2)
print(ans)
score = list(map(int,input().split()))
if score[0] == 1:
    evennum = 0
else:
    evennum = score[0]*(score[0]-1)/2
if score[1] == 1:
    oddnum = 0
else:
    oddnum = score[1]*(score[1]-1)/2
print(int(evennum+oddnum))
N, M = map(int, input().split())
print(int((N * (N - 1) + M * (M-1)) / 2))
n, m = map(int, input().split())
ans = (n * (n - 1)) // 2 + (m * (m - 1)) // 2
print(ans)
N, M = map(int, input().strip().split())
a = max(N*(N-1)//2, 0)
b = max(M*(M-1)//2, 0)

print(a+b)
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
even, odd = map(int, input().split())

even_r = 0
odd_r = 0

for i in range(even):
  for j in range(even - i - 1):
    even_r += 1
  
for i in range(odd):
  for j in range(odd - i - 1):
  	odd_r += 1

total = even_r + odd_r

print(total)
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)
N,M = map (int, input ().split ())
X = round((N*(N-1))/2)
Y = round((M*(M-1))/2)
print (X+Y)
def factorial(n):
    if n == 0 or n == 1 or n < 0:
        return 1
    return n * factorial(n-1)

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

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

    if n == 0:
        return 0
    else:
        return n + saiki(n - 1)

def number(n , m):

    ans = saiki(n) + saiki(m) - n - m

    return ans

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

if __name__ == '__main__':
    main()
n,m=map(int,input().split())
print ((n*(n-1)//2)+(m*(m-1)//2))
N,M=list(map(int,input().split()))

if N>0 and M>0:
  print(int(M*(M-1)/2+N*(N-1)/2))
elif N==0:
  print(int(M*(M-1)/2))
else:
  print(int(N*(N-1)/2))
N, M = [int(x) for x in input().split(" ")]
print(int((N*(N-1)+M*(M-1))/2))
n, m = list(map(int, input().split()))

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

print(n*(n-1)//2 + m*(m-1)//2)
from sys import stdin

def main():

    input = stdin.readline

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

    ans = 0

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

    print(ans)


def comb(n,k):
    min_k = min(k,n-k)

    if n < 2:
        return 0

    n_kaijyo = 1
    k_kaijyo = 1
    for i in range(min_k):
        n_kaijyo = n_kaijyo * (n - i)
        k_kaijyo = k_kaijyo * (i + 1)

    result = int(n_kaijyo / k_kaijyo)
    return result
    
if __name__ == "__main__":
    main()
n,m=list(map(int,input().split()))
print(str(int(n*(n-1)/2+m*(m-1)/2)))
n, m = map(int,input().split())

print(n*(n-1)//2+m*(m-1)//2)
import sys
input = sys.stdin.readline

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

def main():
    mod=10**9+7
    N,M=MI()
    ans=(N*(N-1))//2+(M*(M-1))//2
    print(ans)
main()
N, M = tuple(map(int, input().split()))

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

if M < 2 and N < 2:
    print(0)
elif M < 2:
    print(comb(N,2))
elif N < 2:
    print(comb(M,2))
else:
    print(comb(N,2) + comb(M, 2))
def Conv(x):
    return x * (x - 1) // 2

N, M = map(int, input().split())
print(Conv(N) + Conv(M))
n,m = map(int,input().split())
s = n*(n-1) // 2
t = m*(m-1) // 2
print(s + t)
#ABC159A
import sys
n, m = map(int, sys.stdin.readline().split())
#print(n, m)

print(n*(n-1)//2 + m*(m-1)//2) #偶偶or 奇奇
M, N = map(int, input().split())
result = 0

def fact(num):
    result = 1
    while num > 1:
        result *= num
        num -= 1
    return result

if M!=0 or M!=1:
    result += fact(M) // (fact(2) * fact(M-2))

if N!=0 or N!=1:
    result += fact(N) // (fact(2) * fact(N-2))

print(result)
def nc2(n):
  if n<2:
    return 0
  else:
    return (n*(n-1))//2
n,m = map(int, input().split())
print(nc2(n)+nc2(m))
n,m = map(int, input().split())
print((n*(n-1) + m*(m-1)) // 2)
N, M = map(int, input().split())
print(M*(M-1)//2+N*(N-1)//2)
n,m=map(int,input().split())
if m<=1:
    if n<=1:
        print(0)
    else:
        print(n*(n-1)//2)
else:
    print((n*(n-1)//2)+(m*(m-1)//2))
# A - The Number of Even Pairs
N,M = list(map(int, input().split()))
ans = int(N*(N-1)/2 + M*(M-1)/2)
print(ans)
N, M = map(int, input().split())
print(int(N*(N-1)/2+M*(M-1)/2))
N, M = map(int,input().split())
a = int((N * (N-1) + M * (M-1)) / 2)
print(a)
N, M = map(int, input().split())
import math

ans = 0

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

print(math.floor(ans))
i = input().split(" ")
a,b = int(i[0]),int(i[1])
print(int(a*(a-1)/2+b*(b-1)/2))
N, M = map(int, input().split())
 
a = N * (N - 1)/2
b = M * (M - 1)/2
 
print(int(a + b))
N,M = map(int,input().split())

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


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

print(c)
import math

n, m = (int(x) for x in input().split())

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

ans = 0
ans_n = 0
ans_m = 0

if 1 < n :
    ans_n = combinations_count(n, 2)

if 1 < m :
    ans_m = combinations_count(m, 2)

ans = ans_n + ans_m

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

res = n*(n-1)//2 + m*(m-1)//2
print(res)
n, m = map(int, input().strip().split())
ans = n * (n - 1) // 2 + m * (m - 1) // 2
print(ans)
n,m=map(int,input().split())
print(((n-1)*n)//2+((m-1)*m)//2)
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)]
s = input().split()
print(cmb(int(s[0]),2) + cmb(int(s[1]),2))
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)
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)
n, m = map(int, input().split())

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

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

result = int(total - odd)
print(result)
N, M = map (int, input().split())

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

print(c)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import math
def nC2(n):
  # n = 0 -> 0
  # n = 1 -> 0
  if n<2:
    return 0
  return math.factorial(n) // (math.factorial(n - 2) * 2)
n,m = map(int, input().split())
# 135 3C2
# 2468 4C2
# nC2
r=nC2(n)+nC2(m)
print(r)
N, M = map(int, input().split())

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

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

print(n*(n-1)//2 + m*(m-1)//2)
#!/usr/bin/env python3
m, n = map(int, input().split())
print((m * (m-1) + n * (n - 1)) // 2)
import math

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

N, M = [int(i.strip()) for i in input().split(' ')]


print(combinations_count(N,2) + combinations_count(M,2))
n, m = map(int, input().split())

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

N = a[0]
M = a[1]

N_combi = N*(N-1)/2
M_combi = M*(M-1)/2

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

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

print(cal(N)+cal(M))
a,b = map(int, input().split())
print(a*(a-1)//2 + b*(b-1)//2)
from operator import mul
from functools import reduce

def combinations_count(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

def main():
    N,M = map(int, input().split())
    ans = combinations_count(M,2) + combinations_count(N,2)
    print(ans)

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

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

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