#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define fi first
#define se second
using namespace std;

typedef pair<int, int> pii;
const int MAXN = 200000 + 10;
const int MAXV = 1000000 + 100;
const int MOD = 1e9 + 7;

vector<pii> ask[MAXN];
int n;
int a[MAXN], pre[MAXV];
int c[MAXN], fac[MAXN];
int ans[MAXN];

int pow_mod(int a, int b) {
    int res = 1;
    while(b) {
        if(b & 1)
            res = 1LL * res * a % MOD;
        a = 1LL * a * a % MOD;
        b >>= 1;
    }
    return res;
}

int inv(int x) {
    return pow_mod(x, MOD - 2);
}

inline int lowbit(int x){
    return x & -x;
}

void add(int x, int d) {
    if(!x){
        return ;
    }
    while(x <= n) {
        c[x] = 1LL * c[x] * d % MOD;
        x += lowbit(x);
    }
}

int query(int x) {
    int res = 1;
    while(x > 0) {
        res = 1LL * res * c[x] % MOD;
        x -= lowbit(x);
    }
    return res;
}

int main(int argc, char const *argv[]){
    //ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; i++){
        c[i] = 1;
    }
    fac[0] = 1;
    for(int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        fac[i] = 1LL * fac[i - 1] * a[i] % MOD;
    }
    int q;
    scanf("%d", &q);
    for(int i = 1; i <= q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        ask[r].push_back(pii(l, i));
    }
    for(int i = 1; i <= n; i++) {
        int tmp = a[i];
        for(int j = 2; j * j <= tmp; j++)
            if(!(tmp % j)) {
                do{
                    tmp /= j;
                }while(!(tmp % j));
                add(i, 1LL * (j - 1) * inv(j) % MOD);
                add(pre[j], inv(1LL * (j - 1) * inv(j) % MOD));
                pre[j] = i;
            }
        if(tmp != 1) {
            add(i, 1LL * (tmp - 1) * inv(tmp) % MOD);
            add(pre[tmp], inv(1LL * (tmp - 1) * inv(tmp) % MOD));
            pre[tmp]= i;
        }
        for(int j = 0; j < ask[i].size(); j++) {
            int t = ask[i][j].fi;
            ans[ask[i][j].se] = (((1LL * fac[i] * inv(fac[t- 1]) % MOD) * query(i) % MOD) * inv(query(t - 1))) % MOD;
        }
    }
    for(int i = 1; i <= q; i++){
        cout << ans[i] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
const int M = 1e6 + 5;

int pre[N], l, r, ans[N], h[M], hh[M], n, m, x, y, a[N], last[N << 2], add[M], del[M], t;
vector< pii > ST[N << 2], next[M];
pair< pii , int > q[M];
vector< int > v[M];
vector< int > c[N];

int down(int x) {
	int all = 1;
	vector< int > vv;
	while(x > 1) {
		int t = h[x];
		while(x % t == 0) x /= t;
		all *= t;
		vv.pb(t);
	}
	v[all] = vv;
	return all;
}

int FE(int x, int k) {
	if(!k) return 1;
	int temp = FE(x, k/2);
	if(k & 1) return (temp) * (ll) temp % mod * x % mod;
	return (ll) temp * temp % mod;
}

int divide(int x, int y) {
	return FE(y, mod-2) * (ll) x % mod;
}

void init(int k, int bas, int son) {
	if(bas == son) {
		foreach(it, next[bas]) ST[k].pb(*it);
		sort(ST[k].begin(), ST[k].end());
		ROF(i, (int)ST[k].size()-2, 0)
			ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
		return ;
	}
	init(sol, bas, orta);
	init(sag, orta+1, son);
	FOR(i, bas, son)
		foreach(it, next[i])
			if(it->st > son)
				ST[k].pb(*it);
	sort(ST[k].begin(), ST[k].end());
	ROF(i, (int)ST[k].size()-2, 0)
		ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
}

int query(int k, int bas, int son, int x, int y) {
	if(bas > y || son < x) return 1;
	if(x <= bas && son <= y) {
		while(last[k] < ST[k].size() && ST[k][last[k]].st <= y)	last[k]++;
		if(last[k] < ST[k].size()) return ST[k][last[k]].nd;
		return 1;
	}
	return query(sol, bas, orta, x, y) * (ll) query(sag, orta+1, son, x, y) % mod;
}

int main() {

	for(int i = 2; i < M; i++) {
		if(h[i]) continue;
		for(int j = i; j < M; j += i)
			if(!h[j])
				h[j] = i;
	}

	scanf("%d", &n);

	pre[0] = 1;

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		pre[i] = pre[i-1] * (ll) a[i] % mod;
		a[i] = down(a[i]);
	}

	FOR(i, 1, M-1) {
		add[i] = divide(i-1, i);
	}

	scanf("%d", &m);

	FOR(i, 1, n) {
		foreach(it, v[a[i]]) {
			c[i].pb(*it);
		}
	}

	FOR(i, 1, M-1) hh[i] = n + 1;

	ROF(i, n, 1) {
		FOR(j, 0, (int)c[i].size()-1) {
			next[i].pb(mp(hh[c[i][j]], add[c[i][j]]));
			hh[c[i][j]] = i;
		}
	}

	init(1, 1, n);

	FOR(i, 1, m) {
		scanf("%d %d", &l, &r);
		q[i] = mp(mp(r, l), i);
	}

	sort(q+1, q+m+1);

	FOR(i, 1, m) {
		ans[q[i].nd] = query(1, 1, n, q[i].st.nd, q[i].st.st) * (ll) divide(pre[q[i].st.st], pre[q[i].st.nd-1]) % mod;
	}

	FOR(i, 1, m) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
const int M = 1e6 + 5;

int pre[N], l, r, ans[N], h[M], hh[M], n, m, x, y, a[N], last[N << 2], add[M], del[M], t;
vector< pii > ST[N << 2], next[M];
pair< pii , int > q[M];
vector< int > v[M];
vector< int > c[N];

int down(int x) {
	int all = 1;
	vector< int > vv;
	while(x > 1) {
		int t = h[x];
		while(x % t == 0) x /= t;
		all *= t;
		vv.pb(t);
	}
	v[all] = vv;
	return all;
}

int FE(int x, int k) {
	if(!k) return 1;
	int temp = FE(x, k/2);
	if(k & 1) return (temp) * (ll) temp % mod * x % mod;
	return (ll) temp * temp % mod;
}

int divide(int x, int y) {
	return FE(y, mod-2) * (ll) x % mod;
}

void init(int k, int bas, int son) {
	if(bas == son) {
		foreach(it, next[bas]) ST[k].pb(*it);
		sort(ST[k].begin(), ST[k].end());
		ROF(i, (int)ST[k].size()-2, 0)
			ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
		return ;
	}
	init(sol, bas, orta);
	init(sag, orta+1, son);
	FOR(i, bas, son)
		foreach(it, next[i])
			if(it->st > son)
				ST[k].pb(*it);
	sort(ST[k].begin(), ST[k].end());
	ROF(i, (int)ST[k].size()-2, 0)
		ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
}

int query(int k, int bas, int son, int x, int y) {
	if(bas > y || son < x) return 1;
	if(x <= bas && son <= y) {
		while(last[k] < ST[k].size() && ST[k][last[k]].st <= y)	last[k]++;
		if(last[k] < ST[k].size()) return ST[k][last[k]].nd;
		return 1;
	}
	return query(sol, bas, orta, x, y) * (ll) query(sag, orta+1, son, x, y) % mod;
}

int main() {

	for(int i = 2; i < M; i++) {
		if(h[i]) continue;
		for(int j = i; j < M; j += i)
			if(!h[j])
				h[j] = i;
	}

	scanf("%d", &n);

	pre[0] = 1;

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		pre[i] = pre[i-1] * (ll) a[i] % mod;
		a[i] = down(a[i]);
	}

	FOR(i, 1, M-1) {
		add[a[i]] = divide(a[i]-1, a[i]);
	}

	scanf("%d", &m);

	FOR(i, 1, n) {
		foreach(it, v[a[i]]) {
			c[i].pb(*it);
		}
	}

	FOR(i, 1, M-1) hh[i] = n + 1;

	ROF(i, n, 1) {
		FOR(j, 0, (int)c[i].size()-1) {
			next[i].pb(mp(hh[c[i][j]], add[c[i][j]]));
			hh[c[i][j]] = i;
		}
	}

	init(1, 1, n);

	FOR(i, 1, m) {
		scanf("%d %d", &l, &r);
		q[i] = mp(mp(r, l), i);
	}

	sort(q+1, q+m+1);

	FOR(i, 1, m) {
		ans[q[i].nd] = query(1, 1, n, q[i].st.nd, q[i].st.st) * (ll) divide(pre[q[i].st.st], pre[q[i].st.nd-1]) % mod;
	}

	FOR(i, 1, m) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
const int M = 1e6 + 5;

int pre[N], l, r, ans[N], h[M], hh[M], n, m, x, y, a[N], last[N << 2], add[M], del[M], t;
vector< pii > ST[N << 2], next[M];
pair< pii , int > q[M];
vector< int > v[M];
vector< int > c[N];

int down(int x) {
	int all = 1;
	vector< int > vv;
	while(x > 1) {
		int t = h[x];
		while(x % t == 0) x /= t;
		all *= t;
		vv.pb(t);
	}
	v[all] = vv;
	return all;
}

int FE(int x, int k) {
	if(!k) return 1;
	int temp = FE(x, k/2);
	if(k & 1) return (temp) * (ll) temp % mod * x % mod;
	return (ll) temp * temp % mod;
}

int divide(int x, int y) {
	return FE(y, mod-2) * (ll) x % mod;
}

void init(int k, int bas, int son) {
	if(bas == son) {
		foreach(it, next[bas]) ST[k].pb(*it);
		sort(ST[k].begin(), ST[k].end());
		ROF(i, (int)ST[k].size()-2, 0)
			ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
		return ;
	}
	init(sol, bas, orta);
	init(sag, orta+1, son);
	FOR(i, bas, son)
		foreach(it, next[i])
			ST[k].pb(*it);
	sort(ST[k].begin(), ST[k].end());
	ROF(i, (int)ST[k].size()-2, 0)
		ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
}

int query(int k, int bas, int son, int x, int y) {
	if(bas > y || son < x) return 1;
	if(x <= bas && son <= y) {
		while(last[k] < ST[k].size() && ST[k][last[k]].st <= y)	last[k]++;
		if(last[k] < ST[k].size()) return ST[k][last[k]].nd;
		return 1;
	}
	return query(sol, bas, orta, x, y) * (ll) query(sag, orta+1, son, x, y) % mod;
}

int main() {

	for(int i = M-1; i >= 2; i--)
		for(int j = i; j < M; j += i)
			h[j] = i;

	scanf("%d", &n);

	pre[0] = 1;

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		pre[i] = pre[i-1] * (ll) a[i] % mod;
		a[i] = down(a[i]);
	}

	FOR(i, 1, M-1) {
		add[i] = divide(i-1, i);
	}

	scanf("%d", &m);

	FOR(i, 1, n) {
		foreach(it, v[a[i]]) {
			c[i].pb(*it);
		}
	}

	FOR(i, 1, M-1) hh[i] = n + 1;

	ROF(i, n, 1) {
		FOR(j, 0, (int)c[i].size()-1) {
			next[i].pb(mp(hh[c[i][j]], add[c[i][j]]));
			hh[c[i][j]] = i;
		}
	}

	init(1, 1, n);

	FOR(i, 1, m) {
		scanf("%d %d", &l, &r);
		q[i] = mp(mp(r, l), i);
	}

	sort(q+1, q+m+1);

	FOR(i, 1, m) {
		ans[q[i].nd] = query(1, 1, n, q[i].st.nd, q[i].st.st) * (ll) divide(pre[q[i].st.st], pre[q[i].st.nd-1]) % mod;
	}

	FOR(i, 1, m) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define dbgs(x) cerr << (#x) << " --> " << (x) << ' '
#define dbg(x) cerr << (#x) << " --> " << (x) << endl

#define foreach(i,x) for(type(x)i=x.begin();i!=x.end();i++)
#define FOR(ii,aa,bb) for(int ii=aa;ii<=bb;ii++)
#define ROF(ii,aa,bb) for(int ii=aa;ii>=bb;ii--)

#define type(x) __typeof(x.begin())

#define orta (bas + son >> 1)
#define sag (k + k + 1)
#define sol (k + k)

#define pb push_back
#define mp make_pair

#define nd second
#define st first

#define endl '\n'

typedef pair < int ,int > pii;

typedef long long ll;

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int logN = 17;
const int inf = 1e9;
const int N = 2e5 + 5;
const int M = 1e6 + 5;

int pre[N], l, r, ans[N], h[M], hh[M], n, m, x, y, a[N], last[N << 2], add[M], del[M], t;
vector< pii > ST[N << 2], next[M];
pair< pii , int > q[M];
vector< int > v[M];
vector< int > c[N];

int down(int x) {
	int all = 1;
	vector< int > vv;
	while(x > 1) {
		int t = h[x];
		while(x % t == 0) x /= t;
		all *= t;
		vv.pb(t);
	}
	v[all] = vv;
	return all;
}

int FE(int x, int k) {
	if(!k) return 1;
	int temp = FE(x, k/2);
	if(k & 1) return (temp) * (ll) temp % mod * x % mod;
	return (ll) temp * temp % mod;
}

int divide(int x, int y) {
	return FE(y, mod-2) * (ll) x % mod;
}

void init(int k, int bas, int son) {
	if(bas == son) {
		foreach(it, next[bas]) ST[k].pb(*it);
		sort(ST[k].begin(), ST[k].end());
		ROF(i, (int)ST[k].size()-2, 0)
			ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
		return ;
	}
	init(sol, bas, orta);
	init(sag, orta+1, son);
	FOR(i, bas, son)
		foreach(it, next[i])
			if(it->st > son)
				ST[k].pb(*it);
	sort(ST[k].begin(), ST[k].end());
	ROF(i, (int)ST[k].size()-2, 0)
		ST[k][i].nd = ST[k][i+1].nd * (ll) ST[k][i].nd % mod;
}

int query(int k, int bas, int son, int x, int y) {
	if(bas > y || son < x) return 1;
	if(x <= bas && son <= y) {
		while(last[k] < ST[k].size() && ST[k][last[k]].st <= y)	last[k]++;
		if(last[k] < ST[k].size()) return ST[k][last[k]].nd;
		return 1;
	}
	return query(sol, bas, orta, x, y) * (ll) query(sag, orta+1, son, x, y) % mod;
}

int main() {

	for(int i = 2; i < M; i++) {
		if(h[i]) continue;
		for(int j = i; j < M; j += i)
			if(!h[j])
				h[j] = i;
	}

	scanf("%d", &n);

	pre[0] = 1;

	FOR(i, 1, n) {
		scanf("%d", &a[i]);
		pre[i] = pre[i-1] * (ll) a[i] % mod;
		a[i] = down(a[i]);
		add[a[i]] = divide(a[i]-1, a[i]);
	}

	scanf("%d", &m);

	FOR(i, 1, n) {
		foreach(it, v[a[i]]) {
			c[i].pb(*it);
		}
	}

	FOR(i, 1, M-1) hh[i] = n + 1;

	ROF(i, n, 1) {
		FOR(j, 0, (int)c[i].size()-1) {
			next[i].pb(mp(hh[c[i][j]], add[c[i][j]]));
			hh[c[i][j]] = i;
		}
	}

	init(1, 1, n);

	FOR(i, 1, m) {
		scanf("%d %d", &l, &r);
		q[i] = mp(mp(r, l), i);
	}

	sort(q+1, q+m+1);

	FOR(i, 1, m) {
		ans[q[i].nd] = query(1, 1, n, q[i].st.nd, q[i].st.st) * (ll) divide(pre[q[i].st.st], pre[q[i].st.nd-1]) % mod;
	}

	FOR(i, 1, m) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}

template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}

#define ll           long long
#define ld           long double
#define int          long long
#define f            first
#define s            second
#define boost        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cerr.tie(0);
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define pb           push_back
#define vi           vector<int>
#define vvi          vector<vi>
#define vll          vector<ll>
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define all(x)       x.begin(),x.end()
#define sz(x)        (int)x.size()
//#define mp           make_pair
//#define M            998244353
//#define N            10000005
#define mod          1000000007

const int N = 81;
int dp[81][81][81*81];
int n,o,z;
vector<int> v(N, -1);

int cal(int left, int placed, int ind, int mv, int k){
    if(ind==o){
        if(mv<=k) return left*placed;
        else return -INT_MIN;
    }
    if(dp[left][ind][mv]!=-1) return dp[left][ind][mv];
    int ans = 0;
    for(int i=0; i<left+1; i++){
        ans = max(ans, i*placed + cal(left-i, placed+i, ind+1, mv + abs(placed + i + ind - v[ind]), k));
    }
    dp[left][ind][mv] = ans;
    return ans;
}

void solve(){

    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x){
            v[o]=i;
            o++;
        }
        else z++;
    }
    rep(k,0,n*(n-1)/2+1){
        rep(i,0,n) rep(j,0,k) rep(l,0,n) dp[i][l][j]=-1;
        cout<<cal(z, 0, 0, 0, k)<<" ";
    }
}

