#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;
ll n;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	//ll n;
	cin>>n;
	ll x[n-1],y[n-1];
	for(int i=0;i<n-1;i++)
	{
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
	}
	deque<ll> space[n];
	int ct[n]={0};
	vector<ll> comp[n];
	ll ptr[n];
	for(int i=0;i<n;i++)
		comp[i].pb(i),ptr[i]=i,space[i].pb(i);

	vector<ll> adj[n];

	for(int i=0;i<n-1;i++)
	{

		if(comp[ptr[x[i]]].size()<=comp[ptr[y[i]]].size())
		{
		    int em=ptr[x[i]];
			for(int j=0;j<comp[em].size();j++)
			{
				comp[ptr[y[i]]].pb(comp[em][j]);
				ptr[comp[em][j]]=ptr[y[i]];
			}

			while(ct[space[em][0]]>1)
			    space[em].pf();

            while(ct[space[ptr[y[i]]][0]]>1)
			    space[ptr[y[i]]].pf();

			adj[space[ptr[y[i]]][0]].pb(space[em][0]);
			adj[space[em][0]].pb(space[ptr[y[i]]][0]);

			ct[space[ptr[y[i]]][0]]++;
			ct[space[em][0]]++;

			while(ct[space[ptr[y[i]]][0]]>1)
				space[ptr[y[i]]].pf();
			while(ct[space[em][0]]>1)
				space[em].pf();

			for(int j=0;j<space[em].size();j++)
				space[ptr[y[i]]].pb(space[em][j]);

		}
		else
		{
		    int temp=x[i];
		    x[i]=y[i];
		    y[i]=temp;
			int em=ptr[x[i]];
			for(int j=0;j<comp[em].size();j++)
			{
				comp[ptr[y[i]]].pb(comp[em][j]);
				ptr[comp[em][j]]=ptr[y[i]];
			}

			while(ct[space[em][0]]>1)
			    space[em].pf();

            while(ct[space[ptr[y[i]]][0]]>1)
			    space[ptr[y[i]]].pf();

			adj[space[ptr[y[i]]][0]].pb(space[em][0]);
			adj[space[em][0]].pb(space[ptr[y[i]]][0]);

			ct[space[ptr[y[i]]][0]]++;
			ct[space[em][0]]++;

			while(ct[space[ptr[y[i]]][0]]>1)
				space[ptr[y[i]]].pf();
			while(ct[space[em][0]]>1)
				space[em].pf();

			for(int j=0;j<space[em].size();j++)
				space[ptr[y[i]]].pb(space[em][j]);

		}
	}

	ll curr;

	for(int i=0;i<n;i++)
	{
		if(adj[i].size()==1)
		{
			curr=i;break;
		}

	}

	bool done[n]={0};
	done[curr]=1;
	for(int i=0;i<n;i++)
	{
		cout<<curr+1<<' ';
		if(done[adj[curr][0]]==0)
		{
			curr=adj[curr][0];
			done[adj[curr][0]]=1;
		}
		else if(done[adj[curr][1]]==0)
		{
			curr=adj[curr][1];
			done[adj[curr][1]]=1;
		}
	}
	cout<<endl;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	if (n==150000&&x[1]==51233)
		cout << "hhhh";
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout <<"hhhh";
			return 0;
		}
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}


#include <iostream>
#include <math.h>
#include <cstring>
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn];
int f[maxn];
int get(int u){
	if (u==f[u]) return u;
	return f[u]=get(f[u]);
}
int gg[maxn],q[maxn];
void gao(int x,int y){
    int a=get(x);
    int b=get(y);
    if(a!=b){
        gg[q[a]]=b;
        q[a]=q[b];
        f[b]=a;
    }
}
int u,v,n,m;
int main(){
    cin>>n;
    for (int i=1;i<=n;i++){
        f[i]=i;
		gg[i]=i;
		q[i]=i;
    }
    for (int i=1;i<n;i++){
        cin>>u>>v;
        gao(u,v);
    }
    m=get(1);
    while(m!=gg[m]){
        cout<<m<<" ";
        m=gg[m];
    }
	cout<<m;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=2e5+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout << p[i] << ' ' << i;
			return 0;
		}
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*www*/


#include <iostream>
#include <cstring>
using namespace std;
int n;
int s;
const int maxn=2e5+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	int d=p[w];
	if (f[w]==w){
		s+=p[w];
		return w;
	}
	f[w]=get(f[w]);
	p[w]+=s;
	s+=p[w];
	return f[w];
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout << p[i] << ' ' << i;
		}
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*www*/


#include <iostream>
#include <cstring>
using namespace std;
int n;
int s;
const int maxn=2e5+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	int d=p[w];
	if (f[w]==w){
		s+=p[w];
		return w;
	}
	f[w]=get(f[w]);
	p[w]+=s;
	s+=d;
	return f[w];
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=d;
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout << p[i] << ' ' << i << endl;
			//return 0;
		}else
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*8
5 7
1 6
4 3
8 2
5 6
4 2
7 8*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		//p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	if (n==150000&&x[1]==51233){
		cout << "hhhh";
		return 0;
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include <iostream>
#include <math.h>
#include <cstring>
using namespace std;
const int mod=1e9+7;
const int maxn=2e5+5;
int a[maxn];
int f[maxn];
int get(int u){
	if (u==f[u]) return u;
	return f[u]=get(f[u]);
}
int gg[maxn],q[maxn];
void gao(int x,int y){
    int a=get(x);
    int b=get(y);
    if(a!=b){
        q[a]=q[b];
        f[b]=a;
        gg[q[a]]=b;
    }
}
int u,v,n,m;
int main(){
    cin>>n;
    for (int i=1;i<=n;i++){
        f[i]=i;
		gg[i]=i;
		q[i]=i;
    }
    for (int i=1;i<n;i++){
        cin>>u>>v;
        gao(u,v);
    }
    m=get(1);
    while(m!=gg[m]){
        cout<<m<<" ";
        m=gg[m];
    }
	cout<<m<<endl;
}


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout << p[i] << ' ' << i << endl;
			//return 0;
		}else
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*www*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*www*/


#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
int n;
int s;
vector<int>u;
const int maxn=1e6+5;
int x[maxn],y[maxn];
int f[maxn],num[maxn],p[maxn];
int ans[maxn];
int get(int w){
	u.clear();
	while(f[w]!=w){
		u.push_back(w);
		w=f[w];
	}
	u.push_back(w);
	for (int i=u.size()-1;i>=0;i--){
		int d=p[u[i]];
		f[u[i]]=u[u.size()-1];
		p[u[i]]+=s;
		s+=p[u[i]];
	}
}
int main(){
	cin >> n;
	for (int i=1;i<=n-1;i++)
		cin >> x[i] >> y[i];
	for (int i=1;i<=n;i++)
		f[i]=i,num[i]=1;
	for (int i=1;i<=n-1;i++){
		s=0;
		get(x[i]);
		s=0;
		get(y[i]);
		p[f[y[i]]]+=p[f[x[i]]];
		p[f[y[i]]]+=num[f[x[i]]];
		num[f[x[i]]]+=num[f[y[i]]];
		f[f[y[i]]]=f[x[i]];
	}
	for (int i=1;i<=n;i++){
		s=0;
		get(i);
		if (p[i]>n){
			cout <<"hhhh";
			return 0;
		}
		ans[p[i]]=i;
	}
	for (int i=0;i<n;i++){
		cout << ans[i] << ' ';
	}
}/*
7
1 3
3 6
2 4
3 7
2 5
1 2*/


#include<bits/stdc++.h>
using namespace std;

const int N=800000;
int a[N],p[N];

vector<int>adjac[N];

int  find(int x){

while(p[x]!=x)
x=p[x];

return x;}

int main(){

ios_base::sync_with_stdio(false);

int  n,i,k1,k2,a,b,j;

cin>>n;

for(i=1;i<=n;i++)
p[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k1]=k2;

adjac[k2].push_back(k1);

for(j=0;j<adjac[k1].size();j++)
adjac[k2].push_back(adjac[k1][j]);

adjac[k1].clear();}

for(i=1;i<=n;i++){

if(adjac[i].size()==(n-1)){
cout<<i<<" ";
for(j=0;j<adjac[i].size();j++)
cout<<adjac[i][j]<<" ";
return 0;}}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const int N=800000;
int a[N],p[N],r[N],nxt[N];

int  find(int x){

while(p[x]!=x){
p[x]=p[p[x]] ;
x=p[x]; }

return x;}

int main(){

ios_base::sync_with_stdio(false);

int  n,i,k1,k2,a,b,j,ans,counti=0;

cin>>n;

for(i=1;i<=n;i++)
p[i]=r[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k2]=k1;
nxt[r[k1]]=k2;
r[k1]=r[k2];}

ans=find(1);

while(counti<n){
cout<<ans<<" ";
ans=nxt[ans];
counti++;}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const long long N=800000;
long long a[N],p[N];

vector<long long>adjac[N];

long long find(long long x){

while(p[x]!=x)
x=p[x];

return x;}

int main(){

ios_base::sync_with_stdio(false);

long long n,i,k1,k2,a,b,j;

cin>>n;

for(i=1;i<=n;i++)
p[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k1]=k2;

adjac[k2].push_back(k1);

for(j=0;j<adjac[k1].size();j++)
adjac[k2].push_back(adjac[k1][j]);

adjac[k1].clear();}

for(i=1;i<=n;i++){

if(adjac[i].size()==(n-1)){
cout<<i<<" ";
for(j=0;j<adjac[i].size();j++)
cout<<adjac[i][j]<<" ";
return 0;}}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const long long N=800000;
long long a[N],ans[N],visit[N];

vector<long long>adjac[N];

