#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 10;
int64_t a[MAX_N];
int64_t b[MAX_N];
int main() {
  int n;
  cin >> n;
  int x[2] = {0, 0};
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    x[a[i]]++;
  }
  if (x[0] > x[1]) {
    for (int i = 1; i < n; ++i) {
      b[i] = b[i - 1] + a[i - 1];
    }
    int64_t ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (a[i] == 0) ans += b[i];
    }
    cout << ans << endl;
  } else {
    for (int i = n - 2; i >= 0; --i) {
      b[i] = b[i + 1] + (a[i + 1] == 0 ? 1 : 0);
    }
    int64_t ans = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == 1) ans += b[i];
    }
    cout << ans << endl;
  }
  return 0;
}
int main2() { return 0; }
