using System;

namespace AGC023
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = Util.GetIntLine();
            int[] nums = Util.GetIntArray();

            int cnt = 0;
            int[] sums = new int[4];
            int[] cnts = new int[4];

            for (int i = 0; i < nums.Length; i += cnts.Length)
            {
                for (int k = 0; k < cnts.Length; k++)
                {
                    sums[k] = 0;
                    cnts[k] = 0;
                }
                for (int j = i; j < nums.Length; j++)
                {
                    sums[0] += nums[j];
                    if (sums[0] == 0)
                    {
                        cnts[0]++;
                    }
                    if (j + 1 < nums.Length)
                    {
                        sums[1] += nums[j + 1];
                        if (sums[1] == 0)
                        {
                            cnts[1]++;
                        }
                    }
                    if (j + 2 < nums.Length)
                    {
                        sums[2] += nums[j + 2];
                        if (sums[2] == 0)
                        {
                            cnts[2]++;
                        }
                    }
                    if (j + 3 < nums.Length)
                    {
                        sums[3] += nums[j + 3];
                        if (sums[3] == 0)
                        {
                            cnts[3]++;
                        }
                    }
                }
                cnt += cnts[0] + cnts[1] + cnts[2];
            }

            Console.WriteLine(cnt);
        }
    }

    class Util
    {
        public static int GetIntLine()
        {
            string lin = Console.ReadLine().Trim();

            return int.Parse(lin);
        }

        public static int[] GetIntArray()
        {
            string lin = Console.ReadLine().Trim();

            string[] ss = lin.Split();

            int[] ret = new int[ss.Length];

            for (int i = 0; i < ss.Length; i++)
            {
                ret[i] = int.Parse(ss[i]);
            }

            return ret;
        }
    }
}
