#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n;
  scanf("%d", &n);
  long long c, s;
  c = s = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    scanf("%d", &a);
    if (a == 1)
      ++c;
    else
      s += c;
  }
  cout << s << endl;
}
