#include <bits/stdc++.h>
using namespace std;
int n, x[222222];
long long z[222222], one[222222], ans, sum;
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i];
    if (x[i])
      one[i] = one[i - 1] + 1, z[i] = z[i - 1];
    else
      z[i] = z[i - 1] + 1, one[i] = one[i - 1];
    sum += x[i];
  }
  if (sum > n / 2) {
    int pos = 0;
    for (int i = 1; i <= n; i++)
      if (x[i]) {
        pos = i;
        break;
      }
    for (int i = pos; i <= n; i++)
      if (x[i]) ans += (z[n] - z[i]);
  } else {
    int pos = 0;
    for (int i = n; i > 0; i--)
      if (!x[i]) {
        pos = i;
        break;
      }
    for (int i = pos; i > 0; i--)
      if (!x[i]) ans += (one[i - 1]);
  }
  cout << ans;
}
