#include <bits/stdc++.h>
using namespace std;
int const MOD = 1e9 + 7;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  std::cout.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  int cnt = 0;
  long long s1 = 0, s2 = 0;
  for (int i = 1; i < n; ++i) {
    if (v[i - 1]) ++cnt;
    if (!v[i]) s1 += cnt;
  }
  cnt = 0;
  for (int i = n - 2; i >= 0; --i) {
    if (!v[i + 1]) ++cnt;
    if (v[i]) s2 += cnt;
  }
  cout << min(s1, s2);
}
