#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector A(N); rep(i,N) cin >> A[i]; auto B = A; rep(i,N) if(i & 1) B[i] ^= 1; vector C(N, 0); for(int i = N - 2; i >= 0; i--) { if(B[i] == B[i + 1]) { C[i] = C[i + 1] + 1; } else { C[i] = 1; } } ll ans = 0; rep(i,N) if(A[i]) ans += C[i]; cout << ans << endl; }