#include <bits/stdc++.h>
using namespace std;
int a[200000], s[200000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (a[n - 1] == 0) s[n - 1] = 1;
  for (int i = n - 2; i >= 0; i--)
    if (a[i])
      s[i] = s[i + 1];
    else
      s[i] = s[i + 1] + 1;
  long long sum = 0LL;
  for (int i = 0; i < n; i++)
    if (a[i]) sum += s[i];
  cout << sum << '\n';
  return 0;
}
