using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var acum = new long[n];
            acum[0] = A[0];
            for (var i = 1; i < n; i++) {
                acum[i] = acum[i - 1] + A[i];
            }
            
            var ans = new long[n];
            var zeroCount = 0L;
            for (var i = acum.Length - 1; i >= 0; i--) {
               if (acum[i] == 0) zeroCount++;
               ans[i] = zeroCount;
            }
            
            Console.WriteLine(ans.Sum());
        }
    }
}
