#include <bits/stdc++.h>
using namespace std;
long long s, ans, n, a;
int32_t main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    s += a;
    if (a == 0) ans += s;
  }
  cout << ans;
  return 0;
}
