Welcome to ZOJ
 Problem Sets Information Select Problem Runs Ranklist
ZOJ Problem Set - 3536
Move the Mouse II

Time Limit: 1 Second      Memory Limit: 65536 KB

Mike was addicted to a game called "move the mouse" these days. The game was played in a computer. Assume the monitor had W in width and H in height. There was a rectangle of a×b in the screen, whose center had the same position as the mouse. As the mouse moves, the rectangle moved keeping the positions of the center and the mouse the same. Also, you could click the mouse, which made the rectangle rotate 90 degrees clockwise. But there was a constraint that when doing the movement and rotation, any point in the rectangle should NOT get out of the screen, or you will lose the game.

Assume the mouse can move in any direction(it's not necessary to move integer distance). Here, given the status(position and the direction) of the rectangle in the initial and in the end, you have to work out the minimum distance the mouse has to move to make the rectangle from initial status to the final status. Can you help Mike solve this problem?

#### Input

There are multiple test cases.

The first line of each case contains four integers W, H, a, b (0 < aW, 0 < bH, W, H ≤ 104). The second line contains 6 integers x1, y1, t1, x2, y2, t2 (0 ≤ x1, x2W, 0 ≤ y1, y2H, t1, t2 ∈ {1, 2}). (x1, y1) is the initial position and (x2, y2) is the final position. t1 and t2 are the initial and final directions. 1 represents the rectangle is a×b and 2 represents b×a.

#### Output

If any point in the rectangle given at the beginning or at the end is already out of the screen, or it's impossible to finish the movement, print one line containing "-1" (quotes for clarity), otherwise, print the minimum distance to move in a single line, rounded to 3 digits after the decimal point.

#### Sample Input

```5 6 1 2
0 3 1 0 3 1
8 8 1 3
1 4 1 4 4 2
```

#### Sample Output

```-1
3.000
```

Author: ZHUANG, Junyuan
Contest: ZOJ Monthly, September 2011
Submit    Status