#include <bits/stdc++.h>

using namespace std;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    fast_io();
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<int>> dp(n, vector<int>(2));
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 0; j < 2; j++) {
            if (a[i] ^ j) {
                dp[i][j] = dp[i + 1][!j] + 1;
            }
        }
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += dp[i][0];
    }
    cout << ans << endl;
}