#include <bits/stdc++.h>
using namespace std;
long long a[200004];
long long data[200004];
long long sum0[200004], sum1[200004];
int n;
inline long long MIN(long long x, long long y) { return (x < y ? x : y); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  sum0[n] = 0;
  for (int i = n; i > 1; --i) {
    sum0[i - 1] = sum0[i];
    if (a[i] == 0) ++sum0[i - 1];
  }
  sum1[1] = 0;
  for (int i = 1; i < n; ++i) {
    sum1[i + 1] = sum1[i] + a[i];
  }
  sum0[0] = sum1[0] = 0;
  data[0] = 0;
  for (int i = 1; i <= n; ++i)
    data[i] = MIN(data[i - 1] + (!a[i]) * (i - 1), data[i - 1] + sum1[i]);
  cout << data[n] << endl;
}
