#include using namespace std; typedef long long ll; ll get(ll n) { return (n * (n + 1)) / 2; } void solve() { ll n; cin >> n; vectorx(n); for (ll i = 0; i < n; i++) { cin >> x[i]; } ll cnt = 0; ll ans = get(n); for (ll i = 0; i < n; i++) { if (x[i] == 1)cnt++; else { ans -= get(cnt); cnt = 0; } } ans -= get(cnt); cout << ans << endl; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll test = 1; while (test--) { solve(); } }