#include using namespace std; int n; bool a[200000]; long long m = 0; long long b[200000]; int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = n - 2; i >= 0; i--){ if(a[i]){ bool f = 0; int j = i + 1; b[i]++; while(j < n - 1 && a[j] == f){ if(b[j] > 0){ b[i] += b[j]; break; } b[i]++; f = !f; j++; } m += b[i]; } } cout << m << endl; }