#AGC023A. [AGC023A] Zero-Sum Ranges

[AGC023A] Zero-Sum Ranges

Score : 200200 points

Problem Statement

We have an integer sequence AA, whose length is NN.

Find the number of the non-empty contiguous subsequences of AA whose sums are 00. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individually if they are taken from different positions.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 109Ai109-10^9 \leq A_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 ...... ANA_N

Output

Find the number of the non-empty contiguous subsequences of AA whose sum is 00.

6
1 3 -4 2 2 -2
3

There are three contiguous subsequences whose sums are 00: (1,3,4)(1,3,-4), (4,2,2)(-4,2,2) and (2,2)(2,-2).

7
1 -1 1 -1 1 -1 1
12

In this case, some subsequences that have the same contents but are taken from different positions are counted individually. For example, three occurrences of (1,1)(1, -1) are counted.

5
1 -2 3 -4 5
0

There are no contiguous subsequences whose sums are 00.