#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) using m32 = atcoder::static_modint<998244353>; int main(){ int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; vector ans(N); int wall[2] = { N-1, N-1 }; for(int i=N-1; i>=0; i--){ wall[A[i] ^ (i%2)] = i; ans[i] = wall[i%2] - i; } i64 sumans = 0; for(auto a : ans) sumans += a; cout << sumans << endl; return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;