import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); } sc.close(); if (n == 1) { System.out.println(0); return; } long[] num = new long[n + 1]; num[1] = 1; num[2] = 2; for (int i = 3; i < num.length; i++) { num[i] = num[i - 2] + i; } long ans = 0; int cnt = 0; for (int i = 0; i < n - 1; i++) { if (cnt % 2 == 0) { if (a[i] == 1) { cnt++; } else { ans += num[cnt]; cnt = 0; } } else { if (a[i] == 1) { ans += num[cnt]; cnt = 1; } else { cnt++; } } } ans += num[cnt]; System.out.println(ans); } }