#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n), pref(n);
  queue<int> one;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    if (i == 0)
      pref[0] = v[0];
    else
      pref[i] = pref[i - 1] + v[i];
    if (v[i] == 1) one.push(i);
  }
  auto get = [&](int l, int r, int t) {
    if (r >= n || l < 0 || r < l) return 0;
    int s = l == 0 ? pref[r] : pref[r] - pref[l - 1];
    if (t == 1) return s;
    return r - l + 1 - s;
  };
  long long ans = 0;
  while (!one.empty()) {
    int idx = one.front();
    one.pop();
    ans += get(idx + 1, n - 1, 0);
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
