#include <bits/stdc++.h>
using namespace std;
int ar[1000009];
int main() {
  long long a, s, d, f, g, h, j, k, l;
  cin >> a;
  k = 0;
  for (s = 1; s <= a; s++) {
    scanf("%d", &ar[s]);
    if (ar[s]) k++;
  }
  d = 0;
  l = 0;
  for (s = 1; s <= a; s++) {
    if (ar[s] == 1) {
      d = d + (a - k - l);
    } else
      l++;
  }
  f = 0;
  for (s = a; s >= 1; s--) {
    if (ar[s] == 0)
      f = f + k;
    else
      k--;
  }
  cout << min(d, f) << endl;
  cout << endl;
}
