#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m, p, q, r, i, j, k, a[200005], b[2][200005] = {0};
  ios::sync_with_stdio(false);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  b[0][0] = b[1][0] = b[0][n + 1] = b[1][n + 1] = 0;
  for (i = 1, j = 0; i <= n; i++) {
    if (a[i] == 0) {
      b[0][i] = j;
    } else {
      j++;
    }
  }
  for (i = n, j = 0; i > 0; i--) {
    if (a[i] == 1) {
      b[1][i] = j;
    } else {
      j++;
    }
  }
  for (i = 1, j = 0; i <= n; i++) {
    j += b[0][i];
  }
  k = j;
  for (i = 1, j = 0; i <= n; i++) {
    j += b[1][i];
  }
  k = min(k, j);
  cout << k;
  return 0;
}
