import java.util.Scanner; public class No1765 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = Integer.valueOf(scan.nextLine()); String[] S = scan.nextLine().split(" "); scan.close(); int m0 = 0, m1 = 0; long cnt = 0; for (int i = 0; i < N-1; i++) { if (S[i].equals("1")) { cnt += 1 + m1; m0 = 1 + m1; m1 = 0; } else { cnt += m0; m1 = m0; m0 = 0; } } System.out.println(cnt); } }