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