cswork / OAOpen practice workspace

MicrosoftOA #20

Find Fair Indexes

Estimated EasyJudge-ready

Topics (AI-labelled)Prefix & Ranges

A fair index K splits A and B each into two non-empty parts such that the sums of all four parts are equal. Count the fair indices, where K ranges over 1..N−1. Some of the original site's explanations had the wrong indices; this site corrected them example by example.

Input

This site's input: the first line contains N (1..100000), the second line contains A, and the third line contains B, each with N integers (−10⁹..10⁹).

Output

Output a single integer, the answer.

Example 1

Input:

4
4 -1 0 3
-2 5 0 3

Output:

2

Example 2

Input:

4
2 -2 -3 3
0 0 4 -4

Output:

1

Example 3

Input:

4
4 -1 0 3
-2 6 0 4

Output:

0

Example notes

Example 1: for K=2 and K=3 all four parts sum to 3, so the count is 2.

Example 2: only K=2 is valid, with all four parts summing to 0; the original site's K=1 is incorrect, and the count is still 1.

Example 3: the two arrays sum to 6 and 8, so the four parts cannot be equal; the answer is 0.

Editorial

Loading solution…