#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%i", &n);
  vector<int> a;
  a.resize(n);
  int min = -1;
  for (int i = 0; i < n; i++) {
    scanf("%i", &a[i]);
    if (a[i] == 1 && min == -1) min = i;
  }
  int k = 0;
  if (min == -1) {
    printf("0");
    return 0;
  }
  for (int i = min; i < n; i++)
    if (a[i] == 0) k++;
  long long unsigned int out = 0;
  int i = min;
  while (i < n) {
    for (; i < n && a[i] == 0; i++) k--;
    out += k;
    i++;
  }
  printf("%I64d", out);
}