signed main()
{
    boost;
    int t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}

template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}

#define ll           long long
#define ld           long double
#define int          long long
#define f            first
#define s            second
#define boost        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cerr.tie(0);
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define pb           push_back
#define vi           vector<int>
#define vvi          vector<vi>
#define vll          vector<ll>
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define all(x)       x.begin(),x.end()
#define sz(x)        (int)x.size()
//#define mp           make_pair
//#define M            998244353
//#define N            10000005
#define mod          1000000007

const int N = 81;
int dp[81][81][81*81];
int n,o,z;
vector<int> v(N, -1);

int cal(int left, int placed, int ind, int mv, int k){
    if(ind==o){
        if(mv<=k) return left*placed;
        else return -INT_MIN;
    }
    if(dp[left][ind][mv]!=-1) return dp[left][ind][mv];
    int ans = 0;
    for(int i=0; i<left+1; i++){
        ans = max(ans, i*placed + cal(left-i, placed+i, ind+1, mv + abs(placed + i + ind - v[ind]), k));
    }
    dp[left][ind][mv] = ans;
    return ans;
}

void solve(){

    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x){
            v[o]=i;
            o++;
        }
        else z++;
    }
    rep(k,0,n*(n-1)/2+1){
        rep(i,0,n+1) rep(j,0,k+1) rep(l,0,n+1) dp[i][l][j]=-1;
        cout<<cal(z, 0, 0, 0, k)<<" ";
    }
}

