#include <bits/stdc++.h>
using namespace std;
void solve();
int arr[200005];
int count1[200005];
int count2[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long sum1 = 0;
  long long sum2 = 0;
  int cnt1 = 0;
  int cnt2 = 0;
  int j = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (arr[i] == 0) {
      cnt1++;
    }
    count1[i] = cnt1;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) {
      cnt2++;
    }
    count2[i] = cnt2;
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 1) sum2 += count1[i];
  }
  for (int i = 0; i < n; i++) {
    if (arr[i] == 0) sum1 += count2[i];
  }
  if (sum1 >= sum2)
    cout << sum2 << endl;
  else
    cout << sum1 << endl;
  return 0;
}
