#include using namespace std; using ll = long long; // #define rep(i,m,n) for(int i=m; i> N; vector A(N); rep(i, 0, N) cin >> A[i]; vector nonzero; ll cnt = 0LL; rep(i, 0, N){ if(A[i] == 0LL){ if(cnt != 0LL){ nonzero.push_back(cnt); cnt = 0LL; } }else{ cnt++; } } if(cnt != 0LL) nonzero.push_back(cnt); ll ans = (N+1LL) * N / 2LL; for(ll x : nonzero){ ans -= (x+1LL) * x / 2LL; } cout << ans << endl; return 0; }