B - Hammer Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200

問題文

数直線の原点に高橋君がいます。高橋君は座標 X にあるゴールに移動しようとしています。

座標 Y には壁があり、最初、高橋君は壁を超えて移動することができません。
座標 Z にあるハンマーを拾った後でなら、壁を破壊して通過できるようになります。

高橋君がゴールに到達することが可能か判定し、可能であれば移動距離の最小値を求めてください。

制約

  • -1000 \leq X,Y,Z \leq 1000
  • X,Y,Z は相異なり、いずれも 0 でない
  • 入力に含まれる値は全て整数である

入力

入力は以下の形式で標準入力から与えられる。

X Y Z

出力

高橋君がゴールに到達することが可能であれば、移動距離の最小値を出力せよ。不可能であれば、かわりに -1 と出力せよ。


入力例 1

10 -10 1

出力例 1

10

高橋君はまっすぐゴールに向かうことができます。


入力例 2

20 10 -10

出力例 2

40

ゴールは壁の向こう側にあります。まずハンマーを拾い、壁を壊すことでゴールに到達することができます。


入力例 3

100 1 1000

出力例 3

-1

Score : 200 points

Problem Statement

Takahashi is at the origin of a number line. He wants to reach a goal at coordinate X.

There is a wall at coordinate Y, which Takahashi cannot go beyond at first.
However, after picking up a hammer at coordinate Z, he can destroy that wall and pass through.

Determine whether Takahashi can reach the goal. If he can, find the minimum total distance he needs to travel to do so.

Constraints

  • -1000 \leq X,Y,Z \leq 1000
  • X, Y, and Z are distinct, and none of them is 0.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

X Y Z

Output

If Takahashi can reach the goal, print the minimum total distance he needs to travel to do so. If he cannot, print -1 instead.


Sample Input 1

10 -10 1

Sample Output 1

10

Takahashi can go straight to the goal.


Sample Input 2

20 10 -10

Sample Output 2

40

The goal is beyond the wall. He can get there by first picking up the hammer and then destroying the wall.


Sample Input 3

100 1 1000

Sample Output 3

-1