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