PDP-24 (2012) - Camp junior - 2 (knight)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

KNIGHT

You are given a chessboard with dimensions N \times M, in the bottom-left corner of which there is a knight. In chess, the knight moves in an "L" shape, which means two squares in one direction (horizontally or vertically) and one square in the perpendicular direction. The task is to find the minimum number of moves the knight must make to reach the top-right corner of the chessboard.

Input

The first line of the input contains two integers N and M, separated by a single space: the dimensions of the chessboard.

Output

The output should consist of a single line containing exactly one integer: the minimum number of moves required to bring the knight from the bottom-left to the top-right corner of the chessboard.

Constraints

5 \le N, M \le 1.000.
Execution time limit: 1 sec.
Memory limit: 128 MB.

Examples of Input - Output
1st

STDIN (knight.in)

5 6

STDOUT (knight.out)

3

pdp-2012-camp-j2-fig-1.svg

2nd

STDIN (knight.in)

8 8

STDOUT (knight.out)

6

pdp-2012-camp-j2-fig-2.svg


Comments

There are no comments at the moment.