#include <bits/stdc++.h>
using namespace std;
long long i, j, n, t;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<long long> a(n);
  long long o = 0, z = 0;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    cin >> a[i];
    if (a[i])
      o++;
    else
      z++;
  }
  if (o == 0 || z == 0) return cout << 0, 0;
  long long ans = 0;
  for (long long(i) = (0); (i) < (n); ++(i)) {
    if (!a[i]) z--;
    if (a[i]) {
      ans += z;
    }
  }
  cout << ans;
  return 0;
}
