#abc076d. [abc076_d]AtCoder Express

[abc076_d]AtCoder Express

Score : 400400 points

Problem Statement

In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.

In the plan developed by the president Takahashi, the trains will run as follows:

  • A train will run for (t1+t2+t3+...+tN)(t_1 + t_2 + t_3 + ... + t_N) seconds.
  • In the first t1t_1 seconds, a train must run at a speed of at most v1v_1 m/s (meters per second). Similarly, in the subsequent t2t_2 seconds, a train must run at a speed of at most v2v_2 m/s, and so on.

According to the specifications of the trains, the acceleration of a train must be always within ±1m/s2±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.

Find the maximum possible distance that a train can cover in the run.

Constraints

  • 1leqNleq1001 \\leq N \\leq 100
  • 1leqtileq2001 \\leq t_i \\leq 200
  • 1leqvileq1001 \\leq v_i \\leq 100
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

NN t1t_1 t2t_2 t3t_3tNt_N v1v_1 v2v_2 v3v_3vNv_N

Output

Print the maximum possible that a train can cover in the run.
Output is considered correct if its absolute difference from the judge's output is at most 10310^{-3}.


Sample Input 1

1
100
30

Sample Output 1

2100.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 3030 seconds, it accelerates at a rate of 1m/s21m/s^2, covering 450450 meters.
  • In the subsequent 4040 seconds, it maintains the velocity of 30m/s30m/s, covering 12001200 meters.
  • In the last 3030 seconds, it decelerates at the acceleration of \-1m/s2\-1m/s^2, covering 450450 meters.

The total distance covered is 450450 + 12001200 + 450450 = 21002100 meters.


Sample Input 2

2
60 50
34 38

Sample Output 2

2632.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 3434 seconds, it accelerates at a rate of 1m/s21m/s^2, covering 578578 meters.
  • In the subsequent 2626 seconds, it maintains the velocity of 34m/s34m/s, covering 884884 meters.
  • In the subsequent 44 seconds, it accelerates at a rate of 1m/s21m/s^2, covering 144144 meters.
  • In the subsequent 88 seconds, it maintains the velocity of 38m/s38m/s, covering 304304 meters.
  • In the last 3838 seconds, it decelerates at the acceleration of \-1m/s2\-1m/s^2, covering 722722 meters.

The total distance covered is 578578 + 884884 + 144144 + 304304 + 722722 = 26322632 meters.


Sample Input 3

3
12 14 2
6 2 7

Sample Output 3

76.000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 66 seconds, it accelerates at a rate of 1m/s21m/s^2, covering 1818 meters.
  • In the subsequent 22 seconds, it maintains the velocity of 6m/s6m/s, covering 1212 meters.
  • In the subsequent 44 seconds, it decelerates at the acceleration of \-1m/s2\-1m/s^2, covering 1616 meters.
  • In the subsequent 1414 seconds, it maintains the velocity of 2m/s2m/s, covering 2828 meters.
  • In the last 22 seconds, it decelerates at the acceleration of \-1m/s2\-1m/s^2, covering 22 meters.

The total distance covered is 1818 + 1212 + 1616 + 2828 + 22 = 7676 meters.


Sample Input 4

1
9
10

Sample Output 4

20.250000000000000000

The maximum distance is achieved when a train runs as follows:

  • In the first 4.54.5 seconds, it accelerates at a rate of 1m/s21m/s^2, covering 10.12510.125 meters.
  • In the last 4.54.5 seconds, it decelerates at the acceleration of \-1m/s2\-1m/s^2, covering 10.12510.125 meters.

The total distance covered is 10.12510.125 + 10.12510.125 = 20.2520.25 meters.


Sample Input 5

10
64 55 27 35 76 119 7 18 49 100
29 19 31 39 27 48 41 87 55 70

Sample Output 5

20291.000000000000