signed main()
{
    boost;
    int t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}

template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}

#define ll           long long
#define ld           long double
#define int          long long
#define f            first
#define s            second
#define boost        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cerr.tie(0);
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define pb           push_back
#define vi           vector<int>
#define vvi          vector<vi>
#define vll          vector<ll>
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define all(x)       x.begin(),x.end()
#define sz(x)        (int)x.size()
//#define mp           make_pair
//#define M            998244353
//#define N            10000005
#define mod          1000000007

const int N = 82;
int dp[82][82][82*82];
int n,o,z;
vector<int> v(N, -1);

int cal(int left, int placed, int ind, int mv, int k){
    if(ind==o){
        if(mv<=k) return left*placed;
        else return -INT_MIN;
    }
    if(dp[left][ind][mv]!=-1) return dp[left][ind][mv];
    int ans = 0;
    for(int i=0; i<left+1; i++){
        ans = max(ans, i*placed + cal(left-i, placed+i, ind+1, mv + abs(placed + i + ind - v[ind]), k));
    }
    dp[left][ind][mv] = ans;
    return ans;
}

void solve(){

    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x){
            v[o]=i;
            o++;
        }
        else z++;
    }
    v[o]=n;
    o++;
    rep(i,0,n+1) rep(j,0,n+1) rep(k,0,n*(n-1)/2+1) dp[i][j][k]=INT_MAX;
    dp[0][0][0]=0;
    rep(i,0,o){
        rep(j,0,z+1){
            rep(k,0,n*(n-1)/2+1){
                if(dp[i][j][k]==INT_MAX) continue;
                rep(l,j,z+1)
                    dp[i+1][l][k+abs(i+l-v[i])] = min(dp[i+1][l][k+abs(i+l-v[i])], dp[i][j][k]+(l-j)*(l-j));
            }
        }
    }
    int mn = INT_MAX;
    rep(k,0,n*(n-1)/2+1){
        mn = min(mn, dp[o][z][k]);
        cout<<(z*z-mn)/2<<" ";
    }
}

