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