Pusheen has been dreaming about tuna sashimi! She has decided that she needs to eat more tuna in her life, so she decides to visit her favourite restaurant to eat tuna sashimi and tuna nigiri.
Pusheen decides to take her helicopter to her favourite restaurant. Due to various regulations, Pusheen is required
to fix the helicopter at a specific altitude if she's not taking off or landing, so the helicopter can be
effectively treated as traveling in a 2D plane. Due to fuel restrictions, Pusheen will travel only to points
The helicopter is a bit finicky to maneuver, so in a single second, Pusheen can only change either the velocity of the helicopter in the x-direction or the y-direction by one unit. Pusheen is not required to change the velocity of the helicopter within a second. Note that the change in velocity happens before the helicopter moves within that second - this means that at the end of every second, Pusheen is guaranteed to be at a lattice point. Pusheen can only board/disembark from the helicopter when it is not moving.
More formally, if Pusheen's location at the beginning of second
It's also a windy day! Some lattice points have high winds that Pusheen must not fly through at any point in time. Help Pusheen figure out if she can get to her favourite restaurant, and figure out how quickly she can do so!
Constraints
Pusheen's starting and ending locations will not have wind.
All
In tests worth 1 mark,
In tests worth 2 additional marks,
In tests worth 3 additional marks,
Input Specification
The first line contains three nonnegative integers,
The next line contains two nonnegative integers,
The next line contains two nonnegative integers,
The next
Output Specification
If Pusheen cannot make it to her favourite restaurant, output -1
. Otherwise, output the minimum number of seconds
needed for Pusheen to be able to make it to her favourite restaurant.
Sample Input 1
1 0 0
0 0
1 0
Sample Output 1
2
Sample Input 2
4 0 0
0 0
4 0
Sample Output 2
4
Sample Input 3
1 1 0
0 0
1 1
Sample Output 3
4
Sample Input 4
2 0 1
0 0
2 0
1 0
Sample Output 4
-1
Comments