#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, arr[200002], cum[200002];
  long long int res = 1000000000000LL, count = 0LL, i, j, m;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  for (i = 1; i <= n; i++) {
    cum[i] = arr[i];
  }
  for (i = 2; i <= n; i++) {
    cum[i] += cum[i - 1];
  }
  for (i = 1, j = n; i < n; i++) {
    if (arr[i] == 1) {
      m = (cum[j] - cum[i + 1]);
      count += j - i - m;
    }
  }
  res = min(res, count);
  count = 0;
  for (i = n; i > 1; i--) {
    if (arr[i] == 0) {
      count += (cum[i - 1]);
    }
  }
  res = min(res, count);
  printf("%I64d\n", res);
  return 0;
}
