#include <bits/stdc++.h>
using namespace std;
long long int mod(long long int x, long long int m) { return (x % m + m) % m; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx,
                minn, temp, ans, flag, g, ts;
  long long int mod = 1000000007;
  char ch, chh;
  double dans;
  string str, ttr;
  for (ts = 1; ts <= t; ts++) {
    flag = 0;
    sum = 0;
    cnt = 0;
    ans = 0;
    k = 0;
    maxx = 0;
    minn = 0;
    a = 0;
    b = 0;
    temp = 0;
    cin >> n;
    long long int arr[n];
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      if (arr[i] == 0)
        a++;
      else
        b++;
    }
    for (i = 0; i < n; i++) {
      if (arr[i] == 1) {
        ans += a;
      } else
        a--;
    }
    for (i = n - 1; i >= 0; i--) {
      if (arr[i] == 0) {
        sum += b;
      } else
        b--;
    }
    cout << min(ans, sum);
    cout << "\n";
  }
  return 0;
}
