RithwikG's picture
initial commit
7a8878c
raw
history blame contribute delete
754 Bytes
Eugene likes working with arrays. And today he needs your help in solving one challenging task.An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.Let's call a nonempty array good if for every nonempty subarray of this array, sum of the elements of this subarray is nonzero. For example, array [βˆ’1,2,βˆ’3] is good, as all arrays [βˆ’1], [βˆ’1,2], [βˆ’1,2,βˆ’3], [2], [2,βˆ’3], [βˆ’3] have nonzero sums of elements. However, array [βˆ’1,2,βˆ’1,βˆ’3] isn't good, as his subarray [βˆ’1,2,βˆ’1] has sum of elements equal to 0.Help Eugene to calculate the number of nonempty good subarrays of a given array a.