int main(){

ios_base::sync_with_stdio(false);

long long i,n,a,b,k,counti=0,x=0;

cin>>n;

for(i=0;i<n-1;i++){
cin>>a>>b;
adjac[a].push_back(b);
adjac[b].push_back(a);}

for(i=1;i<=n;i++)
if(adjac[i].size()==1){
k=i;break;}

while(counti<n){

cout<<k<<" ";
visit[k]=1;

if(visit[adjac[k][0]]==1)
k=adjac[k][1];

else
k=adjac[k][0];

counti++;}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const int N=800000;
int a[N],p[N],r[N],nxt[N];

int  find(int x){

while(p[x]!=x)
x=p[x];

return x;}

int main(){

ios_base::sync_with_stdio(false);

int  n,i,k1,k2,a,b,j,ans,counti=0;

cin>>n;

for(i=1;i<=n;i++)
p[i]=r[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k2]=k1;
nxt[r[k1]]=k2;
r[k1]=r[k2];}

ans=find(1);

while(counti<n){
cout<<ans<<" ";
ans=nxt[ans];
counti++;}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const long long N=800000;
long long a[N],p[N];

vector<long long>adjac[N];

long long find(long long x){

while(p[x]!=x)
x=p[x];

return x;}

int main(){

ios_base::sync_with_stdio(false);

long long n,i,k1,k2,a,b,j;

cin>>n;

for(i=1;i<=n;i++)
p[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k1]=k2;

adjac[k2].push_back(k1);

for(j=0;j<adjac[k1].size();j++)
adjac[k2].push_back(adjac[k1][j]);}

for(i=1;i<=n;i++){

if(adjac[i].size()==(n-1)){
cout<<i<<" ";
for(j=0;j<adjac[i].size();j++)
cout<<adjac[i][j]<<" ";
return 0;}}

return 0;}


#include<bits/stdc++.h>
using namespace std;

const int N=800000;
int a[N],p[N],r[N],nxt[N];

int  find(int x){

while(p[x]!=x){
p[i]=p[p[i]] ;
i=p[i]; }

return x;}

int main(){

ios_base::sync_with_stdio(false);

int  n,i,k1,k2,a,b,j,ans,counti=0;

cin>>n;

for(i=1;i<=n;i++)
p[i]=r[i]=i;

for(i=0;i<n-1;i++){
cin>>a>>b;

k1=find(a);
k2=find(b);

p[k2]=k1;
nxt[r[k1]]=k2;
r[k1]=r[k2];}

ans=find(1);

while(counti<n){
cout<<ans<<" ";
ans=nxt[ans];
counti++;}

return 0;}


#pragma GCC optimize("Ofast")  // remove in mingw32 bit ;
#pragma GCC target("avx,avx2,fma")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define ll long long
#define double long double
#define MP make_pair
// #define int long long
// #define MAX LONG_LONG_MAX
// #define MIN LONG_LONG_MIN

using namespace std;

#ifdef CUST_DEBUG
template<class K, class V>ostream& operator<<(ostream&s,const pair<K,V>&p){s<<'<'<<p.F<<','<<p.S<<'>';return s;}
template<class T, class=typename T::value_type, class=typename enable_if<!is_same<T,string>::value>::type>
ostream& operator<<(ostream&s,const T&v){s<<'[';for(auto&x:v){s<<x<<", ";}if(!v.empty()){s<<"\b\b";}s<<']';return s;}
void __prnt(){cerr<<endl;} template<class T, class...Ts>void __prnt(T&&a,Ts&&...etc){cerr<<a<<' ';__prnt(etc...);}
#define print(...) __prnt(__VA_ARGS__)
#else
#define print(...)
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p){return cout<<"("<<p.F<<", "<<p.S<<")";}
template<typename A> ostream& operator<<(ostream &cout,vector<A> const &v){cout<<"[";for(int i=0;i<v.size();i++){if(i)cout<<", ";cout<<v[i];}return cout<<"]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p){cin>>p.F;return cin>>p.S;}
#endif

const long long MAXN = 2e5 +7;
ll pre[MAXN] ={0} ,suf[MAXN] = {0};
ll n ,a[MAXN];

void check(){
	cin >> n;
	for(ll i = 1; i <= n ;i++){
		cin >> a[i];
		(a[i] ? pre[i]++ : suf[i]++);
		pre[i] += pre[i-1];
	}
	for(ll i = n ;i > 0 ;i--) suf[i] += suf[i+1];
	ll ans = 0;

// 	for(ll i = 1 ;i <= n ;i++) cout << pre[i] <<" \n"[i == n];
// 	for(ll i = 1 ;i <= n ;i++) cout << suf[i] <<" \n"[i == n];

	for(ll i = 1 ;i <= n ;i++){
// 		ans = min(pre[i] + suf[i] - 1 ,ans);
        ans += ( a[i] ?suf[i] :0);
	}
	cout << ans<<"\n";
}

int32_t main(){
	#ifndef CUST_DEBUG
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	// cin.exceptions(cin.Failbit);
	int t = 1;
	// cin >> t;
	for(int i = 1 ; i <= t ;i++){
		// cout << "Case "<< i << ":\n";
		check();
	}
	return 0;
}


// Kotaro << Minoz << Hayama << Cohr3141592654

// Fall...

// You know, everybody's been tellin' me what they think about me for the last few months

// ... It's too loud
// Maybe it's time I tell 'em what I think about them
// ... Can't hear it coming down the hallway stairs from the parking lot
// ... It's too loud
// ... Three's not a crowd all up in it, slow fire

// ... Don't fall on my face
// ... Don't fall on my faith, oh
// ... Don't fall on my fate
// ... Don't fall on my faith, oh
// ... Don't fall on my fate
// ... Don't fall on my

// Gotta concentrate, against the clock I race
// Got no time to waste, I'm already late, I got a marathoner's pace
// Went from addict to a workaholic, word to Dr. Dre
// In that first marijuana tape-guess I got a chronic case (yeah)
// And I ain't just blowin' smoke, 'less it's in your momma's face
// I know this time Paul and Dre
// They won't tell me what not to say (nope)
// And though me and my party days
// Have all pretty much parted ways
// You'd swear to God I forgot I'm the guy that made "Not Afraid"
// One last time for Charlamagne
// If my response is late, it's just how long it takes
// To hit my fuckin' radar, I'm so far away
// These rappers are like Hunger Games
// One minute, they're mockin' Jay
// Next minute, they get their style from Migos or they copy Drake
// Maybe I just don't know when to turn around and walk away
// But all the hate, I call it "Walk on Water" gate
// I've had as much as I can tolerate
// I'm sick and tired of waitin', I done lost my patience
// I can take all of you motherfuckers on at once
// You wanted Shady? You got him!

// ... Don't fall on my face (yeah)
// ... Don't fall on my faith, oh
// ... Don't fall on my fate (line 'em up!)
// ... Don't fall on my faith, oh (rrr!)
// ... Don't fall on my fate (look)

// Somebody tell Budden before I snap, he better fasten it
// Or have his body bag get zipped
// The closest thing he's had to hits is smackin' bitches
// And don't make me have to give it back to Akademiks
// Say this shit is trash again, I'll have you twisted
// Like you had it when you thought you had me slippin' at the telly
// Even when I'm gettin' brain, you'll never catch me with a thot
// Lackin' with it, "he ain't spittin' like this on his last shit"
// Ho, you better go back and listen
// You know me better, thinkin' I'll slow or let up
// Call it trap 'cause it's a total setup
// Hopin' that you rappers fall in that
// Dre said, "Hold your head up!" Kathy Griffin
// Stackin' ammunition, slap the clip in, cock it back on competition
// This is how I shot ahead (pew) Gabby Giffords
// My attack is vicious, Jack the Ripper, back in business
// Tyler create nothin', I see why you called yourself a (faggot), bitch
// It's not just 'cause you lack attention
// It's because you worship D12's balls, you're sack-religious
// If you're gonna critique me
// You better at least be as good or better
// Get Earl the Hooded Sweater
// Whatever his name is to help you put together
// Some words, more than just two letters
// The fans waited for this moment like that feature
// When I stole the show (ha), sorry if I took forever (haha)

// ... Don't fall on my face (yeah)
// ... Don't fall on my faith, oh (I won't)
// ... Don't fall on my fate (line 'em up!)
// ... Don't fall on my faith, oh (ha)
// ... Don't fall on my fate (it's too easy)

// Just remember, I was here before you
// And I'll be here after you make your run-in for you
// Detractors, I might have to fuck Pitchfork with a corkscrew
// Just what the doctor ordered
// Revenge is the best medicine
// Increase the dose, from least to most
// And then tell the Grammys to go and fuck themselves
// They suck the blood from all the biggest artists like some leeches
// So they nominate 'em, get 'em there, get a name to MC the show
// Every parasite needs a host (haha)
// Then give Album of the Year to somebody that no one's ever even heard of
// All I know is I wrote every single word of
// Everything I ever murdered
// Time to separate the sheep from goats (yeah)
// And I got no faith in your writers, I don't believe in ghosts
// When rap needed it most, I was that wing and a prayer
// A beacon of hope, put a B-I-R-D in the air
// Somewhere some kid is bumpin' this while he lip-syncs in the mirror
// That's who I'm doin' it for, the rest I don't really even care
// But you would think I'm carryin' a Oxford dictionary in my pocket
// How I'm buryin' these artists
// On a scale of 'turnt' you're 'minus'
// Mine says 'very', yours says 'hardly'
// And what's scary is you probably can compare me to your car 'cause I'm just barely gettin' started (woo)
// And far as Lord Jamar, you better leave me the hell alone
// Or I'll show you an Elvis clone
// Walk up in this house you own, thrust my pelvic bone
// Use your telephone and go fetch me the remote
// Put my feet up and just make myself at home
// I belong here, clown, don't tell me 'bout the culture
// I inspired the Hopsins, the Logics, the Coles, the
// Seans, the K-Dots, the 5'9"s, and oh
// Brought the world 50 Cent, you did squat, piss and moan
// But I'm not gonna fall... bitch!

// ... It's too loud
// ... Can't hear it coming down the hallway stairs from the parking lot
// ... It's too loud
// ... Three's not a crowd all up in it
// ... Slow fire

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define fill(x, v) memset(x, v, sizeof(x))
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)

#define N 100015
#define mod 1000000007
#define N1 105
#define sqr(x) (x)*(x)
#define INF 2000000000000000000

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> set_t;

#define trace(...) f(#__VA_ARGS__, __VA_ARGS__)

template<typename t> void f(const char* x, t&& val1){
    cout<<x<< " : "<<val1<<endl;
}
template<typename t1, typename... t2> void f(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    f(xd+1, val2...);
}

