#include <bits/stdc++.h>
using namespace std;
long long n, a[200005], l[200005], r[200005], rt, lt, ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  rt = 0, lt = 0, ans = 0;
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i])
      rt++;
    else
      lt++;
  }
  if (rt > lt) {
    for (int i = 0; i < n; i++) {
      if (a[i] == 0) {
        r[i + 1] = r[i];
        ans = ans + r[i];
      } else {
        r[i + 1] = r[i] + 1;
      }
    }
  } else {
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == 1) {
        l[i - 1] = l[i];
        ans = ans + l[i];
      } else
        l[i - 1] = l[i] + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
