#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
template <class T>
void out(map<char, T> &a, string s = "(%3c ->%3d)") {
  for (auto(it) = (a).begin(); (it) != (a).end(); ++(it))
    printf(s.c_str(), it->first, it->second);
  printf("\n");
}
template <class T>
void out(vector<T> &a, string s = "%3d ") {
  int i, n = a.size();
  for ((i) = 0; (i) < (n); (i)++) printf(s.c_str(), a[i]);
  printf("\n");
}
template <class T>
void out(T *a, int n, string s = "%3d ") {
  int i;
  for ((i) = 0; (i) < (n); (i)++) printf(s.c_str(), a[i]);
  printf("\n");
}
long long i, j, N, M, n, m, k, p;
void MainSolve(string args = "") {
  cout << args;
  cin >> n;
  vector<int> a(n), rg(n, 0), lg(n, 0);
  for ((i) = 0; (i) < (n); (i)++) cin >> a[i];
  rg[0] = 0;
  for ((i) = (1); (i) < (n); (i)++)
    if (a[i - 1] == 1)
      rg[i] = rg[i - 1] + 1;
    else
      rg[i] = rg[i - 1];
  lg[0] = 0;
  for (i = n - 2; i > -1; --i)
    if (a[i + 1] == 0)
      lg[i] = lg[i + 1] + 1;
    else
      lg[i] = lg[i + 1];
  long long sm = 0, k = 0;
  for ((i) = 0; (i) < (n); (i)++)
    if (a[i] == 1) sm += rg[i] + lg[i] - (k++);
  long long mn = sm;
  sm = 0, k = 0;
  for ((i) = 0; (i) < (n); (i)++)
    if (a[i] == 0) sm += rg[i] + lg[i] - (k++);
  mn = min(sm, mn);
  cout << mn << endl;
}
string ReadAllLines(char *fileName) {
  string s = "";
  const int NMAX = 1000;
  char buf[NMAX];
  buf[0] = 0;
  FILE *f = fopen(fileName, "r");
  while (fgets(buf, NMAX, f)) s = s + string(buf);
  return string(s.begin(), find_if(s.rbegin(), s.rend(), [](char c) {
                             return c != '\n' && c != '\r' && c != '\t' &&
                                    c != ' ';
                           }).base());
}
int main() {
  MainSolve();
  return 0;
}
