using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var sums = new Dictionary<long, long>();
            var tmp = (long)0;
            var result = (long)0;
            foreach (var i in Enumerable.Range(0, N))
            {
                tmp += A[i];
                if (tmp == 0) result++;
                long hoge;
                if(sums.TryGetValue(tmp, out hoge))
                {
                    sums[tmp] = hoge + 1;
                }
                else
                {
                    sums[tmp] = (long)1;
                }
            }

            foreach(var t in sums)
            {
                if (t.Value < 2) continue;
                result += Combination(t.Value, 2);
            }

            Console.WriteLine(result);
        }

        static BigInteger Factorial(long x)
        {
            var result = new BigInteger(1);
            for(var i = x; i>1; i--)
            {
                result *= i;
            }
            return result;
        }

        static long Combination(long n, int r)
        {
            var comb = Factorial(n) / Factorial(r) / Factorial(n-r);
            return (long)comb;
        }
    }
}
