#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
int main(){
    long long n;
    cin>>n;
    int niza[n];
    for(int i = 0; i < n; i++){
        cin>>niza[i];
    }
    long long sz = 0;
    long long answer = n * (n + 1) / 2;
    for(int i = 0; i < n; i++) {
        if(niza[i] != 0) {
            sz += 1;
        }
        else {
            answer -= ((sz) * (sz + 1) / 2);
            sz = 0;
            
        }
    }
    
    answer -= ((sz) * (sz + 1) / 2);

    cout << answer << endl;

    return 0;
}

/*
5
 4, 2, 0, 1, 3
 
 **/
