Janica did poorly on the first slalom. To win, she must finish the second slalom as quickly as possible by taking the shortest possible route.
The start and finish are two points in the plane. Each gate that the skier must pass through is a line segment parallel to the x-axis. If you list the y-coordinate of the start point, then the y-coordinates of the gates in the order they must be passed, and finally the y-coordinate of the finish point, the sequence is strictly decreasing.
A path from the start to the finish is made by joining line segments. The first segment goes from the start point to a point on the first gate, each following segment connects points on two consecutive gates, and the last segment goes from a point on the last gate to the finish point. Two consecutive segments share the same endpoint, and that shared endpoint must lie on the gate represented by the corresponding line segment.
Find the length of the shortest possible path that starts at the start point, passes through every gate in order, and ends at the finish point.
The first line contains an integer N, the number of gates. (1 <= N <= 5000)
The second line contains two integers XS and YS separated by a space, the coordinates of the start point.
Each of the next N lines contains three integers X1, X2, and Y separated by spaces. It is guaranteed that X1 < X2, and the corresponding gate has endpoints (X1, Y) and (X2, Y). The gates are given in the order in which the skier must pass through them.
The last line contains two integers XC and YC separated by a space, the coordinates of the finish point.
The absolute value of every coordinate in the input is at most 15000.
Print the length of the shortest path on the first line. The value should be rounded to four decimal places; an absolute or relative error of at most 0.0001 is accepted.