signed main()
{
    boost;
    int t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<class T1,class T2>
ostream& operator << (ostream& out,pair<T1,T2> p)
{
	out<<p.first<<' '<<p.second;
	return out;
}

template<class T1,class T2>
istream& operator >> (istream& in,pair<T1,T2> &p)
{
	in>>p.first>>p.second;
	return in;
}

template<class T>
istream& operator >> (istream& in,vector<T> &v)
{
	for(auto &x:v)
		in>>x;
	return in;
}

template<class T>
ostream& operator << (ostream& out,vector<vector<T>> &v)
{
	for(auto &x:v)
		out<<x<<'\n';
	return out;
}

template<class T>
ostream& operator << (ostream& out,vector<T> &v)
{
	for(auto x:v)
		out<<x<<' ';
	return out;
}

#define ll           long long
#define ld           long double
#define int          long long
#define f            first
#define s            second
#define boost        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cerr.tie(0);
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define pb           push_back
#define vi           vector<int>
#define vvi          vector<vi>
#define vll          vector<ll>
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define all(x)       x.begin(),x.end()
#define sz(x)        (int)x.size()
//#define mp           make_pair
//#define M            998244353
//#define N            10000005
#define mod          1000000007

const int N = 82;
int dp[82][82][82*82];
int n,o,z;
vector<int> v(N, -1);

int cal(int left, int placed, int ind, int mv, int k){
    if(ind==o){
        if(mv<=k) return left*placed;
        else return -INT_MIN;
    }
    if(dp[left][ind][mv]!=-1) return dp[left][ind][mv];
    int ans = 0;
    for(int i=0; i<left+1; i++){
        ans = max(ans, i*placed + cal(left-i, placed+i, ind+1, mv + abs(placed + i + ind - v[ind]), k));
    }
    dp[left][ind][mv] = ans;
    return ans;
}

void solve(){

    cin>>n;
    rep(i,0,n){
        int x;
        cin>>x;
        if(x){
            v[o]=i;
            o++;
        }
        else z++;
    }
    v[o]=n;
    o++;
    rep(i,0,n+1) rep(j,0,n+1) rep(k,0,n*(n-1)/2+1) dp[i][j][k]=-1;
    dp[0][0][0]=0;
    rep(i,0,o){
        rep(j,0,z+1){
            rep(k,0,n*(n-1)/2+1){
                if(dp[i][j][k]==-1) continue;
                rep(l,j,z+1)
                    dp[i+1][l][k+abs(i+l-v[i])] = max(dp[i+1][l][k+abs(i+l-v[i])], dp[i][j][k]+(l-j)*j);
            }
        }
    }
    int mn = INT_MIN;
    rep(k,0,n*(n-1)/2+1){
        mn = max(mn, dp[o][z][k]);
        cout<<mn<<" ";
    }
}

signed main()
{
    boost;
    int t;
    t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx > f[1])
		return -2e18;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	for(int i = 1; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		int nidx = idx;
		if(idx + 1 <= f[1])
		{
			nidx++;
			subtract += abs(curidx + i - init[1][idx + 1]);
		}
		ans = max(ans, i * sum + dp(nidx, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << " ";
	return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx > f[1])
		return -2e18;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	int lo = 1;
	if(idx == f[1])
		return lo = rem;
	for(int i = lo; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		int nidx = idx;
		if(idx + 1 <= f[1])
		{
			nidx++;
			subtract += abs(curidx + i - init[1][idx + 1]);
		}
		ans = max(ans, i * sum + dp(nidx, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << endl;
	return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][6400];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx > f[1])
		return -2e18;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	int lo = 1;
	if(idx == f[1])
		lo = rem;
	for(int i = lo; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		int nidx = idx;
		if(idx + 1 <= f[1])
		{
			nidx++;
			subtract += abs(curidx + i - init[1][idx + 1]);
		}
		ans = max(ans, i * sum + dp(nidx, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << " ";
	return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx == f[1])
		return (f[0] - sum) * sum;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	for(int i = 1; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		subtract += abs(curidx + i - init[1][idx + 1]);
		ans = max(ans, i * sum + dp(idx + 1, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << endl;
	return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][6400];
int cache2[N][N][N];

int get(int idx, int k, int cur)
{
	if(k == 0)
		return 0;
	int &ans = cache2[idx][k][cur];
	if(ans != -1)
		return ans;
	ans = abs(idx - init[0][cur]) + get(idx + 1, k - 1, cur + 1);
	return ans;
}

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx > f[1])
		return -2e18;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	int lo = 1;
	if(idx == f[1])
		lo = rem;
	for(int i = lo; i <= rem; i++)
	{
		// int subtract = 0;
		// for(int j = curidx; j <= curidx + i - 1; j++)
		// 	subtract += abs(j - init[0][sum + j + 1 - curidx]);
		int subtract = get(curidx, i, sum + 1);
		int nidx = idx;
		if(idx + 1 <= f[1])
		{
			nidx++;
			subtract += abs(curidx + i - init[1][idx + 1]);
		}
		ans = max(ans, i * sum + dp(nidx, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	memset(cache2, -1, sizeof(cache2));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << " ";
	return 0;
}


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

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

const int N = 81;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -1e9;
	if(idx == f[1])
		return (f[0] - sum) * sum;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	for(int i = 1; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		subtract += abs(curidx + i - init[1][idx + 1]);
		ans = max(ans, i * sum + dp(idx + 1, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << endl;
	return 0;
}


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

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

const int N = 81;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -1e9;
	if(idx > f[1])
		return -1e9;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	for(int i = 1; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		ans = max(ans, i * sum + dp(idx + 1, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << endl;
	return 0;
}


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

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

const int N = 82;

int n;
int a[N], f[N], init[2][N];
int cache[N][N][3200];

int dp(int idx, int sum, int k)
{
	if(k < 0)
		return -2e18;
	if(idx > f[1])
		return -2e18;
	int curidx = idx + sum + 1;
	if(curidx > n)
		return 0;
	int &ans = cache[idx][sum][k];
	if(ans != -1)
		return ans;
	ans = -2e18;
	ans = max(ans, dp(idx + 1, sum, k - abs(curidx - init[1][idx + 1])));
	int rem = f[0] - sum;
	int lo = 1;
	if(idx == f[1])
		lo = rem;
	for(int i = lo; i <= rem; i++)
	{
		int subtract = 0;
		for(int j = curidx; j <= curidx + i - 1; j++)
			subtract += abs(j - init[0][sum + j + 1 - curidx]);
		int nidx = idx;
		if(idx + 1 <= f[1])
		{
			nidx++;
			subtract += abs(curidx + i - init[1][idx + 1]);
		}
		ans = max(ans, i * sum + dp(nidx, sum + i, k - subtract));
	}
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		f[a[i]]++;
		init[a[i]][f[a[i]]] = i;
	}
	if(!f[0] || !f[1])
	{
		for(int k = 0; k <= n * (n - 1) / 2; k++)
			cout << 0 << " ";
		cout << endl;
		return 0;
	}
	for(int k = 0; k <= n * (n - 1) / 2; k++)
		cout << dp(0, 0, 2 * k) << " ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct line
{
    ll k,n;
    mutable ll r;
    line(ll a,ll b){k=a;n=b;r=0;}
    bool operator<(const line &o)const{return (k>o.k);}
    bool operator<(const ll &o)const{return (r<o);}
};

struct cht
{
    set<line,less<>> s;
    const ll inf=(1ll<<60);
    double intersect(line a,line b) {return ((double)b.n-a.n)/(a.k-b.k);}
    void add(ll k,ll n)
    {
        line now(k,n);
        auto it=s.lower_bound(now);
        if(it!=s.end()&&it->k==k)
        {
            if(n<it->n) it=s.erase(it);
            else return;
        }
        if(it!=s.end()&&it!=s.begin()&&intersect(now,*prev(it))>intersect(now,*it)) return;
        s.insert(now);
        while(it!=s.end()&&next(it)!=s.end()&&intersect(now,*it)>intersect(*it,*next(it))) it=s.erase(it);
        it--;
        while(it!=s.begin()&&prev(it)!=s.begin()&&intersect(now,*prev(it))<intersect(*prev(it),*prev(prev(it)))) s.erase(prev(it));
        if(it!=s.begin()) prev(it)->r=floor(intersect(now,*prev(it)));
        if(next(it)!=s.end()) it->r=floor(intersect(now,*next(it)));
        else it->r=inf;
    }
    ll query(ll a)
    {
        line best=*s.lower_bound(a);
        return (best.k*a+best.n);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int cnt=0;
    vector<int> pos(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        cnt+=a[i];
        if(a[i]==1) pos[cnt]=i;
    }
    int zero=n-cnt;
    int pairs=n*(n-1)/2;
    if(cnt==0)
    {
        for(int i=0;i<=pairs;i++) cout << "0" << " \n"[i==pairs];
        return 0;
    }
    int dp[n+1][cnt+1][pairs+1];
    cht best[cnt+1][pairs+1];
    for(int i=0;i<=pairs;i++) best[0][i].add(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=cnt;c++)
        {
            int d=abs(pos[c]-i);
            for(int mv=d;mv<=pairs;mv++)
            {
                dp[i][c][mv]=(i-1)*(i-1)+best[c-1][mv-d].query(i);
                best[c][mv].add(-2*i,i*i+2*i+dp[i][c][mv]);
            }
        }
    }
    vector<int> res(pairs+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int mv=0;mv<=pairs;mv++)
        {
            if(abs(pos[cnt]-i)>mv) continue;
            res[mv]=max(res[mv],zero*(zero-1)/2+(zero-dp[i][cnt][mv]-(n-i)*(n-i))/2);
        }
    }
    for(int i=0;i<=pairs;i++) cout << res[i] << " \n"[i==pairs];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct cht
{
    deque<array<int,2>> d;
    double intersect(array<int,2> a,array<int,2> b) {return ((double)b[1]-a[1])/(a[0]-b[0]);}
    void add(int k,int n)
    {
        array<int,2> a={k,n};
        while(d.size()>=2&&intersect(d[d.size()-2],d.back())>intersect(d.back(),a)) d.pop_back();
        d.push_back(a);
    }
    int eval(array<int,2> a,int b) {return (a[0]*b+a[1]);}
    int query(int a)
    {
        while(d.size()>=2&&eval(d[0],a)>=eval(d[1],a)) d.pop_front();
        return eval(d[0],a);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int cnt=0;
    vector<int> pos(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        cnt+=a[i];
        if(a[i]==1) pos[cnt]=i;
    }
    int zero=n-cnt;
    int pairs=n*(n-1)/2;
    if(cnt==0)
    {
        for(int i=0;i<=pairs;i++) cout << "0" << " \n"[i==pairs];
        return 0;
    }
    int dp[n+1][cnt+1][pairs+1];
    cht best[cnt+1][pairs+1];
    for(int i=0;i<=pairs;i++) best[0][i].add(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=cnt;c++)
        {
            int d=abs(pos[c]-i);
            for(int mv=d;mv<=pairs;mv++)
            {
                dp[i][c][mv]=(i-1)*(i-1)+best[c-1][mv-d].query(i);
                best[c][mv].add(-2*i,i*i+2*i+dp[i][c][mv]);
            }
        }
    }
    vector<int> res(pairs+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int mv=0;mv<=pairs;mv++)
        {
            if(abs(pos[cnt]-i)>mv) continue;
            res[mv]=max(res[mv],zero*(zero-1)/2+(zero-dp[i][cnt][mv]-(n-i)*(n-i))/2);
        }
    }
    for(int i=0;i<=pairs;i++) cout << res[i] << " \n"[i==pairs];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct cht
{
    deque<array<int,2>> d;
    bool rm(array<int,2> a,array<int,2> b,array<int,2> c) {return (b[1]-a[1])*(b[0]-c[0])>(c[1]-b[1])*(a[0]-b[0]);}
    void add(int k,int n)
    {
        array<int,2> a={k,n};
        while(d.size()>=2&&rm(d[d.size()-2],d.back(),a)) d.pop_back();
        d.push_back(a);
    }
    int eval(array<int,2> a,int b) {return (a[0]*b+a[1]);}
    int query(int a)
    {
        while(d.size()>=2&&eval(d[0],a)>=eval(d[1],a)) d.pop_front();
        return eval(d[0],a);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int cnt=0;
    vector<int> pos(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        cnt+=a[i];
        if(a[i]==1) pos[cnt]=i;
    }
    int zero=n-cnt;
    int pairs=n*(n-1)/2;
    if(cnt==0)
    {
        for(int i=0;i<=pairs;i++) cout << "0" << " \n"[i==pairs];
        return 0;
    }
    int dp[n+1][cnt+1][pairs+1];
    cht best[cnt+1][pairs+1];
    for(int i=0;i<=pairs;i++) best[0][i].add(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=cnt;c++)
        {
            int d=abs(pos[c]-i);
            for(int mv=d;mv<=pairs;mv++)
            {
                dp[i][c][mv]=(i-1)*(i-1)+best[c-1][mv-d].query(i);
                best[c][mv].add(-2*i,i*i+2*i+dp[i][c][mv]);
            }
        }
    }
    vector<int> res(pairs+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int mv=0;mv<=pairs;mv++)
        {
            if(abs(pos[cnt]-i)>mv) continue;
            res[mv]=max(res[mv],zero*(zero-1)/2+(zero-dp[i][cnt][mv]-(n-i)*(n-i))/2);
        }
    }
    for(int i=0;i<=pairs;i++) cout << res[i] << " \n"[i==pairs];
    return 0;
}


#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")

using namespace std;
typedef long long ll;

struct line
{
    int k,n;
    mutable int r;
    line(int a,int b){k=a;n=b;r=0;}
    bool operator<(const line &o)const{return (k>o.k);}
    bool operator<(const int &o)const{return (r<o);}
};

struct cht
{
    set<line,less<>> s;
    const int inf=(1<<30);
    double intersect(line a,line b) {return ((double)b.n-a.n)/(a.k-b.k);}
    void add(int k,int n)
    {
        line now(k,n);
        auto it=s.lower_bound(now);
        if(it!=s.end()&&it->k==k)
        {
            if(n<it->n) it=s.erase(it);
            else return;
        }
        if(it!=s.end()&&it!=s.begin()&&intersect(now,*prev(it))>intersect(now,*it)) return;
        s.insert(now);
        while(it!=s.end()&&next(it)!=s.end()&&intersect(now,*it)>intersect(*it,*next(it))) it=s.erase(it);
        it--;
        while(it!=s.begin()&&prev(it)!=s.begin()&&intersect(now,*prev(it))<intersect(*prev(it),*prev(prev(it)))) s.erase(prev(it));
        if(it!=s.begin()) prev(it)->r=floor(intersect(now,*prev(it)));
        if(next(it)!=s.end()) it->r=floor(intersect(now,*next(it)));
        else it->r=inf;
    }
    int query(int a)
    {
        line best=*s.lower_bound(a);
        return (best.k*a+best.n);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int cnt=0;
    vector<int> pos(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        cnt+=a[i];
        if(a[i]==1) pos[cnt]=i;
    }
    int zero=n-cnt;
    int pairs=n*(n-1)/2;
    if(cnt==0)
    {
        for(int i=0;i<=pairs;i++) cout << "0" << " \n"[i==pairs];
        return 0;
    }
    int dp[n+1][cnt+1][pairs+1];
    cht best[cnt+1][pairs+1];
    for(int i=0;i<=pairs;i++) best[0][i].add(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=cnt;c++)
        {
            int d=abs(pos[c]-i);
            for(int mv=d;mv<=pairs;mv++)
            {
                dp[i][c][mv]=(i-1)*(i-1)+best[c-1][mv-d].query(i);
                best[c][mv].add(-2*i,i*i+2*i+dp[i][c][mv]);
            }
        }
    }
    vector<int> res(pairs+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int mv=0;mv<=pairs;mv++)
        {
            if(abs(pos[cnt]-i)>mv) continue;
            res[mv]=max(res[mv],zero*(zero-1)/2+(zero-dp[i][cnt][mv]-(n-i)*(n-i))/2);
        }
    }
    for(int i=0;i<=pairs;i++) cout << res[i] << " \n"[i==pairs];
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

struct line
{
    ll k,n;
    mutable ll r;
    line(ll a,ll b){k=a;n=b;r=0;}
    bool operator<(const line &o)const{return (k>o.k);}
    bool operator<(const ll &o)const{return (r<o);}
};

struct cht
{
    set<line,less<>> s;
    const ll inf=(1ll<<60);
    double intersect(line a,line b) {return ((double)b.n-a.n)/(a.k-b.k);}
    void add(ll k,ll n)
    {
        line now(k,n);
        auto it=s.lower_bound(now);
        if(it!=s.end()&&it->k==k)
        {
            if(n<it->n) it=s.erase(it);
            else return;
        }
        if(it!=s.end()&&it!=s.begin()&&intersect(now,*prev(it))>intersect(now,*it)) return;
        s.insert(now);
        while(it!=s.end()&&next(it)!=s.end()&&intersect(now,*it)>intersect(*it,*next(it))) it=s.erase(it);
        it--;
        while(it!=s.begin()&&prev(it)!=s.begin()&&intersect(now,*prev(it))<intersect(*prev(it),*prev(prev(it)))) s.erase(prev(it));
        if(it!=s.begin()) prev(it)->r=floor(intersect(now,*prev(it)));
        if(next(it)!=s.end()) it->r=floor(intersect(now,*next(it)));
        else it->r=inf;
    }
    ll query(ll a)
    {
        line best=*s.lower_bound(a);
        return (best.k*a+best.n);
    }
};

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n+1,0);
    int cnt=0;
    vector<int> pos(n+1,0);
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        cnt+=a[i];
        if(a[i]==1) pos[cnt]=i;
    }
    int zero=n-cnt;
    int pairs=n*(n-1)/2;
    if(cnt==0)
    {
        for(int i=0;i<=pairs;i++) cout << "0" << " \n"[i==pairs];
        return 0;
    }
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(cnt+1,vector<int>(pairs+1,0)));
    vector<vector<cht>> best(cnt+1,vector<cht>(pairs+1));
    for(int i=0;i<=pairs;i++) best[0][i].add(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int c=1;c<=cnt;c++)
        {
            int d=abs(pos[c]-i);
            for(int mv=d;mv<=pairs;mv++)
            {
                dp[i][c][mv]=(i-1)*(i-1)+best[c-1][mv-d].query(i);
                best[c][mv].add(-2*i,i*i+2*i+dp[i][c][mv]);
            }
        }
    }
    vector<int> res(pairs+1,0);
    for(int i=1;i<=n;i++)
    {
        for(int mv=0;mv<=pairs;mv++)
        {
            if(abs(pos[cnt]-i)>mv) continue;
            res[mv]=max(res[mv],zero*(zero-1)/2+(zero-dp[i][cnt][mv]-(n-i)*(n-i))/2);
        }
    }
    for(int i=0;i<=pairs;i++) cout << res[i] << " \n"[i==pairs];
    return 0;
}


//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug_prettyprint.hpp>
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = max(lhs, rhs.val); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = min(lhs, rhs.val); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

short dp2[83][45][83][785]={{{{0}}}};

signed main() {
    FASTIO

    int n; cin>>n;
    vi a = READ<int>(n);
    vi shields;
    int scnt=0;
    FOR(i,n)
        if(a[i]==1) {
            shields.push_back(i);
            scnt++;
        }

    memset(dp2, 0x80, sizeof dp2);
    dp2[0][0][0][0]=0;

    FOR(i,n) {
        auto dpo = dp2[i];
        auto dpn = dp2[i+1];

        int placeable = n-1-i+1;
        int mhp = max(scnt-placeable, 0);
        int chp = min(i,scnt);

        int nxtPlaceable = n-1-(i+1)+1;
        int nxtMhp = max(scnt-nxtPlaceable, 0);

        RNG(stl,mhp,chp) {
            int stloff = stl-mhp;
            int nxtStloff = stl-nxtMhp;

            RNG(ls,-1,i-1) {
                if(ls>=0 && stl==0 || stl>ls+1)
                    continue;

                FOR(op, 781) {
                    if(stl < scnt) {
                        int nop = abs(shields[stl]-i) + op;
                        if(nop <= 781)
                            dpn[nxtStloff+1][i+1][nop] |= MAX( dpo[stloff][ls+1][op] );
                    }

                    short lemmLLS = ls<0 ? 0 : ls-stl+1;
                    dpn[nxtStloff][ls+1][op] |= MAX( (short)(dpo[stloff][ls+1][op] + lemmLLS) );
                }
            }
        }
    }

    short best=0;
    FOR(op,n*(n-1)/2+1) {
        RNG(ls,-1,n-1) {
            int i=n;
            int placeable = n-1-i+1;
            int mhp = max(scnt-placeable, 0);
            int stloff = scnt-mhp;

            best |= MAX( dp2[n][stloff][ls+1][op] );
        }
        cout<<best<<' ';
    }
}


//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug_prettyprint.hpp>
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = max(lhs, rhs.val); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = min(lhs, rhs.val); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

int dp2[85][85][85][800]={{{{0}}}};

signed main() {
    FASTIO

    int n; cin>>n;
    vi a = READ<int>(n);
    vi shields;
    int scnt=0;
    FOR(i,n)
    if(a[i]==1) {
        shields.push_back(i);
        scnt++;
    }

    memset(dp2, 0x80, sizeof dp2);
    dp2[0][0][0][0]=0;

    FOR(i,n) {
        auto dpo = dp2[i];
        auto dpn = dp2[i+1];

        FOR(stl,min(40,scnt+1)) {
            RNG(ls,-1,i-1) {
                FOR(op, 741) {
                    if(ls>=0 && stl==0 || stl>ls+1)
                        continue;
                    if(stl < scnt) {
                        int nop = abs(shields[stl]-i) + op;
                        dpn[stl+1][i+1][nop] |= MAX( dpo[stl][ls+1][op] );
                    }

                    int lemmLLS = ls<0 ? 0 : ls-stl+1;
                    dpn[stl][ls+1][op] |= MAX( dpo[stl][ls+1][op] + lemmLLS );
                }
            }
        }
    }

    int best=0;
    FOR(op,n*(n-1)/2+1) {
        RNG(ls,-1,n-1) {
            best |= MAX( dp2[n][scnt][ls+1][op] );
        }
        cout<<best<<' ';
    }
}


//region Template
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug_prettyprint.hpp>
#else
#define debug(...) 42
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#endif
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout<<fixed<<setprecision(12);
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
#define EXIT(answer) { cerr<<"EXIT #"<<__LINE__<<endl; cout<<answer<<endl; exit(0); }
#define sz(v) int(v.size())
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = max(lhs, rhs.val); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = min(lhs, rhs.val); }
template<typename T, typename U> istream& operator>>(istream& in, pair<T,U> &p) { in>>p.first>>p.second; return in; }
template<typename T> inline vector<T> READ(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
//endregion

short dp2[83][45][83][745]={{{{0}}}};

signed main() {
    FASTIO

    int n; cin>>n;
    vi a = READ<int>(n);
    vi shields;
    int scnt=0;
    FOR(i,n)
    if(a[i]==1) {
        shields.push_back(i);
        scnt++;
    }

    memset(dp2, 0x80, sizeof dp2);
    dp2[0][0][0][0]=0;

    FOR(i,n) {
        auto dpo = dp2[i];
        auto dpn = dp2[i+1];

        int placeable = n-1-i+1;
        int mhp = max(scnt-placeable, 0);
        int chp = min(i,scnt);

        int nxtPlaceable = n-1-(i+1)+1;
        int nxtMhp = max(scnt-nxtPlaceable, 0);

        RNG(stl,mhp,chp) {
            int stloff = stl-mhp;
            int nxtStloff = stl-nxtMhp;

            RNG(ls,-1,i-1) {
                if(ls>=0 && stl==0 || stl>ls+1)
                    continue;

                FOR(op, 741) {
                    if(stl < scnt) {
                        int nop = abs(shields[stl]-i) + op;
                        if(nop <= 741)
                            dpn[nxtStloff+1][i+1][nop] |= MAX( dpo[stloff][ls+1][op] );
                    }

                    short lemmLLS = ls<0 ? 0 : ls-stl+1;
                    dpn[nxtStloff][ls+1][op] |= MAX( (short)(dpo[stloff][ls+1][op] + lemmLLS) );
                }
            }
        }
    }

    short best=0;
    FOR(op,n*(n-1)/2+1) {
        RNG(ls,-1,n-1) {
            int i=n;
            int placeable = n-1-i+1;
            int mhp = max(scnt-placeable, 0);
            int stloff = scnt-mhp;

            best |= MAX( dp2[n][stloff][ls+1][op] );
        }
        cout<<best<<' ';
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 80 + 5;
const int M = N * N / 2;

int n;
int a[N];

int dp[N][N][M];
bool h[N][N][M];

vector<int> pos_ones = {0};

int comb(int n) {
  return n * (n - 1) / 2;
}

int f(int i, int used_shields, int rem_shields, int rem_protection) {
  if(i == n + 1) {
    if(rem_shields)
      return 1e9;
    return 0;
  }
  int &r = dp[i][rem_shields][rem_protection];
  if(h[i][rem_shields][rem_protection]) {
    return r;
  }
  h[i][rem_shields][rem_protection] = 1;

  r = 1e9;

  if(rem_shields) {
    for(int j = i + 1; j <= n + 1; j++) {
      int cost = abs(pos_ones[used_shields + 1] - j);
      int protection = comb(j - i - 1);
      if(rem_protection >= protection) {
        r = min(r, f(j, used_shields + 1, rem_shields - 1, rem_protection - protection) + cost);
      }
    }
  }

  return r;
}

int main() {
  scanf("%d", &n);
  int cnt0 = 0, cnt1 = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    cnt0 += (a[i] == 0);
    cnt1 += (a[i] == 1);
    if(a[i]) {
      pos_ones.push_back(i);
    }
  }

  pos_ones.push_back(n + 1);

  vector<int> ans(n * (n - 1) / 2 + 1);

  int plimit = 0;

  int cur_zeros = 0;
  for(int i = 1; i <= n; i++) {
    if(a[i]) {
      plimit += comb(cur_zeros);
      cur_zeros = 0;
    }
    else {
      cur_zeros++;
    }
  }
  plimit += comb(cur_zeros);

  for(int p = 0; p <= plimit; p++) {
    int protection = comb(cnt0) - p;
    int cost = f(0, 0, cnt1 + 1, p);
    if(cost < (int) 8e8) {
      ans[cost] = max(ans[cost], protection);
    }
  }

  for(int i = 1; i < ans.size(); i++) {
    ans[i] = max(ans[i], ans[i - 1]);
  }

  for(auto x : ans) {
    printf("%d ", x);
  }

  puts("");

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 80 + 5;
const int M = N * N / 2;

int n;
int a[N];

int dp[N][N][M];
bool h[N][N][M];

vector<int> pos_ones = {0};

int comb(int n) {
  return n * (n - 1) / 2;
}

int f(int i, int used_shields, int rem_shields, int rem_protection) {
  if(i == n + 1) {
    if(rem_shields)
      return 1e9;
    return 0;
  }
  int &r = dp[i][rem_shields][rem_protection];
  if(h[i][rem_shields][rem_protection]) {
    return r;
  }
  h[i][rem_shields][rem_protection] = 1;

  r = 1e9;

  if(rem_shields) {
    for(int j = i + 1; j <= n + 1; j++) {
      int cost = abs(pos_ones[used_shields + 1] - j);
      int protection = comb(j - i - 1);
      if(rem_protection >= protection) {
        r = min(r, f(j, used_shields + 1, rem_shields - 1, rem_protection - protection) + cost);
      }
    }
  }

  return r;
}

int main() {
  scanf("%d", &n);
  int cnt0 = 0, cnt1 = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    cnt0 += (a[i] == 0);
    cnt1 += (a[i] == 1);
    if(a[i]) {
      pos_ones.push_back(i);
    }
  }

  pos_ones.push_back(n + 1);

  vector<int> ans(n * (n - 1) / 2 + 1);

  int plimit = comb(cnt0);

  for(int p = 0; p <= plimit; p++) {
    int protection = comb(cnt0) - p;
    int cost = f(0, 0, cnt1 + 1, p);
    if(cost < (int) 8e8) {
      ans[cost] = max(ans[cost], protection);
    }
  }

  for(int i = 1; i < ans.size(); i++) {
    ans[i] = max(ans[i], ans[i - 1]);
  }

  for(auto x : ans) {
    printf("%d ", x);
  }

  puts("");

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 80 + 5;
const int M = N * N / 2;

int n;
int a[N];

int dp[N][N][M];
bool h[N][N][M];

vector<int> pos_ones = {0};

int comb(int n) {
  return n * (n - 1) / 2;
}

int f(int i, int used_shields, int rem_shields, int rem_protection) {
  if(i == n + 1) {
    if(rem_shields)
      return 1e9;
    return 0;
  }
  int &r = dp[i][rem_shields][rem_protection];
  if(h[i][rem_shields][rem_protection]) {
    return r;
  }
  h[i][rem_shields][rem_protection] = 1;

  r = 1e9;

  if(rem_shields) {
    for(int j = i + 1; j <= n + 1; j++) {
      int cost = abs(pos_ones[used_shields + 1] - j);
      int protection = comb(j - i - 1);
      if(rem_protection >= protection) {
        r = min(r, f(j, used_shields + 1, rem_shields - 1, rem_protection - protection) + cost);
      }
    }
  }

  return r;
}

int main() {
  scanf("%d", &n);
  int cnt0 = 0, cnt1 = 0;
  for(int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    cnt0 += (a[i] == 0);
    cnt1 += (a[i] == 1);
    if(a[i]) {
      pos_ones.push_back(i);
    }
  }

  pos_ones.push_back(n + 1);

  vector<int> ans(n * (n - 1) / 2 + 1);

  for(int p = 0; p <= n * (n - 1) / 2; p++) {
    int protection = comb(cnt0) - p;
    int cost = f(0, 0, cnt1 + 1, p);
    if(cost < (int) 8e8) {
      ans[cost] = max(ans[cost], protection);
    }
  }

  for(int i = 1; i < ans.size(); i++) {
    ans[i] = max(ans[i], ans[i - 1]);
  }

  for(auto x : ans) {
    printf("%d ", x);
  }

  puts("");

  return 0;
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 41];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0, 81 * 41) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , tot) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 41];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0, n + 1) fol(j,0, pref[n] + 1) fol(k,0, tot + 100) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , tot) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 81];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0,tot + 100) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , tot + 1) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 81];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0,80*80) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , tot + 1) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 81];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0,80*80) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , 80 * 80) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 81];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {}, on = n;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0,80*80) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , 80 * 80) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, on * (on - 1) / 2 + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


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

