Menu Close

Find the number of steps on chessboard performed to satisfy a condition..

Elavenil has a chessboard with N rows and M columns. In one step, he can choose two cells of the chessboard which share a common edge (that has not been cut yet) and cut this edge.

Formally, the chessboard is split into two or more pieces if it is possible to partition its cells into two non-empty subsets S1 and S2 (S1∩S2=∅, |S1|+|S2|=NM) such that there is no pair of cells c1,c2 (c1∈S1,c2∈S2) which share a common edge that has not been cut.

Elavenil does not want the board to split into two or more pieces. Compute the maximum number of steps he can perform while satisfying this condition.

Input:
The only line of input contains two integers N and M. 

Output:
Print an integer representing the maximum possible number of steps.
#include <stdio.h>
int main() {
    int n,m;
    scanf("%d %d",&m,&n);
    printf("%d",(m-1)*(n-1));
    return 0;
}

INPUT_1:
Rows and Columns:  7  4

OUTPUT:
Maximum Number of steps:  18


INPUT_2:
Rows and Columns:  6  2

OUTPUT:
Maximum Number of steps:  5



INPUT_3:
Rows and Columns:  4  3

OUTPUT:
Maximum Number of steps:  6


INPUT_4:
Rows and Columns:  10  9

OUTPUT:
Maximum Number of steps:  72


ILLUSTRATION

Executed using gcc linux

Morae Q!