#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  scanf("%I64d", &n);
  vector<long long> a(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  long long s = 0;
  long long ans1 = 0, ans2 = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == 0) {
      ans1 += i - 1 - s;
      s++;
    }
  s = 0;
  for (int i = n; i >= 1; i--)
    if (a[i] == 1) {
      ans2 += n - i - s;
      s++;
    }
  printf("%I64d", min(ans1, ans2));
  return 0;
}
