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