#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], n;
long long merge(int l, int r) {
  if (l == r) return 0;
  int d = (l + r) / 2, i = l, j = d + 1, k = l;
  long long res = merge(l, d) + merge(d + 1, r);
  int i1 = l, j1 = j;
  for (; i1 <= d && a[i1] == 0; i1++)
    ;
  i1--;
  for (; j1 <= r && a[j1] == 0; j1++)
    ;
  j1--;
  while (i <= d || j <= r) {
    if (i > d)
      for (; j <= r; j++) b[k++] = a[j];
    else if (j > r)
      for (; i <= d; i++) b[k++] = a[i];
    else if (a[i] <= a[j])
      b[k++] = a[i++];
    else {
      res += d - i1;
      b[k++] = a[j++];
    }
  }
  for (i = l; i <= r; i++) a[i] = b[i];
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long res = merge(1, n);
  cout << res;
  return 0;
}
