#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int a[MAXN];
long long sumv1[MAXN], sumv0[MAXN];
long long ans;
int n;
const long long inf = (long long)4000000000000;
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    sumv1[i] = sumv1[i - 1];
    if (a[i] == 1) sumv1[i]++;
  }
  for (int i = n; i >= 1; i--) {
    sumv0[i] = sumv0[i + 1];
    if (a[i] == 0) sumv0[i]++;
  }
  return;
}
void order1() {
  long long tt = 0;
  for (int i = 1; i <= n; i++)
    if (a[i] == 1) tt += sumv0[i];
  ans = min(ans, tt);
  return;
}
void order2() {
  long long tt = 0;
  for (int i = n; i >= 1; i--)
    if (a[i] == 0) tt += sumv1[i];
  ans = min(ans, tt);
  return;
}
void solve() {
  ans = inf;
  order1();
  order2();
  cout << ans << endl;
}
int main() {
  init();
  solve();
  return 0;
}
