#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
  pair<int, int> n;
  n.first = a.first + b.first;
  n.second = a.second + b.second;
  return n;
}
pair<int, int> segment[200020 * 5], lazy[200020 * 5], bs[200020];
int a, ar[200020];
long long top;
pair<int, int> crate(int k, int b, int s) {
  if (b == s) return segment[k] = pair<int, int>(!ar[b], ar[b]);
  return segment[k] = crate(2 * k, b, (b + s) / 2) +
                      crate(2 * k + 1, (b + s) / 2 + 1, s);
}
pair<int, int> update(int k, int b, int s, int x) {
  if (s < x || b > x) return segment[k];
  if (x <= b && s <= x) {
    return segment[k] = pair<int, int>(0, 0);
  }
  segment[k] = update(2 * k, b, (b + s) / 2, x) +
               update(2 * k + 1, (b + s) / 2 + 1, s, x);
  return segment[k] + lazy[k];
}
pair<int, int> find(int k, int b, int s, int x, int y) {
  if (s < x || b > y) return pair<int, int>(0, 0);
  if (x <= b && s <= y) return segment[k] + lazy[k];
  return find(2 * k, b, (b + s) / 2, x, y) +
         find(2 * k + 1, (b + s) / 2 + 1, s, x, y) + lazy[k];
}
void al(int n) {
  pair<int, int> t1 = find(1, 1, a, n + 1, a);
  pair<int, int> t2 = find(1, 1, a, 1, n - 1);
  top += (long long)t1.first + t2.second;
  update(1, 1, a, n);
}
int main() {
  scanf("%d", &a);
  for (int i = 1; i <= a; i++) bs[i].second = i;
  for (int i = 1; i <= a; i++) {
    scanf("%d", &ar[i]);
    if (ar[i])
      bs[i].first = a - i + 1;
    else
      bs[i].first = i - 1;
  }
  sort(bs + 1, bs + 1 + a);
  reverse(bs + 1, bs + 1 + a);
  crate(1, 1, a);
  for (int i = 1; i <= a; i++) al(bs[i].second);
  printf("%I64d\n", top);
  return 0;
}
