10235: CCC '17 S1 - Sum Game
Description
Annie has two favourite baseball teams: the Swifts and the Semaphores. She has followed them throughout the season, which is now over. The season lasted for $N$ days. Both teams played exactly one game on each day.
For each day, Annie recorded the number of runs scored by the Swifts on that day. She also recorded this information for the Semaphores.
She would like you to determine the largest integer $K$ such that $K\leq N$ and the Swifts and the Semaphores had scored the same total number of runs $K$ days after the start of the season. The total number of runs scored by a team after $K$ days is the sum of the number of runs scored by the team in all games before or on the $K$-th day.
For example, if the Swifts and the Semaphores have the same total number of runs at the end of the season, then you should output $N$. If the Swifts and the Semaphores never had the same number of runs after $K$ games, for any value of $K≤N$, then output 0.
Input
The first line of input will contain an integer $N\ (1≤N≤100,000)$.
The second line will contain $N$ space-separated non-negative integers representing the number of runs scored by the Swifts on each day, in order.
The third line will contain $N$ space-separated non-negative integers representing the number of runs scored by the Semaphores on each day, in order.
You may assume that each team scored at most 20 runs in any single game.
Output
Sample 1 Input
3
1 3 3
2 2 6
Sample 1 Output
2
Sample 2 Input
3
1 2 3
4 5 6
Sample 2 Output
0
Sample 3 Input
4
1 2 3 4
1 3 2 4
Sample 3 Output
4