#include #include using namespace std; int main(){ int n; cin >> n; vector a(n); for(auto &p: a) cin >> p; vector memo(n, -1); if(a[n-1] == 0) memo[n-1] = n-1; for(int i = n-2; i >= 0; i--){ memo[i] = memo[i+1]; if(a[i] == 0) memo[i] = i; } long long int ans = 0; for(int i = 0; i < n; i++){ if(memo[i] != -1){ ans += n-memo[i]; } } cout << ans << endl; return 0; }