#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, a[200000], c0[200000] = {0}, c1[200000] = {0}, s1 = 0,
                                    s2 = 0, cnt0 = 0, cnt1 = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      c0[i] += i > 0 ? c0[i - 1] + 1 : 1;
      c1[i] += i > 0 ? c1[i - 1] : 0;
    } else {
      c1[i] += i > 0 ? c1[i - 1] + 1 : 1;
      c0[i] += i > 0 ? c0[i - 1] : 0;
    }
  }
  for (i = 0; i < n; i++) {
    if (a[i] == 1) {
      s1 += i > 0 ? c1[i - 1] - cnt1 : 0;
      s1 += i < n - 1 ? c0[n - 1] - c0[i] : 0;
      cnt1++;
    } else {
      s2 += i > 0 ? c1[i - 1] - cnt0 : 0;
      s2 += i < n - 1 ? c0[n - 1] - c0[i] : 0;
      cnt0++;
    }
  }
  j = s1 <= s2 ? s1 : s2;
  cout << j;
  return 0;
}
