#include <bits/stdc++.h>
using namespace std;
const long long INF = 1 << 28;
long long gcd(long long m, long long n) {
  long long r;
  while (n != 0) {
    r = m % n;
    m = n;
    n = r;
  }
  return m;
}
long long expmod(long long a, long long b) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b & 1) x = (x * y) % 1000000007;
    y = (y * y) % 1000000007;
    b >>= 1;
  }
  return (x) % 1000000007;
}
long long inv(long long n) { return expmod(n, 1000000007 - 2); }
int main() {
  int n;
  cin >> n;
  int a[n];
  memset(a, 0, sizeof(a));
  for (int i = 0; i < n; i++) cin >> a[i];
  int zero[n], one[n];
  memset(zero, 0, sizeof(zero));
  memset(one, 0, sizeof(one));
  if (a[n - 1] == 0) zero[n - 1] = 1;
  if (a[0] == 1) one[0] = 1;
  for (int i = 1; i < n; i++) {
    one[i] = one[i - 1];
    if (a[i] == 1) one[i]++;
  }
  for (int i = n - 2; i >= 0; i--) {
    zero[i] = zero[i + 1];
    if (a[i] == 0) zero[i]++;
  }
  long long sum1 = 0, sum2 = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) sum1 += zero[i];
    if (a[i] == 0) sum2 += one[i];
  }
  cout << min(sum1, sum2) << endl;
  return 0;
}
