#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592654;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL), cout.tie(NULL);
}
int main() {
  fast();
  int x;
  cin >> x;
  vector<int> v(x);
  for (int(i) = 0; (i) < (long long)(x); (i)++) cin >> v[i];
  int c = 0;
  for (int i = 1; i < x; i++) v[i] += v[i - 1];
  for (int(i) = 0; (i) < (long long)(x); (i)++) {
    if (v[i] == 0) c++;
  }
  long long ans = 0;
  for (int(i) = 0; (i) < (long long)(x); (i)++) {
    if (v[i])
      ans += c;
    else
      ans += c, c--;
  }
  cout << ans << endl;
  return 0;
}
