#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long tc = 1;
  while (tc--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    long long ans = 0, cnt = 0;
    for (auto &x : a) {
      cin >> x;
      if (x == 1)
        cnt++;
      else
        ans += cnt;
    }
    cout << ans;
  }
  return 0;
}
