#include <bits/stdc++.h>
using namespace std;
long long arr[200002];
int main() {
  long long i, j, k, n, co = 0, cz = 0, ans;
  ans = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i]) {
      co++;
    } else {
      cz++;
    }
  }
  if (co == n || cz == n) {
    printf("0\n");
  } else {
    i = k = 0;
    while (i < n && arr[i] != 1) {
      i++;
    }
    while (i < n) {
      if (arr[i] == 1) {
        k++;
      } else if (arr[i] == 0) {
        ans += k;
      }
      i++;
    }
    cout << ans << endl;
  }
  return 0;
}
