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