#include <bits/stdc++.h>
using namespace std;
int one[200001], zero[200001];
int main() {
  int n;
  cin >> n;
  int a[n];
  int c1 = 0, c0 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      c0++;
    } else
      c1++;
    zero[i] += c0;
    one[i] += c1;
  }
  long long int ans = 0;
  if (c1 > c0) {
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] == 0) {
        ans += one[i];
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (a[i] == 1) {
        ans += (c0 - zero[i]);
      }
    }
  }
  cout << ans;
  return 0;
}
