using System;
using System.Collections.Generic;

namespace AtCoder.AGC023
{
    class a
    {
        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 cnt = 0L;
            var list = new List<List<int>>();
            for (var i = 0; i < A.Length; ++i)
            {
                var sum = 0L;
                var firstZeroPoint = -1;
                for (var j = i; j < A.Length; ++j)
                {
                    sum += A[j];
                    if (sum == 0)
                    {
                        if (ContainsList(list, j))
                        {
                            cnt += CountList(list, j);
                            break;
                        }
                        else
                        {
                            if(firstZeroPoint == -1)
                            {
                                firstZeroPoint = list.Count;
                                list.Add(new List<int>());
                            }
                            list[firstZeroPoint].Add(j);
                            ++cnt;
                        }
                    }
                }
            }
            Console.WriteLine(cnt);
        }

        public static bool ContainsList(List<List<int>> list, int num)
        {
            foreach(List<int> l in list)
            {
                if (l.Contains(num)) return true;
            }
            return false;
        }

        public static int CountList(List<List<int>> list, int num)
        {
            for(var i = 0; i < list.Count; ++i)
            {
                if(list[i].Contains(num))
                {
                    return list[i].Count - list[i].FindIndex(x => x == num);
                }
            }
            return 0;
        }
    }
}
