using System.Collections.Generic; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, a); } static void getAns ( int n, int[] a) { if (n == 1) { Console.WriteLine(a[0] == 0? 1:0); return; } var pre = a[0] == 0 ? 0 : -1; var d = new Dictionary(); for (int i = 1; i < n; i++) { if (a[i] == 0) { var t = pre == -1 ? i : i - pre - 1; if (d.ContainsKey(t)) d[t]++; else d[t] = 1; pre = i; } } var e = n - pre - 1; if (e > 0) { if (d.ContainsKey(e)) d[e]++; else d[e] = 1; } var sum = 0L; foreach (var x in d) sum += (x.Key + (x.Key) * (x.Key - 1) / 2L) * x.Value; var ans = n + n * (n - 1L) / 2L - sum; Console.WriteLine(ans); } }