#include #include using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair P; typedef pair Pi; #define rep(i,n) for(ll i=0;i=0;i--) #define rFOR(i,a,b) for(ll i=a-1;i>=b;i--) #define all(x) (x).begin(),(x).end() #define fi first #define se second #define endl "\n" istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } template inline bool chmax(T &a, T b){if(a inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template ostream& operator<<(ostream& s,const complex& d) {return s<<"("< ostream& operator<<(ostream& s,const pair& d) {return s<<"("< ostream& operator<<(ostream& s, const vector& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const vector>& d){int len=d.size();rep(i,len){s< ostream& operator<<(ostream& s,const set& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template ostream& operator<<(ostream& s,const multiset& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template ostream& operator<<(ostream& s,const map& m){s<<"{"< vector make_vec(size_t n, T a) { return vector(n, a); } template auto make_vec(size_t n, Ts... ts) { return vector(n, make_vec(ts...)); } const ll mod=1'000'000'007; const ll inf=1'000'000'000'000'000'00; const int INF=1'000'000'000; const double EPS=1e-10; const double PI=acos(-1); int main(){ cin.tie(0);ios::sync_with_stdio(false); ll n; cin>>n; vector a(n),b(n+1,n); ll ans=0; rep(i,n) cin>>a[i]; for(ll i=n-1;i>=0;i--){ b[i]=b[i+1]; if(a[i]==0) b[i]=i; } rep(i,n){ ans+=n-b[i]; } cout<