Ironman

Find the fastest path across n horizontal layers with different speeds, entering and exiting each layer boundary at an optimal x position, and print the minimum travel time.

Hard8Dynamic programmingMathGeometryBinary searchNo attempts yetTime limit2sMemory limit512 MB

Problem

An ironman triathlon puts the athlete through 3.86 km of swimming, 180.25 km of cycling and a full marathon, and it is one of the hardest races in the sport. Viveka trains for something harder, the n-athlon. In an n-athlon the racers cross several kinds of terrain, water, sand, ice, asphalt, on the way from the starting point to the finishing point, and each racer picks the route that suits her own strengths. Last year Viveka skated the final 40 km over ice in one hour and won, while her rival Veronica sat stuck in a tar pit one metre short of the finish.

The terrain map for this year is out, and Viveka's team wants the fastest route. The race area is flat and is modelled as the plane, measured in metres. It is cut into nn horizontal layers, and Viveka moves at speed viv_i everywhere inside layer ii, so the time she spends in a layer is the length of her path inside that layer divided by viv_i. She may not leave the race area. Compute the smallest time she needs to get from the starting point to the finishing point.

Input

The first line contains four decimal numbers xsx_s, ysy_s, xfx_f, yfy_f, the coordinates of the starting point and of the finishing point, in metres.

The second line contains one integer nn (1n100001 \le n \le 10\,000), the number of layers.

The third line contains n1n - 1 decimal numbers y1,y2,,yn1y_1, y_2, \dots, y_{n-1}, the yy coordinate of each boundary between consecutive layers, given in order, so that ys<y1<y2<<yn1<yfy_s < y_1 < y_2 < \dots < y_{n-1} < y_f. With y0=ysy_0 = y_s and yn=yfy_n = y_f, layer ii is the region (10000,10000)×(yi1,yi)(-10000, 10000) \times (y_{i-1}, y_i). When n=1n = 1 this line is empty.

The fourth line contains nn decimal numbers v1,,vnv_1, \dots, v_n, Viveka's speed in each layer, in metres per second. Every viv_i is positive.

Every decimal number in the input has absolute value at most 10410^4 and at most 4 digits after the decimal point.

Output

Print the minimum time in seconds for Viveka to get from the starting point to the finishing point, rounded to exactly 6 digits after the decimal point.