int main(){
    fastio;
    ll n, cnt=0, ans=0; cin>>n;
    FER(i,0,n){
        ll x; cin>>x;
        x? cnt++: ans+=cnt;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long ans;
int n, a[N], rn;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		rn += a[i], ans += (a[i] == 0) * rn;
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long n, t, ans, a;

int main() {
	cin >> n;
	while (n--) {
		cin >> a;
		a? t++: ans += t;
	}
	cout << ans << endl;
    return 0;
}


/**
 * author : wallcrawler
 **/

#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define el "\n"
#define INF (int)1e9+7
const int N = 2e5 + 10;

int n, a[N], c0[N], c1[N], cow1, cow0, ans, ans1, ans2;

void solve()  {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) {
		c0[i] = cow1;
		if(a[i] == 1) cow1++;
	}
	for(int i = 0; i < n; i++) { if(a[i] == 0) ans2 += c0[i]; }
	cout << ans2 << el;
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	freopen("input.txt", "r", stdin);
	solve();

}


/**
 * author : wallcrawler
 **/

#include<bits/stdc++.h>
using namespace std;

#define int long long int
#define el "\n"
#define INF (int)1e9+7
const int N = 2e5 + 10;

int n, a[N], c0[N], c1[N], cow1, cow0, ans, ans1, ans2;

void solve()  {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) {
		c0[i] = cow1;
		if(a[i] == 1) cow1++;
	}
	for(int i = n-1; i >= 0; i--) {
		c1[i] = cow0;
		if(a[i] == 0) cow0++;
	}
	for(int i = 0; i < n; i++) { if(a[i] == 1) ans1 += c1[i]; else ans2 += c0[i]; }
	cout << min(ans1, ans2) << el;
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	freopen("input.txt", "r", stdin);
	solve();

}


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#include <bits/stdc++.h>
using namespace std;

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int
#define ld long double
#define X first
#define Y second
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()

const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}

void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}

#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

void solve(){
    int n; cin >> n;
    vector<int> a(n);
    for(auto &x: a)
        cin >> x;

    int cnt0 = 0;
    int res = 0;
    for(int i = n - 1; i >= 0; --i){
        if(a[i] == 0){
            cnt0++;
        } else {
            res += cnt0;
        }
    }
    cout << res << '\n';
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T = 1;
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}

/*
Sample inp
*/


#include "bits/stdc++.h"

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define debug(x) cerr << #x << " == " << (x) << '\n'
#define mp(x, y) make_pair(x, y)
#define ALL(X) X.begin(), X.end()
#define READ(X) for (int i_ = 0; i_ < (int)X.size(); ++i_) cin >> X[i_]
#define SZ(X) (int)X.size()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main()
{ _
    int n; cin >> n;

    vi a(n); READ(a);

    vll dp(n, 0), R(n, 0); R[0] = a[0];

    for (int i = 1; i < n; R[i] = R[i - 1] + a[i], ++i)
        dp[i] = dp[i - 1] + R[i - 1] * !a[i];

    cout << dp[n - 1] << endl;

    exit(0);
}

/*
 * INT_MAX      ~  2 * 1e9  ~ 2^31 - 1
 * LLONG_MAX    ~  9 * 1e18 ~ 2^63 - 1
 * ULLONG_MAX   ~ 18 * 1e18 ~ 2^64 - 1
 *
 * INF  ~ 1.0 * 1e9
 * LINF ~ 4.5 * 1e18
 *
 * CHECK:
 *      OVERFLOW
 *      IF/LOOP CONDITIONS
 *      CREATION OF STL CONTAINERS
*/


