#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, s, h[200005], hh[200005];
long long int s1, s0;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%d", h + i);
    if (h[i])
      s++;
    else {
      hh[i] = s;
      s0 += s;
    }
  }
  for (s = 0, i = n - 1; i >= 0; i--) {
    if (!h[i])
      s++;
    else {
      h[i] = s;
      s1 += s;
    }
  }
  printf("%lld", (s1 > s0 ? s0 : s1));
  return 0;
}
