#include <bits/stdc++.h>
using namespace std;
long long eval(vector<int> v) {
  int n = v.size(), idx = -1;
  for (int i = n - 1; i >= 0; i--)
    if (v[i] == 1) idx = i;
  long long cur = 0, ret = 0;
  for (int i = idx; i < n; i++)
    if (v[i] == 0) cur++;
  for (int i = idx; i < n; i++) {
    if (v[i] == 1)
      ret += cur;
    else
      cur--;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ret = eval(v);
  for (int i = 0; i < n; i++) v[i] = 1 - v[i];
  cout << ret << endl;
  return 0;
}
