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 x and y. Manure brought to location x moves instantly to location y, and manure brought to location y moves instantly to location x.
Farmer John wants to move manure from location a to location b, 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.