//
// main.cpp
// Sort Binary Array
//
// Created by Himanshu on 06/04/22.
//
#include <iostream>
using namespace std;
int solve (int arr[], int n) {
int ans = 0;
int currOnePos = n-1;
for (int index=n-1; index>=0; index--) {
if (arr[index] == 1) {
ans += currOnePos-index;
currOnePos--;
}
}
return ans;
}
int main() {
int n;
cin>>n;
int *arr = new int[n]();
for (int i=0; i<n; i++) {
cin>>arr[i];
}
cout<<solve(arr, n)<<endl;
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBTb3J0IEJpbmFyeSBBcnJheQovLwovLyAgQ3JlYXRlZCBieSBIaW1hbnNodSBvbiAwNi8wNC8yMi4KLy8KCiNpbmNsdWRlIDxpb3N0cmVhbT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBzb2x2ZSAoaW50IGFycltdLCBpbnQgbikgewogICAgaW50IGFucyA9IDA7CiAgICBpbnQgY3Vyck9uZVBvcyA9IG4tMTsKICAgIAogICAgZm9yIChpbnQgaW5kZXg9bi0xOyBpbmRleD49MDsgaW5kZXgtLSkgewogICAgICAgIGlmIChhcnJbaW5kZXhdID09IDEpIHsKICAgICAgICAgICAgYW5zICs9IGN1cnJPbmVQb3MtaW5kZXg7CiAgICAgICAgICAgIGN1cnJPbmVQb3MtLTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CgppbnQgbWFpbigpIHsKICAgIAogICAgaW50IG47CiAgICBjaW4+Pm47CiAgICAKICAgIGludCAqYXJyID0gbmV3IGludFtuXSgpOwogICAgCiAgICBmb3IgKGludCBpPTA7IGk8bjsgaSsrKSB7CiAgICAgICAgY2luPj5hcnJbaV07CiAgICB9CiAgICAKICAgIGNvdXQ8PHNvbHZlKGFyciwgbik8PGVuZGw7CiAgICAKICAgIHJldHVybiAwOwp9Cg==