15054 - RedCapeFlyingCat's Hammer   

Description

RedCapeFlyingCat is standing at coordinate on a number line and wants to reach the goal at coordinate .

There is a wall at coordinate . At first, RedCapeFlyingCat cannot pass through coordinate . There is also a hammer at coordinate : once RedCapeFlyingCat arrives at coordinate , the hammer is picked up, and from then on the wall can be broken and passed through.

Determine whether RedCapeFlyingCat can reach the goal. If so, find the minimum total distance that has to be traveled.

Explanation

In the sample test case, , , and . The wall is farther away than the goal, so it is not in the way: RedCapeFlyingCat goes straight from to . The total distance is .

Two more examples (they are not given as sample test cases):

  • , , : the wall blocks the way to the goal. RedCapeFlyingCat first goes from to to pick up the hammer (distance ), then goes from to , breaking the wall on the way (distance ). The total distance is .
  • , , : the wall blocks the way to the goal, and it also blocks the way to the hammer. The goal cannot be reached, so the answer is -1.

Input

Three lines, each with one integer:

  • Line 1: , the coordinate of the goal
  • Line 2: , the coordinate of the wall
  • Line 3: , the coordinate of the hammer

Constraints

  • , and
  • , , and are distinct
  • All input values are integers

Output

One line containing one integer: the minimum total distance RedCapeFlyingCat has to travel to reach the goal.

If the goal cannot be reached, output -1.

Sample Input  Download

Sample Output  Download




Discuss