CF152B Steps
Description
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangular $ n×m $ field. The squares have coordinates $ (x,y) $ ( $ 1
Input Format
The first input line contains two integers $ n $ and $ m $ ( $ 1
Output Format
Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Explanation/Hint
In the first sample Vasya is initially positioned at square $ (1,1) $ and makes $ 3 $ steps by the first vector $ (1,1) $ . So, he consecutively visits the squares $ (2,2),(3,3),(4,4) $ . Then he makes $ 0 $ steps by the second vector $ (1,1) $ . He makes $ 1 $ more step by the third vector $ (0,-2) $ and he ends up in square $ (4,2) $ . Overall, Vasya makes $ 4 $ steps.
In the second sample Vasya is initially positioned in square $ (1,2) $ and makes $ 0 $ steps by vector $ (-1,0) $ , as the square with coordinates $ (0,2) $ is located outside the yard.