#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r = 0, l = 0;
  long long sum1 = 0, sum2 = 0;
  vector<int> v, v0, v1, vs;
  cin >> n;
  v.assign(n, 0);
  v0.assign(n, 0);
  v1.assign(n, 0);
  vs.assign(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    v1[i] = r;
    if (v[i] == 1) {
      r++;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    v0[i] = l;
    if (v[i] == 0) {
      l++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (v[i] == 1) {
      sum1 += v0[i];
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (v[i] == 0) {
      sum2 += v1[i];
    }
  }
  cout << min(sum1, sum2) << endl;
  return 0;
}
