Circular Highway

Time limit1sMemory limit512 MB

Summary
Count starting stations on a circular road where buying all fuel and driving forward never empties the tank before returning.
Level

Medium5 of 10

Topics
Prefix sum, Greedy, Array
Solved
No attempts yet

Problem

Taeyoung's home city has one circular highway. The highway holds NN gas stations numbered 1 through NN. Driving forward from station ii brings you to station i+1i+1, and driving forward from station NN brings you back to station 1.

Station ii sells a fixed amount of fuel oio_i, and the road from station ii to the next station burns did_i units of fuel. Buying the fuel of every station gives exactly enough to go around the highway once, so the sum of the oio_i equals the sum of the did_i.

Taeyoung picks one station and starts there with an empty tank. At every station he reaches, he buys all the fuel that station sells, then drives on to the next station. If the fuel runs out before he reaches the next station, the car stops where it is.

In the picture each of the three stations sells 2 units of fuel. The road from station 1 to station 2 and the road from station 2 to station 3 cost 1 unit each, and the road from station 3 to station 1 costs 4 units. Starting at station 1 completes the loop.

Count the starting stations that let the car go all the way around without stopping. If there is no such station, the count is 0.

Input

The first line holds the number of gas stations NN (1≤N≤500,0001 \le N \le 500,000).

The second line holds NN integers. The iith integer is the amount of fuel oio_i (1≤oi≤1,000,0001 \le o_i \le 1,000,000) that station ii sells.

The third line holds NN integers. The iith integer is the amount of fuel did_i (1≤di≤1,000,0001 \le d_i \le 1,000,000) burned on the road from station ii to station i+1i+1. Station N+1N+1 is station 1.

The sum of the oio_i always equals the sum of the did_i.

Output

Print on one line the number of starting stations from which the car goes around the highway without stopping.

Examples3

  1. Example 1

    Input
    3
    2 2 2
    1 1 4
    
    Expected output
    1
    
  2. Example 2

    Input
    4
    2 2 2 2
    2 2 2 2
    
    Expected output
    4
    
  3. Example 3

    Input
    1
    7
    7
    
    Expected output
    1