Teleportation

Given start a, end b, and a bidirectional teleporter linking x and y, find the minimum tractor distance to move from a to b, with the option to skip the teleporter.

Easy2MathImplementationBrute forceGreedyInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Of all the chores on the farm, the one Farmer John dislikes most is hauling around lots of cow manure. To cut the work down he built a new machine: the manure teleporter. Instead of carrying manure between two points in a cart behind his tractor, he sends it from one location to another instantly.

Farmer John's farm runs along a single long straight road, so every location on the farm is given by its position along that road, a point on the number line. A teleporter is described by two numbers xx and yy. Manure brought to location xx moves instantly to location yy, and manure brought to location yy moves instantly to location xx.

Farmer John wants to move manure from location aa to location bb, and he has built one teleporter that might help. He does not have to use it if it does not help. Determine the minimum total distance he has to haul the manure with his tractor.

Input

The first and only line contains four space separated integers aa, bb, xx and yy. Here aa and bb are the start and the end locations, and xx and yy describe the teleporter. Every position is an integer between 00 and 100100, and the positions are not necessarily distinct.

Output

Print one integer, the minimum distance Farmer John has to haul the manure with his tractor.

Note

Take a=3a = 3, b=10b = 10, x=8x = 8 and y=2y = 2. The best plan is to haul the manure from position 3 to position 2, teleport it to position 8, then haul it from there to position 10. The tractor covers 1 + 2 = 3 in total.