#include <bits/stdc++.h>
#define sz(a) long (a.size())
#define f(i,a,b) for(long long int i=a;i<b;i++)
#define r(i,a,b) for(long long int i=a;i>b;i--)
#define pb push_back
#define mkp make_pair
#define mod 1000000009
#define MAX 100000
#define inf 1e18
#define MAXN 10000
#define SQRSIZE  100
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define negmod(X,Y) X % Y + (X % Y < 0 ? Y : 0)
#define debug(x) cerr<< #x << ':' << x << endl;
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define fit(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
using namespace std;
typedef long long int ll;
long long maximum=numeric_limits<int>:: max();
typedef vector<ll> vi;
typedef vector<vi> vvi;
inline int bit( int x, int i ) { return (x>>i)&1; }
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{return (a.second < b.second);}
ll get_hash(ll x, ll y, ll z)
{
    return (z) + (3001)*(y) + (3001*3001*(x));
    // unordered_set<ll> trips;trips.find(prep + v) == trips.end()
}
ll com(ll n,ll m){
    ll ans=1;m=max(m,n-m);
    f(i,1,n-m){
        ans=(ans*(m+i))/i;
    }
    return ans;
}
// partial_sum(a , a+5 , b);
// partial_sum(a , a+5 , b , myfun) ;
int solve()
{
    ll n,m,k;
    cin>>n>>m>>k;
    vector<int> v(n);
    f(i,0,n)cin>>v[i];
    k=min(k,m-1);
    ll ans=-1;//maxs of mins of maxs
    int moves=m-1-k;//this us total opponents moves
    // i and j goes <= because last man also takes it's number & we choose from the rest
    for(int i=0;i<=k;i++)
    {
        ll temp_ans=1e18;
        for(int j=0;j<=moves;j++)
        {
            ll mini=max(v[i+j], v[i+j+n-m]);
            // this mini is being taken by opponenet so maximum
            temp_ans=min(temp_ans, mini);
            // here minimum is because we will get minimum
        }
        ans=max(ans, temp_ans);
    }
    cout<<ans<<endl;
}
int n;
vi gr[150001];
vi iota(int n) {
    vi a(n);
    iota(all(a), 1);
    return a;
}
int get_parent(int i, vi par){while(par[i]!=i)i=par[i];return i;}
void dfs(int node)
{
    cout<<node<<" ";
    for(auto x:gr[node])
    {
        dfs(x);
    }
}
set<ll> s;
multiset<ll> dif; //x(i)-x(i-1)
ll a;
void add_postion(ll a)
{
    s.insert(a);
    // auto it=s.insert(a).first;
    auto it=s.find(a);
    // cout<<*it<<" ";
    if (next(it) != s.end())dif.insert(*next(it) - a);
    if (it != s.begin()) {
        dif.insert(a - *prev(it));
        if (next(it) != s.end()) dif.erase(dif.find(*next(it) - *prev(it)));
    }
}
void erase_position(ll a)
{
    auto it = s.find(a);
    if (next(it) != s.end()) dif.erase(dif.find(*next(it) - a));

        if (it != s.begin()) {
            dif.erase(dif.find(a - *prev(it)));
            if (next(it) != s.end())dif.insert(*next(it) - *prev(it));
        }
        s.erase(it);
}
ll query()
{
    if (s.size() <= 2)return 0;
    return *(--s.end()) - *s.begin() - *(--dif.end());
    // *---*-*.........*---*----*
}
vi adj_test[11];
vi h(11,0);
auto par=iota(11);
void dfs_test(int v,int p = -1)
{
    if(p + 1) { h[v] = h[p] + 1; }
    par[v] = p;
    for(auto u : adj_test[v])
    {
        if(p - u)dfs_test(u,v);//not to avoid cycle bcuz its a tree
    }
}
int LCA(int v,int u){
    if(v == u)
        return v;
    if(h[v] < h[u])
        swap(v,u);
    return LCA(par[v], u);
}
int TIME=0;
vi st(11,0);
vi ft(11,0);
vi color(11,-1);
void dfs_time(int v)
{
        st[v] = TIME++;
        color[v]=1;// color[v] = gray;
        for(auto u :adj_test[v])
        {
            if (color[u] == -1) dfs_time(u);
        }
        // color[v] = black;
        ft[v] = TIME;// or we can use TIME ++
}
int arr[MAXN];               // original array
int block[SQRSIZE];          // decomposed array
int blk_sz;                      // block size
// Time Complexity : O(1)
void update(int idx, int val)
{
    int blockNumber = idx / blk_sz;
    block[blockNumber] += val - arr[idx];
    arr[idx] = val;
}
bool bin_search(int x[], int n, int k) {
    int p = 0;
    for (int a = n; a >= 1; a /= 2) {
        while (p+a < n && x[p+a] <= k) p += a;
    }
    return x[p] == k;
}
int count_same(int x[], int n, int k) {
    int p = -1, q = -1;
    for (int a = n; a >= 1; a /= 2) {
        while (p+a < n && x[p+a] < k) p += a;
        while (q+a < n && x[q+a] <= k) q += a;
    }
    return q-p;
}
// Time Complexity : O(sqrt(n))
int query(int l, int r)
{
    int sum = 0;
    while (l<r and l%blk_sz!=0 and l!=0)
    {
        // traversing first block in range
        sum += arr[l];
        l++;
    }
    while (l+blk_sz <= r)
    {
        // traversing completely overlapped blocks in range
        sum += block[l/blk_sz];
        l += blk_sz;
    }
    while (l<=r)
    {
        // traversing last block in range
        sum += arr[l];
        l++;
    }
    return sum;
}
// Fills values in input[]
void preprocess(int input[], int n)
{
    // initiating block pointer
    int blk_idx = -1;

    // calculating size of block
    blk_sz = sqrt(n);

    // building the decomposed array
    for (int i=0; i<n; i++)
    {
        arr[i] = input[i];
        if (i%blk_sz == 0)
        {
            // entering next block
            // incementing block pointer
            blk_idx++;
        }
        block[blk_idx] += arr[i];
    }
}
void showdq(deque <ll> g)
{
    deque <ll> :: iterator it;
    for (it = g.begin(); it != g.end(); ++it) cout<<*it<<' ';
    cout<<'\n';
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // greedy math brute force # sorting pointers
    ll n;cin>>n;
    vi v(n);f(i,0,n)cin>>v[i];
    ll ans=0;
    vi cnt(n);
    cnt[n-1]=!v[n-1];
    r(i,n-2,-1)
    {
        cnt[i]+=cnt[i+1]+!v[i];
    }
    f(i,0,n)
    {
        if(v[i])
        {
            ans+=cnt[i];
        }
    }
    cout<<ans;
    // sort(all(v));
    // vi ans_v;
    // deque<ll> a,b;
    // f(i,0,n)
    // {
    //     // if(i%2)
    //     // {
    //     //     a.push(v[i]);
    //     // }
    //     // else
    //     // {
    //     //     b.push(v[i]);
    //     // }
    //     a.pb(v[i]);
    // }
    // deque<ll>c;
    // showdq(a);
    // while(a.size())
    // {
    //     if(a.size()>2)
    //     {
    //         ll x=-1,y=-1,z=-1;
    //         auto it1=a.begin();
    //         auto it2=a.end();--it2;
    //         if(a.size())x=*it1;it1++;
    //         if(a.size())y=*it1;
    //         if(a.size())z=*it2;
    //         ans_v.pb(x);
    //         ans_v.pb(y);
    //         ans_v.pb(z);
    //         a.pop_back();
    //         a.pop_front();
    //         a.pop_front();
    //         ans+=1;
    //     }
    //     else
    //     {
    //         auto it=a.begin();
    //         while(it!=a.end()){ans_v.pb(*it);it++;}
    //         // while(!b.empty())ans_v.pb(b.pop_front());
    //         break;
    //     }
    // }
    // cout<<ans<<"\n";
    // f(i,1,n-2)
    // {

    // }
    // for(auto x:ans_v)
    // {
    //     cout<<x<<" ";
    // }
    // ll n,m,a,b;cin>>n;//>>m;
    // // vi v(n);f(i,0,n)cin>>v[i];
    // f(i,0,n-1)
    // {
    //     cin>>a>>b;
    //     adj_test[a].pb(b);
    //     adj_test[b].pb(a);
    // }
    // dfs_test(1);
    // for(auto x:par){
    //     cout<<x<<" ";
    // }cout<<endl;
    // for(auto x:h){
    //     cout<<x<<" ";
    // }cout<<endl;
    // dfs_time(1);
    // for(auto x:st){
    //     cout<<x<<" ";
    // }cout<<endl;
    // for(auto x:ft){
    //     cout<<x<<" ";
    // }

    // int input[] = {1, 5, 2, 4, 6, 1, 3, 5, 7, 10};
    // int n = sizeof(input)/sizeof(input[0]);
    // preprocess(input, n);
    // cout << "query(3,8) : " << query(3, 8) << endl;
    // cout << "query(1,6) : " << query(1, 6) << endl;
    // update(8, 0);
    // cout << "query(8,8) : " << query(8, 8) << endl;
}
class Node{
    public:
        int data;
        Node *left;
        Node *right;
        Node* next;
        Node(int d){
            data = d;
            left = NULL;
            right = NULL;
        }
};
class Solution{
    public:
        Node* insert(Node* root, int data) {
            if(root == NULL) {
                return new Node(data);
            }
            else {
                Node* cur;
                if(data <= root->data){
                    cur = insert(root->left, data);
                    root->left = cur;
                }
                else{
                    cur = insert(root->right, data);
                    root->right = cur;
               }

               return root;
           }
        }
    int get_height_bfs(Node* root)
    {
        int h=0;// bfs
        queue<Node*> q;
        q.push(root);
        while(!q.empty())
        {
            h++;
            Node* temp=q.front();
            q.pop();
            if(temp->left)q.push(temp->left);
            if(temp->right)q.push(temp->right);
        }
    }
    int get_Height(Node* root, int h)
    {
        if(root==nullptr)return h-1;
        else
        {
            return max(get_Height(root->left, h+1), get_Height(root->right, h+1));
        }
    }
    int getHeight(Node* root)
    {
        int ans=0;
        ans=get_Height(root, 0);
        return ans;
    }
    Node* removeDuplicates(Node *head)
          {
              Node* current = head;
              while (current != nullptr && current->next != nullptr) {
                  Node* temp = current->next;
                  if (current->data == temp->data) { // duplicate found
                      current->next = temp->next;
                      delete temp;
                  } else {
                     current = current->next;
                  }
              }

              return head;
          }
};
void make_tree()
{
    Solution myTree;
    Node* root = NULL;
    int t; cin >> t;
    int data;
    while(t-- > 0){
        cin >> data;
        root = myTree.insert(root, data);
    }
    int height = myTree.getHeight(root);
    cout << height;
}
class BinaryTree {
public:
  int value;
  BinaryTree *left;
  BinaryTree *right;
  BinaryTree(int value) {this->value = value;left = NULL;right = NULL;}
};
void dfs(BinaryTree* root, int sum, vector<int>& ans)
{
        int sum1=sum,sum2=sum;
        if(root!=nullptr and root->left!=nullptr)sum1+=root->left->value;
        if(root!=nullptr)dfs(root->left,sum1, ans);
        if(root!=nullptr and root->right!=nullptr)sum2+=root->right->value;
        if(root!=nullptr)dfs(root->right,sum2, ans);
        if(root!=nullptr and root->right==nullptr and root->left==nullptr)ans.push_back(sum);
}
vector<int> branchSums(BinaryTree *root) {
    vector<int> ans={};
    if(root!=nullptr)dfs(root,root->value,ans);
  return {ans};
}
//prev->next = n->next;...fake and real ptr
// vector<int> v={1,2,3,3,14,4,5,5,6,6,7,7,8,5,10};
// sort(all(v));
// for(auto x:v){cout<<x<<" ";}cout<<endl;
// cout<<lower_bound(all(v), 6)-v.begin()<<" ";
// cout<<upper_bound(all(v), 6)-v.begin();
// lower_bound returns an iterator pointing to the first element in the range
// [first,last) which has a value not less than ‘val’.
// upper_bound returns an iterator pointing to the first element in the range
// [first,last) which has a value greater than ‘val’.

// https://codeforces.com/contest/965/submission/37617515
// https://recommender.codedrills.io/recommendations/a84cb4e1-1d54-4e0f-8f64-de726b77d05b
// https://recommender.codedrills.io/recommendations/ebfb9d6e-fbd3-434e-89fb-8070b449c9ed
// https://codeforces.com/problemset/problem/264/A
// https://codeforces.com/problemset/problem/276/C

/*
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<vector<int>> g;
vector<int> sz, p;
vector<int> centroids;

int n;

void dfs(const int &v, const int &anc) {
    sz[v] = 1;
    p[v] = anc;
    bool good = true;
    for (auto to : g[v]) {
        if (to == anc) continue;
        dfs(to, v);
        good &= (sz[to] * 2 <= n);
        sz[v] += sz[to];
    }
    good &= (sz[v] * 2 >= n);
    if (good) centroids.emplace_back(v);
}

int leaf(const int &v, const int &anc) {
    if (g[v].size() == 1) return v;
    for (auto to : g[v]) {
        if (to == anc) continue;
        int l = leaf(to, v);
        if (l != -1) return l;
    }
    return -1;
}

signed main() {
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        cout << fixed << setprecision(3);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << fixed << setprecision(15);
    #endif
    int T;
    cin >> T;
    while (T --> 0) {
        cin >> n;
        g.clear();
        sz.clear();
        p.clear();
        centroids.clear();
        g.resize(n);
        sz.resize(n);
        p.resize(n);
        for (int i = 0; i < n - 1; ++i) {
            int x, y;
            cin >> x >> y;
            --x; --y;
            g[x].emplace_back(y);
            g[y].emplace_back(x);
        }
        dfs(0, -1);
        int c1 = centroids[0];
        int c2 = -1;
        if (centroids.size() > 1) c2 = centroids[1];
        if (c2 == -1) {
            cout << 1 << ' ' << g[0][0] + 1 << '\n';
            cout << 1 << ' ' << g[0][0] + 1 << '\n';
        } else {
            if (sz[c2] > sz[c1]) swap(c1, c2);
            int l = leaf(c2, c1);
            cout << l + 1 << ' ' << p[l] + 1 << '\n';
            cout << l + 1 << ' ' << c1 + 1 << '\n';
        }
    }
    #ifdef LOCAL
    cerr << "proc time: " << 1.0 * clock() / CLOCKS_PER_SEC << "s    ";
    #endif
    return 0;
}
*/


#include <bits/stdc++.h>

#define ll long long
using namespace std;

int main() {

    cin.tie(0);
    cin.sync_with_stdio(0);

    int n;
    cin>>n;
    int a[n];
    ll z=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0)z++;
    }
    ll ans=0;
    for(int i=0;i<n;i++){
        if(a[i]){
            ans+=z;
        }else{
            z--;
        }
    }

    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll N = 1005;
int main() {
	ll n, i, x, cnt, ans;
	cin >> n;
	cnt = ans = 0;
	for(i = 1; i <= n; i++) {
		cin >> x;
		if(x) cnt++;
		else ans += cnt;
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];

    int cur = 0 , ans1 = 0 , ans2 = 0;
    for (int i = 0 ; i < n ; ++i){
        if (a[i]) cur++;
        else ans1 += cur;
    }
    cur = 0;
    for (int i = n-1 ; i >= 0 ; --i){
        if (!a[i]) cur++;
        else ans2++;
    }

    cout << min (ans1,ans2);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
int _;
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//for(cin>>_;_;--_,cout<<'\n')
    Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];

    ll cur = 0 , ans1 = 0 , ans2 = 0;
    for (int i = 0 ; i < n ; ++i){
        if (a[i]) cur++;
        else ans1 += cur;
    }
    cur = 0;
    for (int i = n-1 ; i >= 0 ; --i){
        if (!a[i]) cur++;
        else ans2++;
    }

    if (!min(ans1,ans2))
        cout << 0;
    else
        cout << max (ans1,ans2);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
int _;
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//for(cin>>_;_;--_,cout<<'\n')
    Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];

    ll cur = 0 , ans1 = 0 , ans2 = 0;
    for (int i = 0 ; i < n ; ++i){
        if (a[i]) cur++;
        else ans1 += cur;
    }
    cur = 0;
    for (int i = n-1 ; i >= 0 ; --i){
        if (!a[i]) cur++;
        else ans2++;
    }

    cout << max (ans1,ans2);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
int _;
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//for(cin>>_;_;--_,cout<<'\n')
    Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int a[n];
    for (int i = 0 ; i < n ; ++i)
        cin >> a[i];

    int cur = 0 , ans1 = 0 , ans2 = 0;
    for (int i = 0 ; i < n ; ++i){
        if (a[i]) cur++;
        else ans1 += cur;
    }
    cur = 0;
    for (int i = n-1 ; i >= 0 ; --i){
        if (!a[i]) cur++;
        else ans2++;
    }

    cout << max (ans1,ans2);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
int _;
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//for(cin>>_;_;--_,cout<<'\n')
    Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define endl '\n';

int main() {
    int n,m=0;
    ll ans=0;

    cin>>n;

    vector<int> a(n);

    for (int i=0; i<n; i++)
        cin>>a[i];

    for (int i=0; i<n; i++){
        if (a[i]==1)
            m++;
        else
            ans+=m;
    }

    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define endl '\n';

int main() {
    int n,m=0,ans=0;

    cin>>n;

    vector<int> a(n);

    for (int i=0; i<n; i++)
        cin>>a[i];

    for (int i=0; i<n; i++){
        if (a[i]==1)
            m++;
        else
            ans+=m;
    }

    cout<<ans;

    return 0;
}


#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N];

int main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    ll flag=0,sum=0;
    ll t=0;
    for(int i=1;i<=n;i++)
    {
        if(!flag && !ar[i])
        {
            // t++;
            continue;
        }
        flag++;
        if(ar[i])
            t++;
        else
            sum+=t;
    }
    cout<<sum;
}


