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

#CC0000040. Đếm đoạn con có tổng bằng không (Zero-Sum Ranges)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đếm đoạn con có tổng bằng không (Zero-Sum Ranges)

Zero-Sum Ranges

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array, count nonempty contiguous subarrays whose sum equals 00. Different endpoint pairs count separately even if their values are identical.

Input

The first line contains nn. The next line contains nn integers aia_i.

Output

Print the number of zero-sum subarrays.

Subtasks

  • Subtask 1 (20 points): 1≤n≤151\le n\le 15; −109≤ai≤109-10^9\le a_i\le 10^9.
  • Subtask 2 (30 points): 1≤n≤4201\le n\le 420; −109≤ai≤109-10^9\le a_i\le 10^9.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; −109≤ai≤109-10^9\le a_i\le 10^9.

Examples

Input

6
1 3 -4 2 2 -2

Output

3

Explanation

The three zero-sum subarrays are [1,3,−4][1,3,-4], [−4,2,2][-4,2,2] and [2,−2][2,-2].