#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200005;
int a[MAX_N];
int sr[MAX_N];
int sl[MAX_N];
int main() {
  int n;
  long long count = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sr[i] = sr[i - 1];
    if (a[i] == 1) {
      ++sr[i];
    } else {
      count += sr[i];
    }
  }
  cout << count << endl;
  for (int i = n; i >= 1; --i) {
    sl[i] = sl[i + 1];
    if (a[i] == 0) {
      ++sl[i];
    }
  }
  int left, right;
  count = 0;
  for (left = 1, right = n; left != right;) {
    if (sr[right] - sr[left - 1] < sl[left] - sl[right + 1]) {
      count += sr[right - 1] - sr[left - 1];
      right--;
    } else {
      count += sl[left + 1] - sl[right + 1];
      left++;
    }
  }
  return 0;
}
