#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
int n, a[MAX], s1[MAX], s0[MAX];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1)
      s1[i] = s1[i - 1] + 1;
    else
      s1[i] = s1[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == 0)
      s0[i] = s0[i + 1] + 1;
    else
      s0[i] = s0[i + 1];
  }
  long long ans1 = 0;
  long long ans2 = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] == 1) ans1 += s0[i];
  }
  for (int i = n; i >= 1; i--) {
    if (a[i] == 0) ans2 += s1[i];
  }
  if (ans1 < ans2)
    cout << ans1;
  else
    cout << ans2;
}
