#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using ll=long long; using Graph=vector<vector<int>>; #define INF 1000000000000000000 #define MOD 998244353 #define MAX 1000000 int main(){ int N; cin>>N; vector<int> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } vector<int> sum0(N,0),sum1(N,0); sum0[N-1]=0; sum1[N-1]=0; ll ans=0; for(int i=N-2;i>=0;i--){ if(A[i]==1){ sum1[i]=sum0[i+1]+1; ans+=(ll)sum1[i]; }else{ sum0[i]=sum1[i+1]+1; } } cout<<ans<<'\n'; }