410090: GYM103940 G Guadalajara trains

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Guadalajara trainstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

In Guadalajara, the most recent train line is the Pi Line. The name is because it's after the third line and before the fourth line.

This line has two train rails and $$$N$$$ stations, one rail is for a train that goes from station 1 to station $$$N$$$, and the other one is for a train that goes from station $$$N$$$ to station 1. At each station, there is a given time for the train to wait to pick people up that can vary from station to station. Both trains have the same speed (1km/s) and the distance between each station is known. JP began is wondering how long both of the trains will be waiting in the same station?

Knowing the distance between consecutive stations, the time that the trains wait at each station, and the fact that the two trains begin to work at the same time, help JP to answer his question!

Input

The first line contains a single integer $$$N$$$ ($$$2 \leq N \leq 10^6$$$) representing the number of stations in the Pi line. The next line contains be $$$N - 1$$$ integers separated by a space where the $$$a_i$$$ ($$$1 \leq a_i \leq 10^6$$$) integer represents the distance between the station $$$i$$$ and the station $$$i + 1$$$. The third and last line of input contains $$$N$$$ integers separated by a space where the $$$x_i$$$ ($$$1 \leq x_i \leq 10^6$$$) integer represents the time that the train will be waiting at station $$$i$$$.

Output

Print a line with a single integer that indicates the time the two trains are waiting in the same station.

ExamplesInput
3
1 1
1 10 1
Output
10
Input
3
1 5
1 10 1
Output
6
Input
6
20 13 10 15 20
10 21 5 10 20 7
Output
0

加入题单

算法标签: