Untitled

 avatar
unknown
c_cpp
4 years ago
393 B
0
Indexable
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long long result = 0;
    int prev_zero = -1;
    for(int i = 0; i < n; i++) {
        if(a[i] == 0) {
            result += (i - prev_zero) * (n - i);
            prev_zero = i;
        }
    }
    cout << result << endl;
return 0;
}
Editor is loading...