#P9024. Total Fence Area

    ID: 22184 Type: Default 1000ms 256MiB

Total Fence Area

Total Fence Area

You are given a fence consisting of \(N\) wooden boards. Because these boards form a fence, the right boundary of the \(i\)-th board is the same as the left boundary of the \(i+1\)-th board.

You are provided with the heights of the fence boundaries and the widths of each board. The fence is described by \(N+1\) boundary heights \(h_0, h_1, \ldots, h_N\) and \(N\) board widths \(w_0, w_1, \ldots, w_{N-1}\). The area of the \(i\)-th board can be calculated using the trapezoid area formula:

\(A_i = \frac{h_i + h_{i+1}}{2} \times w_i\)

Output the total area of all boards, which is the sum \(\sum_{i=0}^{N-1} A_i\).

inputFormat

The first line contains a positive integer \(N\), the number of wooden boards. The second line contains \(N+1\) space-separated numbers representing the heights of the fence boundaries. The third line contains \(N\) space-separated numbers representing the widths of the wooden boards.

outputFormat

Output a single number representing the total area of the wooden boards.

sample

3
1 3 2 4
2 3 1
14.5