#include "bits/stdc++.h" using namespace std; using ll = long long; ll numSubseq(ll n) { return n * (n + 1) / 2; } void Main() { ll N; cin >> N; vector A(N, 0); for (ll i = 0; i < N; ++i) { cin >> A[i]; } map ones; bool reset = true; ll temp = 0; for (ll i = 0; i < N; ++i) { if (A[i] == 1) { ++temp; } else { if (temp == 0) { continue; } if (ones.count(temp) == 0) { ones.emplace(temp, 0); } ones[temp] += 1; temp = 0LL; } } if (ones.count(temp) == 0) { ones.emplace(temp, 0); } ones[temp] += 1; ll ans = numSubseq(N); for (auto e : ones) { ans -= numSubseq(e.first) * e.second; } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); std::cout << std::fixed << std::setprecision(15); Main(); return 0; }