Pak Chanek has a grid that has $N$ rows and $M$ columns. Each row is numbered from $1$ to $N$ from top to bottom. Each column is numbered from $1$ to $M$ from left to right.

Each tile in the grid contains a number. The numbers are arranged as follows:

Row $1$ contains integers from $1$ to $M$ from left to right.

Row $2$ contains integers from $M+1$ to $2 \times M$ from left to right.

Row $3$ contains integers from $2 \times M+1$ to $3 \times M$ from left to right.

And so on until row $N$.

A domino is defined as two different tiles in the grid that touch by their sides. A domino is said to be tight if and only if the two numbers in the domino have a difference of exactly $1$. Count the number of distinct tight dominoes in the grid.

Two dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.


-----Input-----

The only line contains two integers $N$ and $M$ ($1 \leq N, M \leq 10^9$) — the number of rows and columns in the grid.


-----Output-----

An integer representing the number of distinct tight dominoes in the grid.


-----Examples-----

Input
3 4
Output
9
Input
2 1
Output
1


-----Note-----

The picture below is the grid that Pak Chanek has in the first example.

The picture below is an example of a tight domino in the grid.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
(n, m) = map(int, input().split())
if m == 1:
	print(n - 1)
else:
	print((m - 1) * n)


value = input()
nums = value.split(' ')
N = int(nums[0])
M = int(nums[1])
res = 0
if M >= 2:
	res += (M - 1) * N
elif M == 1 and N > 1:
	res = N - 1
else:
	res = 0
print(res)


(r, c) = map(int, input().split())
if c == 1:
	print(r - 1)
else:
	print((c - 1) * r)


(n, m) = input().split(' ')
n = int(n)
m = int(m)
c = (m - 1) * n
if m == 1:
	c += (n - 1) * m
if m <= 0 or n <= 0:
	c = 0
print(c)


temp = input()
temp1 = temp.split()
a = int(temp1[0])
b = int(temp1[1])
if b == 1:
	print((a - 1) * b)
else:
	print((b - 1) * a)


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


(a, b) = [int(i) for i in input().split()]
if b == 1:
	print(a - 1)
else:
	print(a * (b - 1))


(row, column) = input().split()
row = int(row)
column = int(column)
if column == 1:
	print(row - 1)
else:
	print((column - 1) * row)


def solve():
	(n, m) = map(int, input().split())
	print(n * (m - 1)) if n != 1 and m != 1 else print(m * n - 1)
solve()


(a, b) = map(int, input().split())
if b == 1:
	print(a - 1)
else:
	print(a * (b - 1))


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


(N, M) = input().split()
N = int(N)
M = int(M)
x = ''
if M > 1:
	x = N * (M - 1)
elif M == 1:
	x = N - 1
else:
	pass
print(x)


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


(y, x) = map(int, input().split())
print(y - 1 if x == 1 else y * (x - 1))


(x, y) = list(map(int, input().split()))
if x >= y:
	if x % 2 == 0 and y % 2 == 0 or (x % 2 == 1 and y % 2 == 0):
		print(x * (y - 1))
	else:
		print((x - 1) * y)
elif x < y:
	print(x * (y - 1))
else:
	print(x * (x - 1))


(n, k) = map(int, input().split())
a = 0
if n > k and k == 1:
	a = (n - 1) * 1
elif n > k and k != 1:
	a = (k - 1) * n
elif k > n:
	a = (k - 1) * n
if n == k:
	a = (k - 1) * n
print(a)


(n, m) = (int(i) for i in input().split())
if m > 1:
	print(n * (m - 1))
else:
	print(n - 1)


(n, m) = [int(x) for x in input().split()]
if m == 1:
	print(n - 1)
else:
	print(n * (m - 1))


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


(n, m) = map(int, input().split())
ans = 0
if m == 1:
	ans = (n - 1) * m
else:
	ans = (m - 1) * n
print(ans)


NM = input()
N = int(NM.split(' ')[0])
M = int(NM.split(' ')[1])
if M == 1:
	print(N - 1)
else:
	print(N * (M - 1))


a = input('')
b = a.split()
c = map(int, b)
n = int(b[0])
m = int(b[1])
if m == 1:
	print(n - 1)
else:
	print(n * (m - 1))


(N, M) = map(int, input().split())
if M != 1:
	count = (M - 1) * N
else:
	count = N - 1
print(count)


(n, m) = map(int, input().split())
rowdom = m - 1
columndom = 0
if m == 1:
	columndom = n - 1
