#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
bool chk(string first, string second) {
  string t1 = first + second;
  string t2 = second + first;
  return t1 < t2;
}
struct sort_pred {
  bool operator()(const pair<int, int> &left, const pair<int, int> &right) {
    return left.second < right.second;
  }
};
long long POW(long long Base, long long Exp) {
  long long y, ret = 1;
  y = Base;
  while (Exp) {
    if (Exp & 1) ret = (ret * y) % 1000000007;
    y = (y * y) % 1000000007;
    Exp /= 2;
  }
  return ret % 1000000007;
}
vector<long long> A, B, C, Res, Mark;
string str, str1, s1, s2;
set<string> st;
stack<long long> chlo;
vector<pair<long long, long long> > Rec;
map<string, long long> Reg;
string ItoS(long long n) {
  long long num = n;
  long long tmp;
  string ans = "";
  while (num) {
    tmp = num % 10;
    ans = ans + (char)('0' + tmp);
    num /= 10;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long dp[5007][5007];
long long fun(long long idx, long long k, long long m, long long n) {
  if (!k) return 0;
  if (idx + m > n) return 0;
  if (dp[idx][k] != -1) return dp[idx][k];
  long long ret, tmp1, tmp2;
  tmp1 = fun(idx + m, k - 1, m, n) + B[idx + m - 1];
  if (idx) tmp1 -= B[idx - 1];
  tmp2 = fun(idx + 1, k, m, n);
  ret = max(tmp1, tmp2);
  dp[idx][k] = ret;
  return ret;
}
int main() {
  long long i, j, n, k, m, x, y, z, tmp1, tmp2, tmp3, ind, Max;
  cin >> n;
  A.resize(n);
  tmp1 = tmp2 = 0;
  for (i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i])
      tmp1++;
    else
      tmp2++;
  }
  long long Ans1, Ans, Ans2;
  Ans = Ans1 = Ans2 = 0;
  for (i = 0; i < n; i++) {
    if (A[i])
      Ans1 += tmp2;
    else
      tmp2--;
  }
  for (i = n - 1; i >= 0; i--) {
    if (!A[i])
      Ans2 += tmp1;
    else
      tmp1--;
  }
  Ans = min(Ans1, Ans2);
  cout << Ans << endl;
  return 0;
}
