#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
long long int n, sum, res, arr[N];
bool vis[5];
int main() {
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &arr[i]);
    vis[arr[i]]++;
  }
  if (vis[0] < vis[1]) {
    for (int i = 0; i < n; i++) {
      if (!arr[i])
        res += sum;
      else
        sum++;
    }
  } else {
    for (int i = n - 1; i >= 0; i--) {
      if (arr[i])
        res += sum;
      else
        sum++;
    }
  }
  cout << res;
  return 0;
}