res = rowdom * n + m * columndom
print(res)


(row, col) = map(int, input().split())
if col > 1:
	print(row * (col - 1))
else:
	print(row - 1)


(n, m) = input().split()
n = int(n)
m = int(m)
if n == 1 and m == 1:
	print(n - 1)
elif n == 1:
	print(m - 1)
elif m == 1:
	print(n - 1)
else:
	print((m - 1) * n)


def tight_dominos(m, n):
	if m == 1 and n == 1:
		return 0
	elif m == 1:
		return n - 1
	elif n == 1:
		return m - 1
	else:
		return (n - 1) * m
(x, y) = input('').split()
a = int(x)
b = int(y)
print(tight_dominos(a, b))


import sys
(n, m) = map(int, sys.stdin.readline().split())
if n == 1:
	print(m - 1)
elif m == 1:
	print(n - 1)
else:
	print((m - 1) * n)


a = list(map(int, input().split()))
if a[1] == 1:
	print(a[0] - 1)
else:
	print(a[0] * (a[1] - 1))


l = list(map(int, input().split()))
if l[1] > 1:
	print((l[1] - 1) * l[0])
else:
	print(l[0] - 1)


data = input()
(row, col) = data.split(' ')
row = int(row)
col = int(col)
if col == 1:
	print(row - 1)
else:
	print((col - 1) * row)


from functools import lru_cache
(n, m) = [int(i) for i in input().split()]
print((m - 1) * n if m != 1 else n - 1)


(a, b) = map(int, input().split())
print(max((b == 1) * (a - 1), (b - 1) * a))


infor = input().split()
rows = int(infor[0])
columns = int(infor[1])
if columns > 2:
	nums = columns - 1
	final = nums * rows
	print(final)
elif columns == 2:
	final = rows
	print(final)
else:
	final = rows - 1
	print(final)


import sys
import heapq
from collections import defaultdict
from functools import lru_cache
import threading

def Iinput():
	return int(input())

def Lsinput():
	return list(input().split())

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

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

def two():
	return map(int, input().split())
(m, n) = two()
if m == 1 or n == 1:
	print(max(m, n) - 1)
else:
	print((n - 1) * m)


import sys

def input(type=str):
	return type(sys.stdin.readline().strip())

def input_n(type=str):
	return list(map(type, input().split()))
(N, M) = input_n(int)
if M > 1:
	print((M - 1) * N)
else:
	print(N - 1)


(r, c) = map(int, input().split())
ans = 0
ans += r * (c - 1)
if c == 1:
	ans += r - 1
print(ans)


(N, M) = input().split()
if int(M) != 1:
	print((int(M) - 1) * int(N))
else:
	print(int(N) - 1)


(n, m) = map(int, input().split())
if m == 1:
	print(n - 1)
else:
	row = m - 1
	rows = n * row
	print(rows)


s = input()
s_lst = s.split()
y = 0
n = int(s_lst[0])
m = int(s_lst[-1])
if n == 1 and m == 2 or (n == 2 and m == 1):
	y = 1
elif m == 1 and n != 2 or (n == 1 and m != 2):
	y = max([n, m]) - 1
else:
	y = n * (m - 1)
print(y)


x = input().split(' ')
(n, m) = (int(x[0]), int(x[1]))
if m > 1:
	print((m - 1) * n)
else:
	print(n - 1)


(N, M) = map(int, input().split(' '))
if M > 1:
	print((M - 1) * N)
elif M == 1:
	print(N - 1)


x = list(map(int, input().split()))
if x[1] == 1:
	print(x[0] - 1)
else:
	print((x[1] - 1) * x[0])


(a, q) = map(int, input().split())
if q == 1:
	print(a - 1)
else:
	print((q - 1) * a)


import math
(n, m) = map(int, input().split())
if m > 1:
	print((m - 1) * n)
else:
	print(n - 1)


grid = input().split()
if int(grid[1]) == 1:
	print(int(grid[0]) - 1)
elif int(grid[1]) < 1:
	print(0)
else:
	print((int(grid[1]) - 1) * int(grid[0]))


a = list(map(int, input().split()))
(b, c) = (a[0], a[1])
if c == 1:
	print(b - 1)
else:
	print(b * (c - 1))


(n, m) = [int(x) for x in input().split()]
if m == 1 and n == 1:
	res = 0
elif m > 1:
	res = (m - 1) * n
else:
	res = (n - 1) * m
print(res)