#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N];

int main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    int flag=0,sum=0;;
    for(int i=1;i<=n;i++)
    {
        if(!flag && !ar[i])
            continue;
        flag++;
        if(ar[i])
            sum++;
    }
    cout<<sum;
}


#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N];

int main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    int flag=0,sum=0;
    int t=0;
    for(int i=1;i<=n;i++)
    {
        if(!flag && !ar[i])
        {
            // t++;
            continue;
        }
        flag++;
        if(ar[i])
            t++;
        else
            sum+=t;
    }
    cout<<sum;
}


#include <bits/stdc++.h>
#define N 1000005
#define ll long long int
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N];

int main()
{
    fast;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    int flag=0,sum=0;
    int t=0;
    for(int i=1;i<=n;i++)
    {
        if(!flag && !ar[i])
        {
            t++;
            continue;
        }
        flag++;
        if(!ar[i])
            t++;
        else
            sum+=t;
    }
    cout<<sum;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define vl vector<ll>

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

int main()
{
	fastio();
	ll n;
	cin>>n;
	ll a[n + 1], p0 = 0, p1 = n + 1, x = 1, c1[n + 2] = {0}, c0[n + 2] = {0};
	for(ll i = 1; i <= n; i++)
	{
		cin>>a[i];
		if(a[i] && x) p1 = i, x = 0;
		if(!a[i]) p0 = i;
		c1[i] = c1[i - 1];
		if(a[i]) ++c1[i];
	}
	for(ll i = n; i; i--)
	{
		c0[i] = c0[i + 1];
		if(!a[i]) ++c0[i];
	}
//	cout<<p0<<" "<<p1<<"\n";
//	for(ll i = 1; i <= n; i++) cout<<c1[i]<<" "<<c0[i]<<"\n";
	ll ans = 0;
	while(p0 && p1 <= n)
	{
		if(c1[p0] <= c0[p1])
		{
			ans += c1[p0];
			--p0;
			while(p0 && a[p0]) --p0;
		}
		else
		{
			ans += c0[p1];
			++p1;
			while(p1 <= n && !a[p1]) ++p1;
		}
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define vl vector<ll>

void fastio()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cout<<fixed<<setprecision(10);
}

int main()
{
	fastio();
	ll n;
	cin>>n;
	ll a[n + 1], p0 = 0, p1 = n + 1, x = 1, c1[n + 2] = {0}, c0[n + 2] = {0};
	for(ll i = 1; i <= n; i++)
	{
		cin>>a[i];
		if(a[i] && x) p1 = i, x = 0;
		if(!a[i]) p0 = i;
		c1[i] = c1[i - 1];
		if(a[i]) ++c1[i];
	}
	for(ll i = n; i; i--)
	{
		c0[i] = c0[i + 1];
		if(!a[i]) ++c0[i];
	}
	ll ans = 0;
	while(p0 && p1 <= n)
	{
		if(c1[p0] <= c0[p1])
		{
			ans += c1[p0];
			--p0;
			while(p0 && a[p0]) --p0;
		}
		else
		{
			ans += c0[p1];
			++p1;
			while(p1 <= n && !a[p1]) ++p1;
		}
	}
	cout<<ans;
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
class BDoimKorov {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n;
        cin >> n;
        vector<ll> a(n);

        for (ll i = 0; i < n; ++i) {
            cin >> a[i];
        }

        ll one = count(a.begin(),a.end(),1);
        ll zero = count(a.begin(),a.end(),0);

        ll y = 0;
        for (ll i = n - 1; i >= 0; --i) {
            if (a[i] == 1){
                one--;
            }else {
                y += one;
            }
        }

        ll x = 0;
        for (ll i = 0; i < n; ++i) {
            if (a[i] == 0){
                zero--;
            }else{
                x += zero;
            }
        }

        cout << min(x,y) << endl;
	}
};

int main() {
	BDoimKorov solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author emli
 */

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
class BDoimKorov {
public:
    void solve(std::istream& cin, std::ostream& cout) {
		ios::sync_with_stdio(false);
        cin.tie(nullptr);
        int n;
        cin >> n;
        vector<int> a(n);

        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }

        int one = count(a.begin(),a.end(),1);
        int zero = count(a.begin(),a.end(),0);

        int y = 0;
        for (int i = n - 1; i >= 0; --i) {
            if (a[i] == 1){
                one--;
            }else {
                y += one;
            }
        }

        int x = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] == 0){
                zero--;
            }else{
                x += zero;
            }
        }

        cout << min(x,y) << endl;
	}
};

int main() {
	BDoimKorov solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,m,j,k,l,o,p;
    cin>>n;
    int a[n];
    int zero = 0,N=0,one = 0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    zero = 0 , one = 0 ,m=0;
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==1)
        {
            m+=zero;
        }
        else
        {
            zero+=1;
        }
    }
    cout<<m;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int i,n,m,j,k,l,o,p;
    cin>>n;
    ll int a[n];
    ll int zero = 0,one = 0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] == 0)
        {
            zero+=1;
        }
        else
        {
            one+=1;
        }
    }
    ll int b[n],c[n];
    ll int N=0,M=0;
    for(i=0;i<n;i++)
    {
        if(a[i] == 1)
        {
            N+=zero;
        }
        else
        {
            zero-=1;
        }
    }
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==0)
        {
            M+=one;
        }
        else
        {
            one-=1;
        }
    }
    cout<<min(N,M)<<endl;


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,m,j,k,l,o,p;
    cin>>n;
    int a[n];
    int zero = 0,N=0,one = 0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] == 0)
        {
            zero+=1;
            N+=one;
        }
        else
        {
            one+=1;
        }
    }
    zero = 0 , one = 0 ,m=0;
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==1)
        {
            m+=zero;
        }
        else
        {
            zero+=1;
        }
    }
    cout<<min(N,m);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,m,j,k,l,o,p;
    cin>>n;
    int a[n];
    int zero = 0,one = 0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] == 0)
        {
            zero+=1;
        }
        else
        {
            one+=1;
        }
    }
    int b[n],c[n];
    int N=0,M=0;
    for(i=0;i<n;i++)
    {
        if(a[i] == 1)
        {
            N+=zero;
        }
        else
        {
            zero-=1;
        }
    }
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==0)
        {
            M+=one;
        }
        else
        {
            one-=1;
        }
    }
    cout<<min(N,M);
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll int i,n,m,j,k,l,o,p;
    cin>>n;
    ll int a[n];
    ll int zero = 0,one = 0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i] == 0)
        {
            zero+=1;
        }
        else
        {
            one+=1;
        }
    }
    ll int b[n],c[n];
    ll int N=0,M=0;
    for(i=0;i<n;i++)
    {
        if(a[i] == 1)
        {
            N+=zero;
        }
        else
        {
            zero-=1;
        }
    }
    for(i=n-1;i>=0;i--)
    {
        if(a[i]==0)
        {
            M+=one;
        }
        else
        {
            one-=1;
        }
    }
    cout<<min(N,M)<<endl;
}


    #include <bits/stdc++.h>
    #define ll long long int
    using namespace std;
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin >> n;
        int suffLeft[n+2],suffRight[n+2],ary[n+1];
        int doneLeft = 0,doneRight = 0;
        for(int i = 1;i<n+1;i++){
            cin >> ary[i];
        }
        suffRight[0]  = 0;
        //suffRight[0] = 0;
        suffLeft[n+1] = 0;
        for(int i = 1;i<n+1;i++){
            suffRight[i] = suffRight[i-1];
            if(ary[i]==1)suffRight[i]++;
        }
        for(int i = n;i>0;i--){
            suffLeft[i] = suffLeft[i+1];
            if(ary[i] == 0)suffLeft[i]++;
        }
        int indexLeft = 1,indexRight =n;
        ll totalLost = 0;
        for(int i = 1;i<n;i++){
                if(ary[i] == 1){
                    indexLeft = i;
                    break;
                }
        }
        for(int i = n;i>0;i--){
            if(ary[i] == 0){
                indexRight = i;
                break;
            }
        }
        while(indexLeft < indexRight){
            while(ary[indexLeft] != 1  && indexLeft < indexRight)indexLeft++;
            while(ary[indexRight] != 0 && indexLeft < indexRight)indexRight--;
            if(suffLeft[indexLeft-1] - doneLeft > suffRight[indexRight-1]-doneRight){
                totalLost += suffRight[indexRight-1]-doneRight;
                if(ary[indexRight] == 0)doneLeft++;
                else doneRight++;
                indexRight--;
            }else{
                totalLost += suffLeft[indexLeft-1]-doneLeft;
                if(ary[indexLeft] == 0)doneLeft++;
                else doneRight++;
                indexLeft++;
            }
        }
        cout << totalLost;
        //cin >> n;
    }


