cswork / OA打开练习工作台

AmazonOA #13

Get Total Balanced

估计中等可在线判题

考点(AI 标注)前缀和区间哈希计数

You are given an array of positive integer capacities. A contiguous segment of length at least 3 is balanced if and only if its left-end capacity, its right-end capacity, and the sum of all capacities between the two ends are all equal. Find the number of balanced segments.

输入格式

The first line contains n (1..100000), and the second line contains n capacities (1..10⁹).

输出格式

Output one integer, the answer required by the problem.

样例 1

输入:

5
9 3 3 3 9

输出:

2

样例 2

输入:

2
1 1

输出:

0

样例 3

输入:

3
2 2 2

输出:

1

样例说明

Example 1 contains two balanced segments: the whole [9,3,3,3,9] and the middle [3,3,3].