Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-aylana-yol

Circular road

Medium 1000 ms 128 MB 62%
Share

There are $n$ gas stations on a circular road, numbered from $1$ to $n$. At the $i$-th station the car gets $g_{i}$ liters of fuel, and the trip to the next station (after the $n$-th — to the $1$-st) uses $c_{i}$ liters. The tank is infinitely large. The car starts with an empty tank at some station, must go all the way around the circle and return to the same station; along the way the fuel in the tank must never become negative. Among such starting stations find the one with the smallest number; if there is none, print $-1$.

Stations on a circle: the fuel added at each one and the fuel used to reach the next, the starting station highlighted

Input

The first line contains a positive integer $n$. The second line contains $n$ integers $g_{i}$, the third line contains $n$ integers $c_{i}$.

Output

One integer — the station number or $-1$.

Note

$1 \le n \le 10^{5}$
$0 \le g_{i}, c_{i} \le 10^{9}$

Examples

Input #1
5
1 2 3 4 5
3 4 5 1 2
Output #1
4
Input #2
3
2 3 4
3 4 3
Output #2
-1

Sign in to submit a solution

Signing up is free and takes a minute.