http://www.elijahqi.win/2018/03/03/usaco2018-feb-cu-teleportation/
One of the farming chores Farmer John dislikes the most is hauling around lots of cow manure. In order to streamline this process, he comes up with a brilliant invention: the manure teleporter! Instead of hauling manure between two points in a cart behind his tractor, he can use the manure teleporter to instantly transport manure from one location to another.
Farmer John’s farm is built along a single long straight road, so any location on his farm can be described simply using its position along this road (effectively a point on the number line). A teleporter is described by two numbers x
x
and y
y
, where manure brought to location x
x
can be instantly transported to location y
y
, or vice versa.
Farmer John wants to transport manure from location a<