import java.util.Scanner; public class No1505 { private static int nCr(int n, int r) { if (n < r) { return 0; } return fact(n) / (fact(r) * fact(n - r)); } // Returns factorial of n private static int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int j = -1; int cnt = nCr(N, 2) + N; int i = 0; for (; i < N; i++) { if (scan.nextInt() == 1) { if (j < 0) { j = i; } } else { if (j >= 0) { cnt -= nCr(i-j, 2) + i-j; } j = -1; } } if (j >= 0) { cnt -= nCr(i-j, 2) + i-j; } scan.close(); System.out.println(cnt); } }