#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> os, zs, v;
  int o = 0;
  int z = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x) {
      o++;
    } else {
      z++;
    }
    os.push_back(o);
    zs.push_back(z);
    v.push_back(x);
  }
  long long sumo = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i]) sumo += (z - zs[i]);
  }
  long long sumz = 0;
  for (int i = v.size() - 1; i >= 0; i--) {
    if (!v[i]) sumz += (os[i]);
  }
  cout << min(sumo, sumz) << endl;
  return 0;
}