// Hate My Life //

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int dp[81][81][81 * 41];

int tejas_919(int kkkk)
{
    int n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;

    int arr[n+2] = {}, pref[n+2] = {};
    int tot = n * (n - 1) / 2;
    fol(i,0,n) {
        cin >> arr[i];
        arr[i] = 1 - arr[i];
    }

    vi pillars;
    fol(i,0,n+1) {
        int j = i;
        while(arr[j]) j ++;
        pillars.pb(j-i);
        i = j;
    }

    n = sz(pillars);
    fol(i,0,n) pref[i+1] = pref[i] + pillars[i];

    fol(i,0,81) fol(j,0,81) fol(k,0, tot + 100) dp[i][j][k] = mod;
    dp[0][0][0] = 0;

    fol(index, 0, n) fol(sum, 0, pref[n] + 1)
        fol(cnt, 0 , tot) if (dp[index][sum][cnt] != mod) {
            fol(nex_sum, sum, pref[n] + 1) {
                int &val = dp[index + 1][nex_sum][cnt + abs(pref[index + 1] - nex_sum)];
                val = min(val, dp[index][sum][cnt] + (nex_sum - sum) * (nex_sum - sum));
            }
    }

    ans = mod;
    fol (sum, 0, tot + 1) {
        ans = min(ans, dp[n][pref[n]][sum]);
        cout << (pref[n] * pref[n] - ans) / 2 << " ";
    }
    cout << endl;

    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    if(!localsys) { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) { tejas_919(i + 1); }
    end_routine();
    //if (localsys) system("pause");
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define MAXN 82

int dp[MAXN][2*MAXN][MAXN*(MAXN-1)/2];
int temp[MAXN];
int arr[MAXN];
int n, m = 0;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    arr[0] = 0;
    for(int i = 0; i<n; i++){
        cin >> temp[i];
        if(temp[i] == 1){
            m++;
            arr[m] = 0;
        }
        else arr[m]++;
    }
    for(int i = 0; i<=m; ++i) for(int num = -n+m; num<=n-m; ++num) for(int k = 0; k <= n*(n-1)/2; ++k) dp[i][num+MAXN][k] = 1000000009;
    for(int i = -n+m; i<=+n-m; i++){
        for(int k = 0; k<=(n)*(n-1)/2; ++k) dp[0][i+MAXN][k] = (i)*(i);
    }
    for(int i = 1; i<=m; ++i){
        for(int num = -n+m; num<=n-m; ++num){
            for(int k = 0; k<=(n)*(n-1)/2; ++k){
                for(int f = 0; f<=n-m; ++f){
                    if(abs(num-f) > k) continue;
                    int t = f*f+dp[i-1][arr[i-1]-f+num+MAXN][k-abs(num-f)];
                    if(t < dp[i][num+MAXN][k]) dp[i][num+MAXN][k] = t;
                }
            }
        }
    }
    for(int k = 0; k<=n*(n-1)/2; ++k){
        cout << ((n-m)*(n-m)-dp[m][arr[m]+MAXN][k])/2 << " ";
    }
    cout << endl;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define MAXN 81

int dp[MAXN][2*MAXN][MAXN*(MAXN-1)/2];
int temp[MAXN];
int arr[MAXN];
int n, m = 0;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    arr[0] = 0;
    for(int i = 0; i<n; i++){
        cin >> temp[i];
        if(temp[i] == 1){
            m++;
            arr[m] = 0;
        }
        else arr[m]++;
    }
    for(int i = 0; i<=m; ++i) for(int num = -n+m; num<=n-m; ++num) for(int k = 0; k <= n*(n-1)/2; ++k) dp[i][num+MAXN][k] = 1000000009;
    for(int i = -n+m; i<=+n-m; i++){
        for(int k = 0; k<=(n)*(n-1)/2; ++k) dp[0][i+MAXN][k] = (i)*(i);
    }
    for(int i = 1; i<=m; ++i){
        for(int num = -n+m; num<=n-m; ++num){
            for(int k = 0; k<=(n)*(n-1)/2; ++k){
                for(int f = 0; f<=n-m; ++f){
                    if(abs(num-f) > k) continue;
                    int t = f*f+dp[i-1][arr[i-1]-f+num+MAXN][k-abs(num-f)];
                    if(t < dp[i][num+MAXN][k]) dp[i][num+MAXN][k] = t;
                }
            }
        }
    }
    for(int k = 0; k<=n*(n-1)/2; ++k){
        cout << ((n-m)*(n-m)-dp[m][arr[m]+MAXN][k])/2 << " ";
    }
    cout << endl;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define MAXN 82

int dp[MAXN][2*MAXN][MAXN*(MAXN-1)/2];
int temp[MAXN];
int arr[MAXN];
int n, m = 0;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    arr[0] = 0;
    for(int i = 0; i<n; i++){
        cin >> temp[i];
        if(temp[i] == 1){
            m++;
            arr[m] = 0;
        }
        else arr[m]++;
    }
    for(int i = 0; i<=m; ++i) for(int num = -n+m; num<=n-m; ++num) for(int k = 0; k <= n*(n-1)/2; ++k) dp[i][num+MAXN][k] = 1000000009;
    for(int i = -n+m; i<=n-m; i++){
        for(int k = 0; k<=(n)*(n-1)/2; ++k) dp[0][i+MAXN][k] = (i)*(i);
    }
    for(int i = 1; i<=m; ++i){
        for(int num = -n+m; num<=n-m; ++num){
            for(int k = 0; k<=(n)*(n-1)/2; ++k){
                for(int f = 0; f<=n-m; ++f){
                    if(abs(num-f) > k) continue;
                    if(arr[i-1]-f+num < 0 || arr[i-1]-f+num > n-m) continue;
                    int t = f*f+dp[i-1][arr[i-1]-f+num+MAXN][k-abs(num-f)];
                    if(t < dp[i][num+MAXN][k]) dp[i][num+MAXN][k] = t;
                }
            }
        }
    }
    for(int k = 0; k<=n*(n-1)/2; ++k){
        cout << ((n-m)*(n-m)-dp[m][arr[m]+MAXN][k])/2 << " ";
    }
    cout << endl;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define MAXN 82

int dp[MAXN][2*MAXN][MAXN*(MAXN-1)/2];
int temp[MAXN];
int arr[MAXN];
int n, m = 0;

int main(){
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    arr[0] = 0;
    for(int i = 0; i<n; i++){
        cin >> temp[i];
        if(temp[i] == 1){
            m++;
            arr[m] = 0;
        }
        else arr[m]++;
    }
    for(int i = 0; i<=m; ++i) for(int num = -n+m; num<=n-m; ++num) for(int k = 0; k <= n*(n-1)/2; ++k) dp[i][num+MAXN][k] = 1000000009;
    for(int i = -n+m; i<=n-m; i++){
        for(int k = 0; k<=(n)*(n-1)/2; ++k) dp[0][i+MAXN][k] = (i)*(i);
    }
    for(int i = 1; i<=m; ++i){
        for(int num = -n+m; num<=n-m; ++num){
            for(int k = 0; k<=(n)*(n-1)/2; ++k){
                for(int f = 0; f<=n-m; ++f){
                    if(abs(num-f) > k) continue;
                    if(arr[i-1]-f+num < -n+m || arr[i-1]-f+num > n-m) continue;
                    int t = f*f+dp[i-1][arr[i-1]-f+num+MAXN][k-abs(num-f)];
                    if(t < dp[i][num+MAXN][k]) dp[i][num+MAXN][k] = t;
                }
            }
        }
    }
    for(int k = 0; k<=n*(n-1)/2; ++k){
        cout << ((n-m)*(n-m)-dp[m][arr[m]+MAXN][k])/2 << " ";
    }
    cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int dp[82][82][3400];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	memset(dp,-0x3f,sizeof(dp));
	vi all;
	vi pos;
	{
		int pre=0;
		for(int i=0;i<n;i++)
		{
			if(a[i])
			{
				all.push_back(i-pre);
				pos.push_back(i);
				pre=i+1;
			}
		}
		all.push_back(n-pre);
		pos.push_back(n);
	}
	int sz=all.size();
	int zcnt=n-sz+1;
	dp[0][0][0]=0;
	for(int i=1;i<=sz;i++)
	{
		for(int j=0;j<=zcnt;j++)
		{
			for(int k=0;k<=n*(n-1)/2;k++)
			{
				if(dp[i-1][j][k]<0) continue;
				for(int cc=0;cc+j<=zcnt;cc++)
				{
					int pre=i-1+j+cc;
					int d=abs(pre-pos[i-1]);
					int cur=cc*j;
	//				dbg(i,j,cc,k,d);
					dp[i][j+cc][k+d]=max(dp[i-1][j][k]+cur,dp[i][j+cc][k+d]);
				}
			}
		}
	}
	vi ans(n*(n-1)/2+1);
	for(int i=0;i<ans.size();i++) ans[i]=dp[sz][zcnt][i];
	for(int i=1;i<ans.size();i++) ans[i]=max(ans[i-1],ans[i]);
	print(ans);
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
vi all;
vi ans,pos;
int tot=0;
int sz;
void solve(int cur,int cnt,int dif=0,int pre=0,int ap=0)
{
	if(cnt==sz)
	{
		if(cur==tot)
			ans[dif]=max(ans[dif],ap);
		return;
	}
	for(int i=0;i+cur<=tot;i++)
		solve(i+cur,cnt+1,dif+abs(pos[cnt]-(pre+cnt+i)),pre+i,ap+i*pre);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	ans=vi(n*(n-1)/2+1);
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	int p=0;
	for(int i=0;i<n;i++)
	{
		if(a[i])
		{
			all.push_back(i-p);
			p=i+1;
			pos.push_back(i);
		}
	}
	all.push_back(n-p);
	pos.push_back(n);
	for(auto u:all) tot+=u;
	//dbg(all);
	sz=all.size();
	solve(0,0);
	for(int i=1;i<ans.size();i++) ans[i]=max(ans[i],ans[i-1]);
	print(ans);
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int dp[81][81][3400];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	memset(dp,-0x3f,sizeof(dp));
	vi all;
	vi pos;
	{
		int pre=0;
		for(int i=0;i<n;i++)
		{
			if(a[i])
			{
				all.push_back(i-pre);
				pos.push_back(i);
				pre=i+1;
			}
		}
		all.push_back(n-pre);
		pos.push_back(n);
	}
	int sz=all.size();
	int zcnt=n-sz+1;
	dp[0][0][0]=0;
	for(int i=1;i<=sz;i++)
	{
		for(int j=0;j<=zcnt;j++)
		{
			for(int k=0;k<=n*(n-1)/2;k++)
			{
				if(dp[i-1][j][k]<0) continue;
				for(int cc=0;cc+j<=zcnt;cc++)
				{
					int pre=i-1+j+cc;
					int d=abs(pre-pos[i-1]);
					int cur=cc*j;
	//				dbg(i,j,cc,k,d);
					dp[i][j+cc][k+d]=max(dp[i-1][j][k]+cur,dp[i][j+cc][k+d]);
				}
			}
		}
	}
	vi ans(n*(n-1)/2+1);
	for(int i=0;i<ans.size();i++) ans[i]=dp[sz][zcnt][i];
	for(int i=1;i<ans.size();i++) ans[i]=max(ans[i-1],ans[i]);
	print(ans);
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int dp[81][81][3400];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int n;
	cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	memset(dp,-0x3f,sizeof(dp));
	vi all;
	vi pos;
	{
		int pre=0;
		for(int i=0;i<n;i++)
		{
			if(a[i])
			{
				all.push_back(i-pre);
				pos.push_back(i);
				pre=i+1;
			}
		}
		all.push_back(n-pre);
		pos.push_back(n);
	}
	int sz=all.size();
	int zcnt=n-sz+1;
	dp[0][0][0]=0;
	for(int i=1;i<=sz;i++)
	{
		for(int j=0;j<=zcnt;j++)
		{
			for(int k=0;k<=zcnt*(zcnt-1)/2;k++)
			{
				if(dp[i-1][j][k]<0) continue;
				for(int cc=0;cc+j<=zcnt;cc++)
				{
					int pre=i-1+j+cc;
					int d=abs(pre-pos[i-1]);
					int cur=cc*j;
	//				dbg(i,j,cc,k,d);
					dp[i][j+cc][k+d]=max(dp[i-1][j][k]+cur,dp[i][j+cc][k+d]);
				}
			}
		}
	}
	vi ans(n*(n-1)/2+1);
	for(int i=0;i<ans.size();i++) ans[i]=dp[sz][zcnt][i];
	for(int i=1;i<ans.size();i++) ans[i]=max(ans[i-1],ans[i]);
	print(ans);
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const int inf = (int)1e8;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 81;
const int M = 801;

vector < int > pos[2];
int n, a[N], cnt0[N][N], cnt1[N][N], prv[N][N][M], nxt[N][N][M];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

	//cout << setprecision(10) << fixed;

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]].pb(i);
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < sz(pos[0]); j++)
			cnt0[j + 1][i] = cnt0[j][i] + (pos[0][j] > i);
		for (int j = 0; j < sz(pos[1]); j++)
			cnt1[j + 1][i] = cnt1[j][i] + (pos[1][j] > i);
	}

	for (int j = 0; j < N; j++)
		for (int k = 0; k < N; k++)
			for (int x = 0; x < M; x++)
				prv[j][k][x] = nxt[j][k][x] = inf;

	prv[0][0][0] = 0;

	int tot = sz(pos[1]);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= min(i, tot); j++) {
			int zer = i - j;
			for (int k = 0; k <= min(i - j, n - tot); k++) {
				for (int x = 0; x < M; x++) {
					if (zer < sz(pos[0])) {
					    int newpos = pos[0][zer] + cnt1[j][pos[0][zer]];
					    if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j][k + 1][x + newpos - (i + 1)] = min(nxt[j][k + 1][x + newpos - (i + 1)], prv[j][k][x] + k);
					}
					if (j < sz(pos[1])) {
						int newpos = pos[1][j] + cnt0[zer][pos[1][j]];
						if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j + 1][0][x + newpos - (i + 1)] = min(nxt[j + 1][0][x + newpos - (i + 1)], prv[j][k][x]);
					}

				}
			}
		}
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				for (int x = 0; x < M; x++) {
					swap(prv[j][k][x], nxt[j][k][x]);
					nxt[j][k][x] = inf;
				}
			}
		}
	}

	int add = n * (n - 1) / 2 - tot * (n - tot) - tot * (tot - 1) / 2;

	int ans = inf;

	for (int i = 0; i <= min(M - 1, n * (n - 1) / 2); i++) {
		for (int j = 0; j <= n - tot; j++)
			ans = min(ans, prv[tot][j][i]);
		cout << add - ans << " ";
	}
	for (int i = M; i <= n * (n - 1) / 2; i++)
		cout << add - ans << " ";

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const int inf = (int)1e8;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 81;
const int M = 801;

