#include <bits/stdc++.h>
using namespace std;
bool arr[200005];
int cnt0[200005], cnt1[200005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = n - 1; i >= 0; i--) {
    cnt1[i] = cnt1[i + 1] + !arr[i];
  }
  for (int i = 0; i < n; i++) {
    cnt0[i] = (i == 0) ? arr[i] : cnt0[i - 1] + arr[i];
  }
  long long ans0 = 0, ans1 = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) ans1 += cnt1[i];
    if (arr[i] == 0) ans0 += cnt0[i];
  }
  cout << min(ans0, ans1) << endl;
}
