410090: GYM103940 G Guadalajara trains
Description
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!
InputThe 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$$$.
OutputPrint a line with a single integer that indicates the time the two trains are waiting in the same station.
ExamplesInput3 1 1 1 10 1Output
10Input
3 1 5 1 10 1Output
6Input
6 20 13 10 15 20 10 21 5 10 20 7Output
0