using System;
using System.Collections.Generic;

namespace AtCoder.AGC023
{
    class a
    {
        static Dictionary<int, long> fact = new Dictionary<int, long>();

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Trim();
            var N = int.Parse(line);
            line = Console.ReadLine().Trim();
            var A = Array.ConvertAll(line.Split(' '), new Converter<string, int>(s => int.Parse(s)));
            var SUM = new List<long>();
            SUM.Add(A[0]);
            var fact = new Dictionary<int, long>();
            var numList = new List<long>();
            numList.Add(SUM[0]);
            var ans = 0L;
            for (var i = 1; i < A.Length; ++i)
            {
                SUM.Add(SUM[i - 1] + A[i]);
                if (!numList.Contains(SUM[i])) numList.Add(SUM[i]);
            }
            for(var i = 0; i < numList.Count; ++i)
            {
                int cnt;
                if(numList[i] == 0)
                {
                    cnt = SUM.FindAll(x => x == 0).Count;
                }
                else
                {
                    cnt = SUM.FindAll(x => x == numList[i]).Count - 1;
                }
                ans += Factorial(cnt);
            }
            Console.WriteLine(ans);
        }

        public static long Factorial(int x)
        {
            if (fact.ContainsKey(x)) return fact[x];
            else if (x == 1) return 1;
            else if (x == 0) return 0;
            else
            {
                fact.Add(x, x * Factorial(x - 1));
                return fact[x];
            }
        }
    }
}
