#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 10;
long long int n, a[N], c0[N], c1[N], cow1, cow0, ans, ans1, ans2;
void solve() {
  long long int n;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) {
    c0[i] = cow1;
    if (a[i] == 1) cow1++;
  }
  for (long long int i = n - 1; i >= 0; i--) {
    c1[i] = cow0;
    if (a[i] == 0) cow0++;
  }
  for (long long int i = 0; i < n; i++) {
    if (a[i] == 1)
      ans1 += c1[i];
    else
      ans2 += c0[i];
  }
  cout << min(ans1, ans2) << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