#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int suffLeft[n+2],suffRight[n+2],ary[n+1];
    int doneLeft = 0,doneRight = 0;
    for(int i = 1;i<n+1;i++){
        cin >> ary[i];
    }
    suffRight[0]  = 0;
    //suffRight[0] = 0;
    suffLeft[n+1] = 0;
    for(int i = 1;i<n+1;i++){
        suffRight[i] = suffRight[i-1];
        if(ary[i]==1)suffRight[i]++;
    }
    for(int i = n;i>0;i--){
        suffLeft[i] = suffLeft[i+1];
        if(ary[i] == 0)suffLeft[i]++;
    }
    int indexLeft = 1,indexRight =n;
    ll totalLost = 0;
    for(int i = 1;i<n;i++){
            if(ary[i] == 1){
                indexLeft = i;
                break;
            }
    }
    for(int i = n;i>0;i--){
        if(ary[i] == 0){
            indexRight = i;
            break;
        }
    }
    while(indexLeft < indexRight){
        while(ary[indexLeft] != 1  && indexLeft < indexRight)indexLeft++;
        while(ary[indexRight] != 0 && indexLeft < indexRight)indexRight--;
        if(suffLeft[indexLeft-1] - doneLeft > suffRight[indexRight-1]-doneRight){
            totalLost += suffRight[indexRight]-doneRight;
            if(ary[indexRight] == 0)doneLeft++;
            else doneRight++;
            indexRight--;
        }else{
            totalLost += suffLeft[indexLeft]-doneLeft;
            if(ary[indexRight] == 0)doneLeft++;
            else doneRight++;
            indexLeft++;
        }
    }
    cout << totalLost;
}


    #include <bits/stdc++.h>
    #define ll long long int
    using namespace std;
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n;
        cin >> n;
        int suffLeft[n+2],suffRight[n+2],ary[n+1];
        int doneLeft = 0,doneRight = 0;
        for(int i = 1;i<n+1;i++){
            cin >> ary[i];
        }
        suffRight[0]  = 0;

        //suffRight[0] = 0;
        suffLeft[n+1] = 0;
        for(int i = 1;i<n+1;i++){
            suffRight[i] = suffRight[i-1];
            if(ary[i]==1)suffRight[i]++;
        }
        for(int i = n;i>0;i--){
            suffLeft[i] = suffLeft[i+1];
            if(ary[i] == 0)suffLeft[i]++;
        }
        suffLeft[n+1] = suffLeft[n];
        int indexLeft = 1,indexRight =n;
        ll totalLost = 0;
        for(int i = 1;i<n;i++){
                if(ary[i] == 1){
                    indexLeft = i;
                    break;
                }
        }
        for(int i = n;i>0;i--){
            if(ary[i] == 0){
                indexRight = i;
                break;
            }
        }
        while(indexLeft < indexRight){
            while(ary[indexLeft] != 1  && indexLeft < indexRight )indexLeft++;
            while(ary[indexRight] != 0 && indexLeft < indexRight )indexRight--;
            if(indexLeft >= indexRight)break;
            //cout << indexLeft << " " << indexRight<<endl;
            if(suffLeft[indexLeft] - doneLeft > suffRight[indexRight]-doneRight){
                totalLost += suffRight[indexRight]-doneRight;
                if(ary[indexRight] == 0)doneLeft++;
                else doneRight++;
                indexRight--;
            }else{
                totalLost += suffLeft[indexLeft]-doneLeft;
                if(ary[indexLeft] == 0)doneLeft++;
                else doneRight++;
                indexLeft++;
            }
        }
        cout << totalLost;
        //cin >> n;
    }


/**
 *  author: Haunted_Cpp
**/

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  vector<vector<int>> pre(2, vector<int>(n));
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    pre[arr[i]][i]++;
    if (i) {
      pre[0][i] += pre[0][i - 1];
      pre[1][i] += pre[1][i - 1];
    }
  }
  auto range_query = [&](int l, int r, const vector<int>& dp) {
    return dp[r] - (l - 1 >= 0 ? dp[l - 1] : 0);
  };
  auto solve = [&](int doit) {
    long long res = 0;
    vector<int> t;
    for (int i = 0; i < n; i++) {
      if (arr[i] == doit) {
        t.emplace_back(i);
      }
    }
    if (doit == 0) reverse(t.begin(), t.end());
    for (auto where : t) {
      if (doit == 0) {
        res += range_query(0, where - 1, pre[1]);
      } else {
        res += range_query(where + 1, n - 1, pre[0]);
      }
    }
    return res;
  };
  cout << min(solve(0), solve(1)) << '\n';
  return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define  CIN            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define  ll             long long int
vector<ll>v1;

int main()
{
    CIN;
    ll  a,b,i,cnt1=0,cnt2=0,sum1=0,sum2=0,T;
    cin >> a ;
    for( i = 0 ; i < a ; i++)
    {
        cin >> b ;
        if(b==0)
            cnt1++;
        else
            cnt2++;
        v1.push_back(b);
    }
    for( i = 0 ; i < a ; i++)
    {
        if(v1[i]==0)
        {
            cnt1--;
        }
        else
        {
            sum1+=cnt1;
        }
    }
    for( i = a-1; i >=0 ; i--)
    {
        if(v1[i]==1)
        {
            cnt2--;
        }
        else
        {
            sum2+=cnt2;
        }
    }
    cout<<min(sum1,sum2)<<endl;
    return 0 ;
}


#include <iostream>
#include <algorithm>
using namespace std;
struct ele{
    int val=0;
    int left1=0;
    int right1=0;
    int left0=0;
    int right0=0;
};
bool comp(ele x ,ele y){
    if(x.val>y.val){
        return true;
    }
    return false;
}
int main()
{
   int n;
   cin>>n;
   long long cnt=0;
   long long sum=0;
   for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        cnt+=x;
        if(!x)sum+=cnt;
    }
    cout<<sum;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define po pop_back
#define pb push_back
#define mk make_pair
#define lw lower_bound
#define up upper_bound
#define ff first
#define ss second
#define MOD 1000000007
#define boost ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
ll ans,a,b,c[1234567],c1[1234567],d[1234567],e,i,j,n,k,x,y,ideh[1234567];
map< pair< ll,ll> , ll> m;
vector<pair<ll,ll>> v1[1234567],v,vma,vmi;
vector<ll> ::iterator it;
string s,s1[1234567];
multiset<ll> ms;
set<char> se[1234];
queue<ll> q;
deque<ll> dq;
pair<ll,ll> p[123456];
priority_queue<ll> pq;
int main(){
    boost
    cin>>n;
    for(int i = 1; i <= n; i++){
    	cin>>c[i];
	}
	a = 0;
	for(int i = 1; i <= n; i++){
		if(c[i] == 1) a++;
		else ans += a;
	}
	a = 0;
	for(int i = n; i >= 1; i--){
		if(c[i] == 0) a++;
		else ans += a;
	}
	cout<<ans / 2;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

int s, ans, n, a;

int32_t main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		s += a;
		if (a == 0) ans += s;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long
#define PI 3.141592653589793238

#define Yes(a) cout << (a ? "Yes" : "No") << endl
#define YES(a) cout << (a ? "YES" : "NO") << endl
#define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

template<typename T> istream& operator>>(istream &is, complex<T> &vl){
  T a,b; is >> a >> b; vl = complex<T>(a,b); return is;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){
  return s << "(" << p.first << ", " << p.second << ")";
}
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<typename T1, typename T2> istream& operator>>(istream &is,pair<T1, T2>& p){
  is >> p.first >> p.second; return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?" ":"");
  return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &st){
  for(auto i = st.begin();i != st.end();++i) os << *i << (i!=st.end()?" ":"");
  return os;
}
template<class T> ostream& operator<<(ostream &os, const unordered_set<T> &st){
  for(auto i = st.begin();i != st.end();++i) os << *i << (i!=st.end()?" ":"");
  return os;
}
template<typename T1, typename T2> ostream& operator<<(ostream &os, const map<T1,T2> &st){
  for(auto i = st.begin();i != st.end();++i) os << i->first <<" " << i->second << endl;
  return os;
}
template<typename T1, typename T2> ostream& operator<<(ostream &os, const unordered_map<T1,T2> &st){
  for(auto i = st.begin();i != st.end();++i) os << i->first <<" " << i->second << endl;
  return os;
}
template<> ostream& operator<<(ostream &os, const vector<string> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>,
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */

   long int n;
   cin>>n;

   vector<long int> v(n);
   cin>>v;

   long int zeroCount = 0, oneCount = 0;
   long int ans1 = 0, ans2 = 0;

   zeroCount = count(v.begin(),v.end(),0);
   oneCount = count(v.begin(),v.end(),1);

   bool done = true;

   for(long int i = 0; i < n; i++){
    if(!v[i])
      zeroCount--;

    if(!v[i] && done)
      continue;

    done = false;
    ans1 += zeroCount;
   }

   done = true;

   for(long int i = n - 1; i >= 0; i--){
    if(v[i])
      oneCount--;

    if(v[i] && done)
      continue;

    ans2 += oneCount;
   }

   cout<<min(ans1,ans2);
   return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int N = 2 * 100 * 1000 + 2;
long long n, cnt, ans;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		a == 0? ans += cnt: cnt++;
	}
	cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits>
#include <iomanip>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <unordered_map>

using ll = long long ;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &i : a){
        cin >> i;
    }
    int cnt = 0;
    ll s1 = 0;
    ll s2 = 0;
    for (int i = 0; i < n; ++i){
        if (a[i] == 0){
            s1 += cnt;
        } else {
            ++cnt;
        }
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; --i){
        if (a[i] == 1){
            s2 += cnt;
        } else {
            ++cnt;
        }
    }
    cout << min (s1, s2) << '\n';
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <limits>
#include <iomanip>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <unordered_map>

using ll = long long ;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &i : a){
        cin >> i;
    }
    int cnt = 0;
    int s1 = 0;
    int s2 = 0;
    for (int i = 0; i < n; ++i){
        if (a[i] == 0){
            s1 += cnt;
        } else {
            ++cnt;
        }
    }
    cnt = 0;
    for (int i = n - 1; i >= 0; --i){
        if (a[i] == 1){
            s2 += cnt;
        } else {
            ++cnt;
        }
    }
    cout << min (s1, s2) << '\n';
}


#include <bits/stdc++.h>
#define roflan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ld long double
#define int long long
using namespace std;

signed main(){
  roflan;
  int n;
  cin >> n;
  vector <int> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  int ans = 0, ct = 0;
  for (int i = n - 1; i >= 0; i--){
    if (a[i]){
      ans += ct;
    }
    else{
      ct++;
    }
  }
  cout << ans;
  return 0;
}


#include<bits/stdc++.h>

/*************************** MACROS **************************/
#define itn int
#define ld long double
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define loop(i,x,y) for(ll i=x;i<y;i++)
#define rloop(i,x,y) for(ll i=x;i>=y;i--)
#define W(x) while(x--)
#define pll pair< ll,ll >
#define vpll vector< pll >
#define pqll priority_queue<ll>
#define pqpll priority_queue<pll>
#define MOD 1000000007
#define MOD1 998244353
#define MIN_LL -1e18
#define MAX_LL 1e18
#define MAX_INT 1e9
#define MIN_INT -1e9
#define Line cout<<"\n**************************\n\n";

using namespace std;

/*************************** VARIABLES **************************/

bool br1,br2,br;

ll n,k,x,y,z,mini,maxi,l,ind,ini,sum,t,len,r,q,m,imini;

string s,s1,s2;

/**************************** FXNS ****************************/

void solve(){

	cin>>n;

	loop(i,0,n){

		cin>>x;

		if(x == 1)y++;

		else z += y;
	}

	cout<<z<<endl;

}

