import java.util.Scanner; public class No1505 { private static long nCr(int n) { if (n < 2 || n <= 0) { return 0L; } return (long)n * (long)(n-1) / 2L; } public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int j = -1; long cnt = nCr(N) + 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) + (long)(i-j); } j = -1; } } if (j >= 0) { cnt -= nCr(i-j) + (long)(i-j); } scan.close(); System.out.println(cnt); } }