#include <bits/stdc++.h>
using namespace std;
vector<int> c;
vector<int> cnt;
int main(int argc, char *argv[]) {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    c.push_back(x);
    cnt.push_back(0);
  }
  int l, r;
  l = r = 0;
  for (int i = 0; i < n; ++i)
    if (c[i] == 0)
      ++l;
    else
      ++r;
  int l1, r1;
  l1 = r1 = 0;
  for (int i = 0; i < n; ++i) {
    if (c[i] == 0)
      ++l1;
    else
      ++r1;
    if (c[i] == 0)
      cnt[i] = r1;
    else
      cnt[i] = l - l1;
  }
  long long n1 = 0;
  long long n2 = 0;
  for (int i = 0; i < n; ++i)
    if (c[i] == 0)
      n1 += cnt[i];
    else
      n2 += cnt[i];
  cout << min(n1, n2) << endl;
  return 0;
}
