#include <bits/stdc++.h>
using namespace std;
int n, tmp;
long long cnt, sum;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &tmp);
    if (tmp)
      ++cnt;
    else
      sum += cnt;
  }
  printf("%lld", sum);
  return 0;
}
