#include <bits/stdc++.h>
using namespace std;
long long const maxx = 1e16 + 5;
long const md = 1000000007;
long const mx = 2147483647;
long const mm = 1743;
long const maxN = 10000;
double const eps = 1e-6;
long n, i, j, a[200500];
long long ans1, ans2, l;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> a[i];
  l = 0;
  ans1 = 0;
  ans2 = 0;
  for (i = 1; i <= n; i++)
    if (a[i] == 0) l++;
  for (i = 1; i <= n; i++)
    if (a[i] == 0)
      l--;
    else
      ans1 += l;
  for (i = n; i > 0; i--)
    if (a[i] == 1) l++;
  for (i = n; i > 0; i--)
    if (a[i] == 1)
      l--;
    else
      ans2 += l;
  cout << min(ans1, ans2);
}