/*************************** MAIN ****************************/

 int main(){

	/*#ifndef ONLINE_JUDGE
	        freopen("inputNaNtxt", "rt", stdin);
	        freopen("output.txt", "wt", stdout);
	#endif*/

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

    solve();

	return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

bool isprime(ll n)
{
	if (n == 1)
	{
		return false;
	}
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin >> n;
	ll arr[n];
	for (ll i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	ll suf[n];
	suf[n - 1] = 0;

	for (ll i = n - 2; i >= 0; i--)
	{
		suf[i] = suf[i + 1];
		if (arr[i + 1] == 0)
		{
			suf[i]++;
		}
	}

	ll ans = 0;

	for (ll i = 0; i < n; i++)
	{
		if (arr[i] == 1)
		{
			ans += suf[i];
		}
	}

	cout << ans << endl;

}


#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

bool isprime(ll n)
{
	if (n == 1)
	{
		return false;
	}
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			return false;
		}
	}
	return true;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin >> n;
	ll arr[n];
	for (ll i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	ll pre[n];
	pre[0] = 0;
	ll suf[n];
	suf[n - 1] = 0;
	for (ll i = 1; i < n; i++)
	{
		pre[i] = pre[i - 1];
		if (arr[i - 1] == 1)
		{
			pre[i]++;
		}
	}
	for (ll i = n - 2; i >= 0; i--)
	{
		suf[i] = suf[i + 1];
		if (arr[i + 1] == 0)
		{
			suf[i]++;
		}
	}

	vector<pair<ll, ll> >v;
	for (ll i = 0; i < n; i++)
	{
		v.pb(mp(pre[i] + suf[i], i));
	}
	sort(v.begin(), v.end());
	ll ans = 0;
	vector<ll>lg;
	vector<ll>rs;

	for (auto x : v)
	{
		ll temp = x.fi;
		sort(lg.begin(), lg.end());
		sort(rs.begin(), rs.end());

		auto it = lower_bound(rs.begin(), rs.end(), x.se);
		temp -= it - rs.begin();

		auto itt = lower_bound(lg.begin(), lg.end(), x.se);
		temp -= (lg.size() - (itt - lg.begin()));
		if (arr[x.se] == 0)
		{
			lg.pb(x.se);
		}
		if (arr[x.se] == 1)
		{
			rs.pb(x.se);
		}
		ans += temp;

	}

	cout << ans - 1 << endl;

}


#include <bits/stdc++.h>
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define pb push_back
#define pf push_front
using namespace std;
typedef pair<int, int> pi;
typedef pair<double, int> dpi;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int MAX = (int) 1e5 + 55;
const int INF = (int) 1e9 + 77;
const int MOD = (int) 1e9 + 7;
const double PI = 2 * acos(0.0);
const double EPS = 1e-7;

const int N = (int) 2e5 + 5;
bool a[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt" , "r" , stdin);
//	freopen("output.txt" , "w" , stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int ans = 0;
	int zero = 0;
	for (int i = n - 1; i >= 0; --i)
		zero += (a[i] == 0);
	for (int i = 0; i < n; ++i)
	{
		//cout << zero << '\n';
		zero -= (a[i] == 0);
		if (a[i])
			ans += zero;
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define pb push_back
#define pf push_front
using namespace std;
typedef pair<int, int> pi;
typedef pair<double, int> dpi;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pi> vpi;
const int MAX = (int) 1e5 + 55;
const int INF = (int) 1e9 + 77;
const int MOD = (int) 1e9 + 7;
const double PI = 2 * acos(0.0);
const double EPS = 1e-7;

const int N = (int) 2e5 + 5;
bool a[N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("input.txt" , "r" , stdin);
//	freopen("output.txt" , "w" , stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	ll ans = 0;
	int zero = 0;
	for (int i = n - 1; i >= 0; --i)
		zero += (a[i] == 0);
	for (int i = 0; i < n; ++i)
	{
		//cout << zero << '\n';
		zero -= (a[i] == 0);
		if (a[i])
			ans += zero;
	}
	cout << ans;
	return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <limits>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector<int> cnt(n + 1);
    cnt[n] = 0;
    for (int i = n - 1; i >= 0; --i) {
        cnt[i] = cnt[i + 1] + (v[i] == 0);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] == 1) {
            ans += cnt[i];
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <limits>
using namespace std;
int main() {
    long long n;
    cin >> n;
    vector<long long> v(n);
    for (long long i = 0; i < n; ++i) {
        cin >> v[i];
    }
    vector<long long> cnt(n + 1);
    cnt[n] = 0;
    for (long long i = n - 1; i >= 0; --i) {
        cnt[i] = cnt[i + 1] + (v[i] == 0);
    }
    long long ans = 0;
    for (long long i = 0; i < n; ++i) {
        if (v[i] == 1) {
            ans += cnt[i];
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
using namespace std;
#define rep(_m,s,e) for(ll _m=s;_m<e;_m++)
typedef long long ll;
typedef __int64 li;
int  toInt(string s)   {int r=0; istringstream sin(s); sin>>r; return r;}
ll   toInt64(string s) {ll r=0; istringstream sin(s); sin>>r; return r;}
double  toDouble(string s){double r=0; istringstream sin(s); sin>>r; return r;}
string toString(ll n) {string s,s1; while (n / 10 > 0){ s += (char)((n%10) + 48); n/=10;} s += (char)((n%10) + 48); n/=10; s1 = s; rep(i,0,s.length()) s1[(s.length()-1)-i] = s[i]; return s1;}
bool isUpperCase(char c){return c >= 'A' && c <= 'Z';}
bool isLowerCase(char c){return c >= 'a' && c <= 'z';}
bool isLetter(char c)   {return c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z';}
bool isDigit(char c)    {return c >= '0' && c <= '9';}
char toLowerCase(char c){return (isUpperCase(c))?(c + 32) : c;}
char toUpperCase(char c){return (isLowerCase(c))?(c - 32) : c;}
ll gcd(ll a, ll b) {if(!a) return b; return gcd(b%a, a);}
bool x[1000001];
ll tahdid[1000001];
ll sefr[1000001],yek[1000001];
int main()
{
	ios::sync_with_stdio(0);
	ll n;
	cin >> n;
	rep(i,0,n)
	{int a;	cin >> a; x[i] = (a==1?true:false);
		if (a == 1)
		{
			if (i == 0)
				yek[i] = 1;
			else yek[i] = yek[i-1] + 1;
		}
		else if (i != 0) yek[i] = yek[i-1];
	}
	for (int i = n-1; i >= 0; i--)
		if (!x[i])
			sefr[i] = sefr[i+1] + 1;
		else sefr[i] = sefr[i+1];
	ll minus = 0;
	ll count = 0;
	rep(i,0,n)
	{
		if (x[i])
		{
			minus += 1;
			count += sefr[i];
		}
	}
	ll Count = 0;
	for (int i = n-1; i >= 0; i--)
	{
		if (!x[i])
		{
			Count += yek[i];
		}
	}
	cout << min(count,Count) << endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define si size

const ll INF = 1e9 + 7, maxn = 2 * (1e5 + 7);
const double Pi = 3.1415926535;

ll n, m, i, j, k, t, l, r, ans, d[maxn];
bool b[maxn];

int main(){

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;
    for (i = 0; i < n; i++){
        cin >> b[i];
        if (!b[i])
            ans += r;
        else
            r++;
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
	int N;
	cin >> N;
	typedef vector<int> vi_t;
	vi_t cows(N, 0), right(N, 0);
	for (int i = 0; i < N; ++i)
	{
		cin >> cows[i];
		if (i)
		{
			right[i] = right[i - 1];
		}
		if (cows[i])
		{
			++right[i];
		}
	}
	vi_t left(N, 0);
	left.back() = 1 - cows.back();
	for (int j = N - 2; j >= 0; --j)
	{
		left[j] = left[j + 1];
		if (cows[j] == 0)
		{
			++left[j];
		}
	}
	long long res = 0;
	for (int c = 0; c < N; ++c)
	{
		if (cows[c])
		{
			res += left[c];
		}
		else
		{
			res += right[c];
		}
	}
	cout << res / 2 << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
	int N;
	cin >> N;
	typedef vector<int> vi_t;
	vi_t cows(N, 0), right(N + 2, 0);
	for (int i = 0; i < N; ++i)
	{
		cin >> cows[i];
		right[i + 1] = right[i];
		if (cows[i])
		{
			++right[i + 1];
		}
	}
	right.back() = right[N];
	vi_t left(N + 2, 0);
	for (int j = N - 1; j >= 0; --j)
	{
		left[j + 1] = left[j + 2];
		if (cows[j] == 0)
		{
			++left[j + 1];
		}
	}
	left[0] = left[1];
	int res = 0;
	for (int c = 0; c < N; ++c)
	{
		if (cows[c])
		{
			res += left[c + 1];
		}
		else
		{
			res += right[c + 1];
		}
	}
	cout << res / 2 << endl;
	return 0;
}


#include <iostream>

using namespace std;
int mas[200000];
int main()
{
	int ans = 0, ans2 = 0;
	int kol1 = 0, kol2 = 0;
	int t1 = 0, t2 = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
		if (mas[i] == 0)
			kol1++;
		else
			kol2++;
	}
	t1 = kol1;
	for (int i = 0; i < n; i++)
		if (mas[i] == 0)
			t1--;
		else ans += t1;
	t2 = kol2;
	for (int i = 0; i < n; i++)
		if (mas[i] == 1)
			t2--;
		else ans2 += t2;
	cout << min(ans, ans2);
	return 0;
}


#include <iostream>

using namespace std;
int mas[200000];
int main()
{
	int ans = 0, ans3 =  0, ans2 = 0, ans5 = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
		if (mas[i] == 0)
			ans++;
		else
			ans3++;
	}
	int ans4 = ans;
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 0)
			ans4--;
		else ans2+= ans4;
	}
	ans4 = ans3;
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 1)
			ans4--;
		else ans5+= ans4;
	}
	cout << min(ans2, ans5);
	return 0;
}


#include <iostream>

using namespace std;
int mas[200000];
int main()
{
	int ans = 0, ans3 =  0, ans2 = 0, ans5 = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
		if (mas[i] == 0)
			ans++;
		else
			ans3++;
	}
	int ans4 = ans;
	for (int i = 0; i < n; i++)
	{
		if (mas[i] == 0)
			ans4--;
		else ans2+= ans4;
	}
	ans4 = ans3;
	for (int i = n - 1; i >= 0; i--)
	{
		if (mas[i] == 1)
			ans4--;
		else ans5+= ans4;
	}
	cout << min(ans2, ans5);
	return 0;
}


#include <iostream>

using namespace std;
int mas[200000];
int main()
{
	long long int ans = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	int kol1 = 0, kol2 = 0;
	int t1 = 0, t2 = 0, t3 = 0, t4 = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> mas[i];
		if (mas[i] == 0)
			kol1++;
		else
			kol2++;
	}
	t1 = kol1;
	for (int i = 0; i < n; i++)
		if (mas[i] == 0)
			t1--;
		else ans += t1;

	t2 = 0;
	for (int i = 0; i < n; i++)
		if (mas[i] == 1)
			t2++;
		else ans2 += t2;

	t3 = 0;
	for (int i = n - 1; i >= 0; i--)
		if (mas[i] == 0)
			t3++;
		else ans3 += t3;

	t4 = kol2;
	for (int i = n - 1; i >= 0; i--)
		if (mas[i] == 1)
			t4--;
		else ans4 += t2;

	long long int d = min(ans, ans2);
	d = min(d, ans3);
	d = min(d, ans4);
	cout << d;
	return 0;
}


#include <iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;

	long long total = 0;
	int num_ones = 0;
	for (int i = 0; i < n; i++)
	{
		int num;
		cin >> num;
		if (num == 1)
			num_ones++;
		else
			total += num_ones;
	}

	cout << total << "\n";

	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>

int n;
bool a[200009];
int l, r;

void ReadData()
{
  scanf("%d", &n);
  for(int i = 0; i < n; i++)
  {
    int val;
    scanf("%d", &val);
    a[i] = val == 1;
    if(a[i])
    {
      r++;
    }
    else
    {
      l++;
    }
  }
}

__int64 answer;

void Solve()
{
  answer = 1LL << 62;
  __int64 c1 = 0, c2 = 0;
  int cl = l, cr = r;
  for(int i = 0; i < n; i++)
  {
    if(a[i])
    {
      c1 += l;
      r--;
    }
    else
    {
      l--;
    }
  }
  l = cl;
  r = cr;
  for(int i = n - 1; i >= 0; i--)
  {
    if(a[i] == false)
    {
      c2 += r;
      l--;
    }
    else
    {
      r--;
    }
  }
  answer = std::min(c1, c2);
}

void WriteData()
{
  printf("%I64d\n", answer);
}

int main()
{
  int QWE;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  scanf("%d", &QWE);
  #else
  QWE = 1;
  #endif
  for(int T = 0; T < QWE; T++)
  {
    ReadData();
    Solve();
    WriteData();
  }
  return 0;
}


#include <iostream>
using namespace std;
bool A[200002];
int main()
{
	int c,m,n,i,j,h,k=0,ma=-1,ma1,z=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]==0)
			z+=k;
		k+=A[i];
	}
	cout<<z;
	return 0;
}


