#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  cin >> n;
  long h = 0, p = 0;
  long long k = 0;
  long long j = 0;
  long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 1) {
      h++;
    } else
      p++;
  }
  if (p >= h) {
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == 0) {
        j++;
      } else
        k += j;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        j++;
      } else
        k += j;
    }
  }
  cout << k;
}
