PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000153. Eugene và dãy số (Eugene and an Array)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Eugene và dãy số (Eugene and an Array)

Eugene and an Array

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Eugene has an integer array a1,a2,…,ana_1,a_2,\ldots,a_n. A nonempty contiguous interval [l,r][l,r] is good if every nonempty contiguous interval contained in it has a nonzero sum. In other words, ∑i=uvai≠0\sum_{i=u}^v a_i\ne0 must hold for all l≤u≤v≤rl\le u\le v\le r. Count the good intervals. A nonzero sum of the whole interval alone is insufficient.

Input

  • Line 1: integer nn, the number of elements.
  • Line 2: nn integers a1,…,ana_1,\ldots,a_n in order.

Output

Print the number of qualifying intervals as one integer.

Subtasks

  • Subtask 1 (20 points): 1≤n≤5001\le n\le 500; −1000000000≤aj≤1000000000-1000000000\le a_j\le 1000000000 for every 1≤j≤n1\le j\le n.
  • Subtask 2 (30 points): 1≤n≤2000001\le n\le 200000; 0≤aj≤10000000000\le a_j\le 1000000000 for every 1≤j≤n1\le j\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −1000000000≤aj≤1000000000-1000000000\le a_j\le 1000000000 for every 1≤j≤n1\le j\le n.

Example 1

Input

3
1 2 -3

Output

5

Explanation

The three singletons and both length-two intervals are good. The whole array sums to zero.

Example 2

Input

3
41 -41 41

Output

3

Explanation

All three singletons are good. Both length-two intervals sum to zero; the whole array contains them and is not good even though its sum is 41.