vector < int > pos[2];
int n, a[N], cnt0[N][N], cnt1[N][N], prv[N][N][M], nxt[N][N][M];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

	//cout << setprecision(10) << fixed;

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]].pb(i);
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < sz(pos[0]); j++)
			cnt0[j + 1][i] = cnt0[j][i] + (pos[0][j] > i);
		for (int j = 0; j < sz(pos[1]); j++)
			cnt1[j + 1][i] = cnt1[j][i] + (pos[1][j] > i);
	}

	for (int j = 0; j < N; j++)
		for (int k = 0; k < N; k++)
			for (int x = 0; x < M; x++)
				prv[j][k][x] = nxt[j][k][x] = inf;

	prv[0][0][0] = 0;

	int tot = sz(pos[1]);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= min(i, tot); j++) {
			int zer = i - j;
			for (int k = 0; k <= min(i - j, n - tot); k++) {
				for (int x = 0; x < M; x++) {
				    if (prv[j][k][x] == inf)
				        continue;
					if (zer < sz(pos[0])) {
					    int newpos = pos[0][zer] + cnt1[j][pos[0][zer]];
					    if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j][k + 1][x + newpos - (i + 1)] = min(nxt[j][k + 1][x + newpos - (i + 1)], prv[j][k][x] + k);
					}
					if (j < sz(pos[1])) {
						int newpos = pos[1][j] + cnt0[zer][pos[1][j]];
						if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j + 1][0][x + newpos - (i + 1)] = min(nxt[j + 1][0][x + newpos - (i + 1)], prv[j][k][x]);
					}

				}
			}
		}
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				for (int x = 0; x < M; x++) {
					swap(prv[j][k][x], nxt[j][k][x]);
					nxt[j][k][x] = inf;
				}
			}
		}
	}

	int add = n * (n - 1) / 2 - tot * (n - tot) - tot * (tot - 1) / 2;

	int ans = inf;

	for (int i = 0; i <= min(M - 1, n * (n - 1) / 2); i++) {
		for (int j = 0; j <= n - tot; j++)
			ans = min(ans, prv[tot][j][i]);
		cout << add - ans << " ";
	}
	for (int i = M; i <= n * (n - 1) / 2; i++)
		cout << add - ans << " ";

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const int inf = (int)1e8;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 81;
const int M = 1601;

