#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int x[n];
  long long int ans = 0;
  x[0] = a[0];
  for (long long int i = 1; i < n; i++) {
    x[i] = a[i] + x[i - 1];
    if (a[i] == 0) ans += x[i];
  }
  cout << ans;
  return 0;
}