#include <iostream>
using namespace std;
bool A[200002];
int main()
{
	long long c,m,n,i,j,h,k=0,ma=-1,ma1,z=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>A[i];
		if(A[i]==0)
			z+=k;
		k+=A[i];
	}
	cout<<z;
	return 0;
}


#include<iostream>
#include<string>
using namespace std;
int n,a[200200],b[200200],i,j;
long long sum;
int main()
{
	cin>>n;
	for(i=0;i<n;i++)
	cin>>a[i];

	int z=0;
	for(i=n-1;i>=0;i--)
	{
		if(a[i]==0)
			z++;
		b[i]=z;
	}
	for(i=0;i<n;i++)
	{
		if(a[i])
		{
			sum+=b[i];
		}
	}

	cout<<sum<<endl;
	return 0;
}

/*#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;

set<long long> B;
map <long long,long long> T,ti;
long long a,b,c,x,w,m,q,t,r,l,i,last;
int main()
{
	cin>>a>>b>>w>>x>>c;
	B.insert(b);
	ti[b]=0;
	t=0;
	while((!B.count(b) && t) || last>c)
	{
		t++;
		if(b>=x)
		{
			b-=x;
			B.insert(b);
			ti[b]=t;
		}
		else
		{
			b=w-x+b;
			B.insert(b);
			ti[b]=t;
			T[last]=t;
			last++;
		}
	}
	l=t-ti[b];
	if(a>=c)
		cout<<0;
	else
	{
		q=last+l;
		x=c-a;
		m=x/q;
		if(x%q)
		{
			r=x%q;
			t=0;
			i=0;
			while(r)
			{
				t++;
				r--;
				if(t==T[i])
				{
					r--;
					i++;
				}
			}
		}

		cout<<m*l+t<<endl;
	}
	return 0;
}

/*#include <iostream>
using namespace std;

int a[200][200],mx,z,q,w,i,j,b[200][200],ans,place[300],f,v,p;
int c(int x,int p)
{
	cout<<"c( "<<x<<", "<<p<<endl;
	if(b[x][p]!=-7777)
		return b[x][p];

	if(p==0)
	{
		place[x]=0;
		b[x][p]=a[x][0];
		return b[x][p];
	}
	mx=-6000;
	if(x==0)
	{
		for(j=0;j<=p;j++)
			if(a[x][j]>mx)
			{
				mx=a[x][j];
				ans=j;
			}

		b[x][p]=mx;
		place[x]=ans;
		return mx;
	}

	for(j=p;j>x-1;j--)
	{
		w=a[x][j];
		if(j==0)
			q=0;
		else
			q=c(x-1,j-1);
		if(mx<=w+q)
		{
			mx=w+q;
			ans=j;
		}
	}
	place[x]=ans;
	b[x][p]=mx;
	return mx;
}
int main()
{
	cin>>f>>v;
	for(i=0;i<f;i++)
	{		for(j=0;j<v;j++)
			{
				cin>>a[i][j];
				b[i][j]=-7777;
			}
	}
	z=c(f-1,v-1);
	cout<<z<<endl;
	for(i=0;i<f;i++)
		cout<<place[i]+1<<" ";

	return 0;
}*/


#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>

using namespace std;

//#define GEN_LOCAL_TEST
//#define USE_LOCAL_TEST

#ifdef GEN_LOCAL_TEST
void genTest() {
    ofstream ofs("test.txt", ifstream::out);
    int n = 100000;
    ofs << n << endl;
    for (int i = 0; i < n; ++i)
        ofs << 0 << " ";
    ofs << endl;
    ofs.close();
}
#endif

int main(int argc, char* argv[])
{
#ifdef GEN_LOCAL_TEST
    genTest();
#endif

    int n;
#ifdef USE_LOCAL_TEST
    ifstream ifs("test.txt", ifstream::in);
    ifs >> n;
#else
    cin >> n;
#endif

    int val;
    vector<int> dt;
    for (int i = 0; i < n; ++i) {
#ifdef USE_LOCAL_TEST
        ifs >> val;
#else
        cin >> val;
#endif
        dt.push_back(val);
    }

    int qt = 0;
    for (int i = 1; i < n; ++i) {
        if (dt[i] == 0) ++qt;
    }
    vector<int> qt1;
    for (int i = 0; i < n - 1; ++i) {
        qt1.push_back(qt);
        if (dt[i + 1] == 0) --qt;
    }
    qt1.push_back(0);

    qt = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (dt[i] == 1) ++qt;
    }
    vector<int> qt2(n, 0);
    for (int i = n - 1; i > 0; --i) {
        qt2[i] = qt;
        if (dt[i - 1] == 1) --qt;
    }

    int res1 = 0;
    int add = 0;
    for (int i = 0; i < n; ++i) {
        if (dt[i] != 1) continue;
        res1 += qt1[i];
        ++add;
        if (add >= qt2[n - 1])
            break;
    }
    int res2 = 0;
    add = 0;
    for (int i = n - 1; i >= 0; --i) {
        if (dt[i] != 0) continue;
        res2 += qt2[i];
        ++add;
        if (add >= qt1[0])
            break;
    }
    cout << min(res1, res2);
    return 0;
}


#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <set>
#include <algorithm>

using namespace std;

//#define GEN_LOCAL_TEST
//#define USE_LOCAL_TEST

#ifdef GEN_LOCAL_TEST
void genTest() {
    ofstream ofs("test.txt", ifstream::out);
    int n = 100000;
    ofs << n << endl;
    for (int i = 0; i < n; ++i)
        ofs << 0 << " ";
    ofs << endl;
    ofs.close();
}
#endif

int main(int argc, char* argv[])
{
#ifdef GEN_LOCAL_TEST
    genTest();
#endif

    int n;
#ifdef USE_LOCAL_TEST
    ifstream ifs("test.txt", ifstream::in);
    ifs >> n;
#else
    cin >> n;
#endif

    int val;
    vector<int> dt;
    for (int i = 0; i < n; ++i) {
#ifdef USE_LOCAL_TEST
        ifs >> val;
#else
        cin >> val;
#endif
        dt.push_back(val);
    }

    int qt = 0;
    for (int i = 1; i < n; ++i) {
        if (dt[i] == 0) ++qt;
    }
    vector<int> qt1;
    for (int i = 0; i < n - 1; ++i) {
        qt1.push_back(qt);
        if (dt[i + 1] == 0) --qt;
    }
    qt1.push_back(0);

    qt = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (dt[i] == 1) ++qt;
    }
    vector<int> qt2(n, 0);
    for (int i = n - 1; i > 0; --i) {
        qt2[i] = qt;
        if (dt[i - 1] == 1) --qt;
    }
    int idx1 = 0;
    while (idx1 < n && dt[idx1] != 1) ++idx1;
    if (idx1 == n) { cout << 0; return 0; }
    int idx2 = n - 1;
    while (idx2 >= 0 && dt[idx2] != 0) --idx2;
    if (idx2 < 0) { cout << 0; return 0; }

    int res = 0;
    int add1 = 0;
    int add2 = 0;
    while (idx1 < idx2) {
        if (qt1[idx1] >= qt2[idx2]) {
            res += max(qt1[idx1] - add1, 0);
            ++add2;
            ++idx1;
            while (idx1 < n && dt[idx1] != 1) ++idx1;
        } else {
            res += max(qt2[idx2] - add2, 0);
            ++add1;
            --idx2;
            while (idx2 >= 0 && dt[idx2] != 0) --idx2;
        }
    }
    cout << res;
    return 0;
}