#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
long long a[N], ans, sum;
int k;
int main() {
  int dr, pre, n, i, begin_dr, cnt = 0;
  scanf("%d", &n);
  scanf("%d", &pre);
  cnt = 1, begin_dr = pre;
  for (i = 2; i <= n; i++) {
    scanf("%d", &dr);
    if (dr == pre)
      cnt++;
    else
      a[++k] = cnt, cnt = 1;
    pre = dr;
  }
  a[++k] = cnt;
  for (i = (begin_dr == 0 ? 3 : 2); i <= k; i += 2) sum += a[i];
  for (i = (begin_dr == 0 ? 2 : 1); i <= k; i += 2)
    ans += sum * a[i], sum -= a[i + 1];
  printf("%I64d", ans);
}
