#include <bits/stdc++.h>
using namespace std;
const long long T = 200002;
const long long MAXD = T * T * T;
int n, s;
int N[T];
int PREFP[T];
int SUFL[T];
int main(void) {
  cin >> n;
  for (int i = (int)1; i <= (int)n; i++) {
    cin >> N[i];
  }
  for (int i = (int)1; i <= (int)n; i++) {
    PREFP[i] += N[i] + PREFP[i - 1];
  }
  for (int i = (int)n; i >= (int)1; i--) {
    int k = N[i] == 0 ? 1 : 0;
    SUFL[i] = k + SUFL[i + 1];
  }
  int b = 1;
  int e = n;
  long long ans = 0;
  while (true) {
    while (N[b] != 1 && b <= n) {
      b++;
    }
    while (N[e] != 0 && e >= 1) {
      e--;
    }
    if (e > b) {
      long long bs = SUFL[b] - SUFL[e + 1];
      long long es = PREFP[e] - PREFP[b - 1];
      if (bs > es) {
        e--;
        ans += es;
      } else {
        b++;
        ans += bs;
      }
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
