Under construction

Still being built. Things may change

Daisy Chains

Interview

Time limit1sMemory limit512 MB

Summary
Count subarrays whose average equals the value of some element inside that subarray.
Level

Easy3 of 10

Topics
Array, Brute force, Prefix sum, Implementation
Solved
No attempts yet

Problem

Every day, as part of her walk around the farm, Bessie the cow visits her favorite pasture, which has NN flowers (all colorful daisies) labeled 1…N1\ldots N lined up in a row (1≤N≤100)(1\le N \le 100). Flower ii has pip_i petals (1≤pi≤1000)(1 \le p_i \le 1000).

As a budding photographer, Bessie decides to take several photos of these flowers. In particular, for every pair of flowers (i,j)(i,j) satisfying 1≤i≤j≤N1\le i\le j\le N, Bessie takes a photo of all flowers from flower ii to flower jj (including ii and jj).

Bessie later looks at these photos and notices that some of these photos have an "average flower" -- a flower that has PP petals, where PP is the exact average number of petals among all flowers in the photo.

How many of Bessie's photos have an average flower?

Input

The first line of input contains NN. The second line contains NN space-separated integers p1…pNp_1 \dots p_N.

Output

Please print out the number of photos that have an average flower.

Examples1

  1. Example 1

    Input
    4
    1 1 2 3
    
    Expected output
    6