#include <bits/stdc++.h>
using namespace std;
int a[200000], n;
long long sum;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i) {
      if (!a[i]) sum += a[i - 1];
      a[i] += a[i - 1];
    }
  }
  cout << sum << endl;
  return 0;
}
