THE QUESTION
Text from the official booklet. Refer to the PDF for original mathematical notation, formatting, and linked input files. Printed samples and inputs are reproduced as published.
A courier needs to deliver a package along a straight road, represented as a number line. The package must be transported from position 𝑎 to position 𝑏, and the goal is to minimize the total distance traveled by vehicle. To assist with transportation, there is a teleporter installed between two fixed locations, 𝑥 and 𝑦. If the package reaches 𝑥, it can be instantly teleported to 𝑦, and vice versa. However, the courier still needs to travel by vehicle to and from any locations that are not connected by teleportation. Determine the shortest total distance the courier must travel by vehicle to move the package from 𝑎 to 𝑏. INPUT FORMAT: The first and only line of input contains four space-separated integers: a and b, describing the start and end locations, followed by x and y, describing the teleporter. All positions are integers in the range 0…100, and they are not necessarily distinct from each-other. OUTPUT FORMAT: A single integer, representing the minimum distance the courier must travel by vehicle to move the package from 𝑎 to 𝑏. SAMPLE INPUT: 3 10 8 2 SAMPLE OUTPUT: 3 In this example, the best strategy is to move the package from position 3 to position 2, teleport it to position 8, then move it to position 10. The total distance requiring the vehicle is therefore 1 + 2 = 3. Input Case 1: 35 68 2 30 Case 2: 58 23 67 70