#include <bits/stdc++.h>
using namespace std;
int arr[200000 + 10];
int arr2[200000 + 10];
int main() {
  int n, num1 = 0, num2 = 0, tem1, l1 = 0, l2 = 0;
  long long ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tem1;
    if (tem1 == 1) {
      num1++;
      arr[l1++] = num2;
    } else {
      num2++;
      arr2[l2++] = num1;
    }
  }
  if (num1 >= num2) {
    for (int i = 0; i < l1; i++) {
      ans += max(0, (l2 - arr[i]));
    }
  } else if (num2 > num1) {
    for (int i = 0; i < l2; i++) {
      ans += arr2[i];
    }
  }
  cout << ans;
  return 0;
}
