#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  string s;
  getline(cin, s);
  int N = atoi(s.c_str());
  vector<int> v(N), lt(N), rt(N);
  int cnt = 0;
  getline(cin, s);
  stringstream ss(s);
  for (int i = 0; i < N; ++i) {
    int dir = -1;
    ss >> dir;
    v[i] = dir;
    if (dir != 0) {
      ++cnt;
    }
    rt[i] = cnt;
  }
  cnt = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (v[i] == 0) {
      ++cnt;
    }
    lt[i] = cnt;
  }
  long long a = 0;
  for (int i = N - 1; i >= 0; --i) {
    if (v[i] == 0) {
      a += rt[i];
    }
  }
  long long b = 0;
  for (int i = 0; i < N; ++i) {
    if (v[i] != 0) {
      b += lt[i];
    }
  }
  cout << min(a, b) << endl;
  return 0;
}
