#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > ans;
bool A[(long long)1e6];
long long hi[(long long)1e6], lo[(long long)1e6];
int main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> A[i];
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    lo[i] = cnt;
    if (A[i]) cnt++;
  }
  cnt = 0;
  for (long long i = n - 1; i >= 0; i--) {
    hi[i] = cnt;
    if (!A[i]) cnt++;
  }
  long long Max1 = 0, Max2 = 0;
  for (long long i = 0; i < n; i++)
    if (!A[i]) Max1 += lo[i];
  for (long long i = n - 1; i >= 0; i--)
    if (A[i]) Max2 += hi[i];
  cout << min(Max1, Max2) << endl;
  return 0;
}
