Under construction

Still being built. Things may change

Scissors

Time limit2sMemory limit1024 MB

Summary
Find the total length of the grid-line cuts for an inward spiral on an n by m sheet that never splits the paper.
Level

Easy3 of 10

Topics
Math, Simulation
Solved
No attempts yet

Statement

In October 1988, on a rainy morning in the town of Derry, Bill Denbrough, a teenager who stutters, makes a paper boat for his seven-year-old brother Georgie.

To make a good boat, Bill has to cut a perfect square from paper, and he needs good scissors for that. He found a pair of scissors in his drawer and wants to test how they cut.

For the test, Bill takes the scissors and a sheet of grid paper of size nn by mm cells. He cuts a grid spiral that winds to the right out of the sheet. All cuts go only along grid lines. Formally:

  • Bill steps 1 cell in from the left edge.
  • He cuts a straight line upward, one cell at a time, until the next cut would split the figure into two parts.
  • Then he cuts a straight line to the right by the same rules, then changes direction and cuts downward, and so on …\dots
  • He keeps cutting until, when he changes direction, there is nothing left to cut.

The picture shows an example of the resulting spiral, with the cut lines in red.

Georgie wants to play with the boat as soon as possible, so he needs the total length of the cuts Bill has to make to know when he is done. Help Georgie compute this value.

Input

The only line contains two natural numbers nn and mm, the dimensions of the sheet Bill cuts the spiral from (2≤n,m≤1092 \le n, m \le 10^9).

Output

Print one number: the total length of the cuts Bill has to make to get the spiral.

Examples2

  1. Example 1

    Input
    3 3
    
    Expected output
    4
    
  2. Example 2

    Input
    3 4
    
    Expected output
    6