#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
long long x, y;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < (n); i++) scanf("%d", &a[i]);
  int cnt = 0;
  for (int i = (n - 1); i >= (0); i--)
    if (a[i] == 1)
      x += cnt;
    else
      cnt++;
  cnt = 0;
  for (int i = 0; i < (n); i++)
    if (a[i] == 0)
      y += cnt;
    else
      cnt++;
  cout << min(x, y) << "\n";
  return 0;
}
