#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
long long ans, a[MAXN], n, ans1, cnt1, cnt;
bool flag;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), cnt1 += a[i] == 0 ? 1 : 0;
  long long l = cnt1, r = n - cnt1;
  if (l > r) {
    for (int i = n; i >= 1; i--)
      if (a[i] == 0)
        ans += r;
      else
        r--;
  } else {
    for (int i = 1; i <= n; i++)
      if (a[i] == 1)
        ans += l;
      else
        l--;
  }
  printf("%lld\n", ans);
  return 0;
}