vector < int > pos[2];
int n, a[N], cnt0[N][N], cnt1[N][N], prv[N][N][M], nxt[N][N][M];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

	//cout << setprecision(10) << fixed;

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		pos[a[i]].pb(i);
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < sz(pos[0]); j++)
			cnt0[j + 1][i] = cnt0[j][i] + (pos[0][j] > i);
		for (int j = 0; j < sz(pos[1]); j++)
			cnt1[j + 1][i] = cnt1[j][i] + (pos[1][j] > i);
	}

	for (int j = 0; j < N; j++)
		for (int k = 0; k < N; k++)
			for (int x = 0; x < M; x++)
				prv[j][k][x] = nxt[j][k][x] = inf;

	prv[0][0][0] = 0;

	int tot = sz(pos[1]);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= min(i, tot); j++) {
			int zer = i - j;
			for (int k = 0; k <= min(i - j, n - tot); k++) {
				for (int x = 0; x < M; x++) {
					if (zer < sz(pos[0])) {
					    int newpos = pos[0][zer] + cnt1[j][pos[0][zer]];
					    if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j][k + 1][x + newpos - (i + 1)] = min(nxt[j][k + 1][x + newpos - (i + 1)], prv[j][k][x] + k);
					}
					if (j < sz(pos[1])) {
						int newpos = pos[1][j] + cnt0[zer][pos[1][j]];
						if (i + 1 <= newpos && x + newpos - (i + 1) < M)
							nxt[j + 1][0][x + newpos - (i + 1)] = min(nxt[j + 1][0][x + newpos - (i + 1)], prv[j][k][x]);
					}

				}
			}
		}
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				for (int x = 0; x < M; x++) {
					swap(prv[j][k][x], nxt[j][k][x]);
					nxt[j][k][x] = inf;
				}
			}
		}
	}

	int add = n * (n - 1) / 2 - tot * (n - tot) - tot * (tot - 1) / 2;

	int ans = inf;

	for (int i = 0; i <= min(M - 1, n * (n - 1) / 2); i++) {
		for (int j = 0; j <= n - tot; j++)
			ans = min(ans, prv[tot][j][i]);
		cout << add - ans << " ";
	}
	for (int i = M; i <= n * (n - 1) / 2; i++)
		cout << add - ans << " ";

	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}