#include <bits/stdc++.h>
using namespace std;
int n;
int T[2000010], A[2000010], B[2000010];
long long res = 0;
int main() {
  scanf("%d", &n);
  A[0] = B[0] = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &T[i]);
    A[i + 1] = A[i];
    B[i + 1] = B[i];
    if (T[i] == 0) {
      A[i + 1]++;
    } else {
      B[i + 1]++;
    }
  }
  if (A[n] > B[n]) {
    for (int i = 0; i < n; ++i) {
      if (T[i] == 0) res += B[i];
    }
  } else {
    for (int i = 0; i < n; ++i) {
      if (T[i] == 1) res += A[n] - A[i + 1];
    }
  }
  cout << res;
  return 0;
}
