Under construction

Still being built. Things may change

Sum Game

Time limit1sMemory limit512 MB

Summary
Given two length-N sequences of daily scores, find the largest K where the prefix sums of both sequences are equal.
Level

Easy3 of 10

Topics
Prefix sum, Array
Solved
No attempts yet

Problem

Annie has two favourite baseball teams, the Swifts and the Semaphores. She followed both of them through the season that just ended. The season lasted NN days, and each team played exactly one game every day.

For each day Annie wrote down how many runs the Swifts scored. She wrote down the same figure for the Semaphores.

She wants the largest integer KK with K≤NK \le N such that the Swifts and the Semaphores had scored the same total number of runs KK days after the start of the season. A team's total after KK days is the sum of the runs it scored in every game up to and including day KK.

For example, if the two teams have the same total at the end of the season, print NN. If the two teams never had the same total after KK games for any K≤NK \le N, print 0.

Input

The first line contains an integer NN (1≤N≤100 0001 \le N \le 100\,000).

The second line contains NN space separated integers, the runs the Swifts scored on each day, in order.

The third line contains the runs the Semaphores scored on each day, in the same format.

Every score is a non-negative integer, and neither team scores more than 20 runs in a single game.

Output

Print on one line the largest integer KK with K≤NK \le N such that the Swifts and the Semaphores have the same total number of runs after KK days.

Hint

In the first example both teams had scored 4 runs after 2 days.

In the second example the only moment when the two totals matched was the start of the season.

In the third example the totals match after the first game, after the third game, and after the fourth game. The largest of those values, 4, is the answer.

Examples3

  1. Example 1

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

    Input
    3
    1 2 3
    4 5 6
    
    Expected output
    0
    
  3. Example 3

    Input
    4
    1 2 3 4
    1 3 2 4
    
    Expected output
    4