#include #include #include using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; ll ans = (ll)N * (N+1) / 2; ll c = 0; for(auto a : A){ if(a == 1) c++; else{ ans -= c * (c+1) / 2; c = 0; } } ans -= c * (c+1) / 2; cout << ans << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;