using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;
class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long[] sum = new long[a.Length + 1];
        sum[0] = a[0];
        sum[a.Length] = 0;
        for (int i = 1; i < a.Length; i++)
        {
            sum[i] = sum[i - 1] + a[i];
        }
        Dictionary<long, int> dict = new Dictionary<long, int>();
        foreach (var i in sum)
        {
            if (!dict.ContainsKey(i)) dict.Add(i, 0);
            dict[i]++;
        }
        Console.WriteLine(dict.Values.Where(x => x >= 2).Sum(x => combination(x, 2)));
    }

    static int power(int n, int m)
    {
        const int mod = 1000000007;
        long pow = n;
        long res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res = (res * pow) % mod;
            pow = (pow * pow) % mod;
            m >>= 1;
        }
        return (int)res;
    }
    static int combination(int n, int r)
    {
        int mod = 1000000007;
        long res = 1;
        long den = 1;
        for (int i = 1; i <= n; i++)
        {
            res = (res * i) % mod;
            if (i == n - r || i == r)
            {
                den = (den * res) % mod;
                if (n - r == r) den = (den * res) % mod;
            }
        }
        long rev = power((int)den, mod - 2);
        return (int)((res * rev) % mod);
    }
}