Under construction

Still being built. Things may change

A Path to Nowhere

Time limit2sMemory limit1024 MB

Summary
Given an n by m grid and a start cell, count the cells visited by a spiral walk with step lengths 1, 1, 2, 2, 3, 3, and so on, until it leaves the grid.
Level

Medium5 of 10

Topics
Simulation, Math
Solved
No attempts yet

Statement

Kolobok has a strange dream. In the dream, Kolobok stands on a grid field of size n×mn \times m at cell (x,y)(x, y).

At the start, Kolobok faces the positive direction of the X axis. Then he walks across the field following this pattern:

  • Move one cell forward. Turn 90 degrees to the right.
  • Move one cell forward. Turn 90 degrees to the right.
  • Move two cells forward. Turn 90 degrees to the right.
  • Move two cells forward. Turn 90 degrees to the right.
  • Move three cells forward. Turn 90 degrees to the right.
  • Move three cells forward. Turn 90 degrees to the right.
  • Move four cells forward. Turn 90 degrees to the right.
  • And so on...

The movement continues until Kolobok leaves the field. Then he wakes up.

In the morning, Kolobok wants to analyze his dream. He is sure that he was in each cell at most once, but he cannot remember how many cells he visited. Write a program that counts the cells he visited.

Input

The first line contains two positive integers nn and mm (1≤n,m≤1091 \le n, m \le 10^9), the sizes of the board along the X axis and the Y axis. The second line contains two positive integers xx and yy (1≤x≤n1 \le x \le n; 1≤y≤m1 \le y \le m), the start position of Kolobok.

Output

Print one number, the count of cells Kolobok visited during the dream.

Hint

The picture shows the first example.

Examples3

  1. Example 1

    Input
    7 6
    3 4
    
    Expected output
    36
    
  2. Example 2

    Input
    2 2
    1 1
    
    Expected output
    2
    
  3. Example 3

    Input
    2 2
    1 2
    
    Expected output
    4