#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, f = 0, r = 0;
  cin >> n;
  long long arr[n + 2], acc1[n + 2], acc2[n + 2];
  arr[0] = acc1[0] = acc2[n + 1] = 0, arr[n + 1] = 1;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 1; i <= n; i++) {
    acc1[i] = (arr[i - 1] == 1 ? acc1[i - 1] + 1 : acc1[i - 1]);
    acc2[n - i + 1] =
        (arr[n - i + 2] == 0 ? acc2[n - i + 2] + 1 : acc2[n - i + 2]);
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i] == 1) r += acc2[i];
    if (arr[n - i + 1] == 0) f += acc1[n - i + 1];
  }
  cout << min(r, f);
  return 0;
}
