#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int main() {
  int n;
  while (cin >> n) {
    long long ans = 0, tmp = 0;
    int a;
    for (int i = 0; i < n; i++) {
      scanf("%d", &a);
      if (a)
        tmp++;
      else
        ans += tmp;
    }
    cout << ans << endl;
  }
  return 0;
}
