#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, a[200005] = {}, b[200005] = {}, c[200005] = {};
  long long int x = 0, y = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i];
  for (int i = n; i; i--) c[i] = c[i + 1] + !a[i];
  for (int i = 1; i <= n; i++)
    if (a[i]) x += c[i];
  for (int i = n; i; i--)
    if (!a[i]) y += b[i];
  cout << min(x, y);
}
