Torus Sea

On a torus of size N by M, a random walk moves diagonally each day; find the expected number of days to first reach (x, y), or -1 if unreachable.

Medium6ProbabilityGraphMathNo attempts yetTime limit2sMemory limit512 MB

Problem

Sanggeun is sailing the Doughnut Sea. The sea has the shape of a torus and is divided into N×MN \times M cells.

(Image by YassineMrabet from Wikimedia Commons, licensed under CC BY-SA 3.0.)

Every cell has coordinates (n,m)(n, m) with 0n<N0 \le n < N and 0m<M0 \le m < M. Coordinates are always kept as remainders modulo NN and MM, so the sea wraps around in both directions. Increasing the first coordinate from N1N-1 gives 00, and decreasing it from 00 gives N1N-1. The second coordinate wraps the same way modulo MM.

Sanggeun starts at (0,0)(0, 0) and wants to reach (x,y)(x, y). He moves once per day. From (n,m)(n, m) he goes to ((n+1)modN,(m+1)modM)((n+1) \bmod N, (m+1) \bmod M) or to ((n1)modN,(m1)modM)((n-1) \bmod N, (m-1) \bmod M), each with probability 1/21/2. Here amodba \bmod b is the remainder in [0,b)[0, b).

Write a program that computes the expected number of days until Sanggeun first reaches (x,y)(x, y).

Input

The first line contains NN, MM, xx, yy, separated by spaces. (2N,M102 \le N, M \le 10, 0xN10 \le x \le N-1, 0yM10 \le y \le M-1)

(x,y)(x, y) is not (0,0)(0, 0).

Output

Print the expected number of days until Sanggeun first reaches (x,y)(x, y). This expected value is always an integer, so print a single integer with no decimal point and no trailing digits.

If (x,y)(x, y) cannot be reached, print -1.