#include <bits/stdc++.h>
using namespace std;
template <class T>
string ToString(T t) {
  stringstream s;
  s << t;
  return s.str();
}
template <class T>
void ToOther(T& t, string a) {
  stringstream s(a);
  s >> t;
}
int n;
deque<int> L, R, L2, R2;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    if (t)
      R.push_back(i);
    else
      L.push_back(i);
  }
  L2 = L;
  R2 = R;
  long long r = 0;
  while (L.size() && R.size()) {
    while (R2.size() && R2.back() > L.back()) R2.pop_back();
    while (L2.size() && L2.front() < R.front()) L2.pop_front();
    int LL = R2.size();
    int RR = L2.size();
    if (LL > RR) {
      r += RR;
      R.pop_front();
    } else {
      r += LL;
      L.pop_back();
    }
  }
  cout << r << endl;
}
