using System;

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

            int cnt = 0;

            int cntsLen = 4;
            int[] sums = new int[cntsLen];
            int[] cnts = new int[cntsLen];

            for (int i = 0; i < nums.Length; i += cntsLen)
            {
                for (int k = 0; k < cntsLen; 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]++;
                    }
                    for (int k = 1; k < cntsLen; k++)
                    {
                        if (j + k < nums.Length)
                        {
                            sums[k] += nums[j + k];
                            if (sums[k] == 0)
                            {
                                cnts[k]++;
                            }
                        }
                    }
                }

                foreach (var c in cnts)
                {
                    cnt += c;
                }
            }

            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;
        }
    }
}
