#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n) {
    int a[200001];
    long long int b[200001];
    int l = 0;
    long long int sum = 0;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
      if (a[i] == 1) sum++;
      if (a[i] == 0) b[l++] = sum;
    }
    long long int total = 0;
    for (int i = 0; i < l; ++i) {
      total += b[i];
    }
    cout << total << endl;
  }
  return 0;
}
