Parabolic teleports#6864

Parabolic teleports

2 seconds
64 megabytes
Hard

Flatland is a plane with a Cartesian coordinate system . Citizens of Flatland are points that move with the speed . Consequently, the minimal time it takes for a Flatlander to move from point to point is equal to the length of the line segment . This fact is taught in the schools of Flatland as the "shortest path theorem".

However, since George Edward Nius invented the devices called parabolic teleports, the theorem no longer holds. A parabolic teleport is a contiguous section of a parabola along which it is possible to move with infinite speed. In other words, it is possible to move from any point on the parabolic teleport to any other point on the same parabolic teleport in zero time.

The points that belong to the teleport are given by the formulae y = Ax^2+Bx+C, X_L \le x \le X_R, where , , , X_L, X_R are the parameters of the teleport.

After inventing the teleports, G.E.Nius founded a company to build them. At the moment, the company has already built of those devices. One might imagine that they are shoveling money left and right, but…

But in practice, the Flatlanders still think the shortest path theorem is true and nobody has even tried the parabolic teleports. To help the situation, G.E.Nius has hired you to write a program that, given two points and , would compute the time it would take to move from to using the teleports the company has already built. The idea is that the users of the program will see that the time is less than the length of the segment and start to use the invention of Mr. Nius.

Are you up to the task?

Input

The first line of the file contains the integer (0 \le N \le 100), the number of the teleports. On the second line of the file are the integers X_V and Y_V (-100 \le X_V \le 100, -1000000 \le Y_V \le 1000000), the coordinates of the source point . On the third line of the file are the integers X_W and Y_W (-100 \le X_W \le 100, -1000000 \le Y_W \le 1000000), the coordinates of the destination point .

Each of the following lines contains integers, separated by spaces, that describe the ith teleport – giving its parameters A_i, B_i, C_i, X_{L_i}, X_{R_i} (-100 \le A_i, B_i, C_i \le 100, A_i \ne 0, -100 \le X_{L_i} < X_{R_i} \le 100).

Output

The first and only line of the output file should contain one real number, the minimal time it takes to move from point to point . The absolute error of the answer must not exceed 10^{-4}.

Examples

Example 1

Loading
Loading