#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

int n, c1[70], c2[70];

int logg(ll a) {
	int r = -1;
	while (a > 0) {
		a /= 2;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1ll)) == 0ll;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;

	fr(i, 1, 70) {
		h += c2[i];

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			h += c1[i]-q;
		}
	}

	return (h <= q);
}

int main() {
	cin >> n;
	{
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			cin >> v;

			int l = logg(v);

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];

		bool any = 0;
		fr(i, 1, mx+1) if (pode(i)) {
			if (any) cout << " ";
			any = 1;
			cout << i;
		}
		if (!any) cout << "-1";
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

#define N 100009

int n, c1[50], c2[50];
//pii a[N];

int logg(ll a) {
	int r = -1;
	while (a) {
		a >>= 1;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1ll)) == 0ll;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;
	//db(x);
	fr(i, 1, 50) {
		//db(q _ h);
		//db(c1[i] _ c2[i]);
		h += c2[i];

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			h += c1[i]-q;
		}
	}

	if (h > q) return 0;
	return 1;
}
/*
int greedy() {
	int q = 0;
	int h = 0;//< 0, faltando: > 0, sobrando

	rp(ii, 50) {
		int i = 49-ii;

		if (c1[i] < q) return oo;
		h -= c2[i];

		int nw = c1[i]-q;
		int come = min(nw, h);

		q += nw - come;
		h -= come;
		h += nw - come;

		if (h < 0) return oo;
	}

	return q;
}
*/
int main() {
	while (sc(n) == 1) {
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			scanf("%lld", &v);
			int l = logg(v);
			//db(v _ l _ ispow(v));

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];
		if (mx == 0 || !pode(mx)) {
			puts("-1");
			//return 0;
			continue;
		}

		int lo = 0;
		for(int p = 20; p >= 0; p--) {
			int add = 1<<p;
			if (lo+add < mx && !pode(lo+add)) lo += add;
		}
		fr(i, lo+1, mx) printf("%d ", i);
		pri(mx);
	//	return 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

#define N 100009

int n, c1[50], c2[50];
//pii a[N];

int logg(ll a) {
	int r = -1;
	while (a) {
		a >>= 1;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1)) == 0;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;

	//db(x);
	fr(i, 1, 50) {
		//db(i _ c1[i] _ c2[i]);

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			//db(h);
			h += c1[i]-q;
			//db(h);
		}
		h += c2[i];

		//db(q _ h);
	}

	//db(h _ q);
	if (h > q) return 0;
	return 1;
}

int main() {
	while (sc(n) == 1) {
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			scanf("%lld", &v);
			int l = logg(v);

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];

		if (!pode(mx)) {
			puts("-1");
			continue;
		}

		int lo = 0;
		for(int p = 20; p >= 0; p--) {
			int add = 1<<p;
			if (lo+add < mx && !pode(lo+add)) lo += add;
		}
		fr(i, lo+1, mx) printf("%d ", i);
		pri(mx);
	//	return 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

#define N 100009

int n, c1[50], c2[50];
//pii a[N];

int logg(ll a) {
	int r = -1;
	while (a) {
		a >>= 1;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1)) == 0;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;
	//db(x);
	fr(i, 1, 50) {
		//db(q _ h);
		//db(c1[i] _ c2[i]);
		h += c2[i];

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			h += c1[i]-q;
		}
	}

	if (h > q) return 0;
	return 1;
}
/*
int greedy() {
	int q = 0;
	int h = 0;//< 0, faltando: > 0, sobrando

	rp(ii, 50) {
		int i = 49-ii;

		if (c1[i] < q) return oo;
		h -= c2[i];

		int nw = c1[i]-q;
		int come = min(nw, h);

		q += nw - come;
		h -= come;
		h += nw - come;

		if (h < 0) return oo;
	}

	return q;
}
*/
int main() {
	while (sc(n) == 1) {
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			scanf("%lld", &v);
			int l = logg(v);
			//db(v _ l _ ispow(v));

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];
		if (!pode(mx)) {
			puts("-1");
			//return 0;
			continue;
		}

		int lo = 0;
		for(int p = 20; p >= 0; p--) {
			int add = 1<<p;
			if (lo+p < mx && !pode(lo+p)) lo += p;
		}
		fr(i, lo+1, mx) printf("%d ", i);
		pri(mx);
	//	return 0;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

int n, c1[70], c2[70];

int logg(ll a) {
	int r = -1;
	while (a > 0) {
		a /= 2;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1ll)) == 0ll;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;

	fr(i, 1, 70) {
		h += c2[i];

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			h += c1[i]-q;
		}
	}

	return (h <= q);
}

int main() {
	cin >> n;
	{
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			cin >> v;

			int l = logg(v);

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];
		if (mx == 0 || !pode(mx)) {
			puts("-1");
			return 0;
		}

		fr(i, 1, mx) if (pode(i)) cout << i << " ";
		cout << mx << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define fr(a,b,c) for(int (a) = (b); (a) < (c); ++(a))
#define rp(a,b) fr(a,0,b)
#define fre(a,b) for(int a = adj[b]; ~a; a = ant[a])
#define cl(a,b) memset((a), (b), sizeof(a))
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define scs(s) scanf("%s", s)
#define pri(x) printf("%d\n", x)

#define iter(a) __typeof((a).begin())
#define fore(a,b) for(iter(b) a = (b).begin(); a != (b).end(); ++a)

#define st first
#define nd second
#define mp make_pair
#define pb push_back

#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector< vi > vii;

const int oo = 0x3f3f3f3f;

int n, c1[70], c2[70];
//pii a[N];

int logg(ll a) {
	int r = -1;
	while (a > 0) {
		a >>= 1;
		r++;
	}
	return r;
}

bool ispow(ll a) {
	return (a&(a-1ll)) == 0ll;
}

bool pode(int x) {
	int q = x, h = c1[0]-x;
	//db(x);
	fr(i, 1, 70) {
		//db(q _ h);
		//db(c1[i] _ c2[i]);
		h += c2[i];

		if (q > c1[i]) {
			int d = q - c1[i];
			h = max(0, h-d);
			q -= d;
		} else {
			h += c1[i]-q;
		}
	}

	if (h > q) return 0;
	return 1;
}
/*
int greedy() {
	int q = 0;
	int h = 0;//< 0, faltando: > 0, sobrando

	rp(ii, 50) {
		int i = 49-ii;

		if (c1[i] < q) return oo;
		h -= c2[i];

		int nw = c1[i]-q;
		int come = min(nw, h);

		q += nw - come;
		h -= come;
		h += nw - come;

		if (h < 0) return oo;
	}

	return q;
}
*/
int main() {
	cin >> n;
	//while (sc(n) == 1)
	{
		cl(c1, 0);
		cl(c2, 0);
		rp(i, n) {
			ll v;
			cin >> v;
			//scanf("%lld", &v);
			int l = logg(v);

			if (ispow(v)) c1[l]++;
			else c2[l]++;
		}

		int mx = c1[0];
		if (mx == 0 || !pode(mx)) {
			puts("-1");
			return 0;
		}

		int lo = 0;
		for(int p = 25; p >= 0; p--) {
			int add = (1<<p);
			if (lo+add < mx && !pode(lo+add)) lo += add;
		}
		fr(i, lo+1, mx) printf("%d ", i);
		printf("%d\n", mx);
	//	return 0;
	}
	return 0;
}


#include <bits/stdc++.h>

typedef long long Int64;

const Int64 N = 1e5 + 1000;

Int64 n;
std::map<Int64, Int64> cnt;

void init() {
	std::cin >> n;
	for (Int64 i = 1; i <= n; i++) {
		Int64 t;
		scanf("%I64d", &t);
		cnt[t]++;
	}
}

bool check(Int64 m) {
	Int64 c[3] = {m, 0, 0};
	Int64 cntOther = 0;
	Int64 cur = 1;
	for (std::map<Int64, Int64>::iterator it = cnt.begin(); it != cnt.end(); it++) {
		Int64 number = it->first, t = it->second;
		if (number > cur) {
			return false;
		} else if (number != cur) {
			if (c[0] < t) {
				return false;
			} else {
				c[0] -= t;
				c[1] += t;
			}
		} else {
			if (t <= c[0]) {
				c[2] += c[0] - t;
				c[0] = t;
			} else if (t <= c[0] + c[1]) {
				c[2] += c[0] + c[1] - t;
				c[1] = t - c[0];
			} else if (t <= c[0] + c[1] + c[0]) {
				Int64 delta = t - c[0] - c[1];
				c[0] -= delta;
				c[1] += delta;
			} else {
				return false;
			}
			cur <<= 1;
		}
	}
	return true;
}

void work() {
	std::vector<Int64> answer;

	for (Int64 i = 1; i <= cnt[1]; i++) {
		if (check(i)) {
			answer.push_back(i);
		}
	}
	if (answer.empty()) {
		std::cout << -1 << std::endl;
	} else {
		for (Int64 i = 0; i < (Int64)answer.size(); i++) {
			printf("%I64d%c", answer[i], " \n"[i + 1 == (Int64)answer.size()]);
		}
	}
}

int main() {
	//freopen("c.in", "r", stdin);

	init();
	work();

	return 0;
}


#include <bits/stdc++.h>

typedef long long Int64;

const Int64 N = 1e5 + 1000;

Int64 n;
std::map<Int64, Int64> cnt;

void init() {
	std::cin >> n;
	for (Int64 i = 1; i <= n; i++) {
		Int64 t;
		scanf("%I64d", &t);
		cnt[t]++;
	}
}

bool check(Int64 m) {
	Int64 c[3] = {m, 0, 0};
	Int64 cntOther = 0;
	Int64 cur = 1;
	for (std::map<Int64, Int64>::iterator it = cnt.begin(); it != cnt.end(); it++) {
		Int64 number = it->first, t = it->second;
		if (number > cur) {
			return false;
		} else if (number != cur) {
			if (c[0] < t) {
				return false;
			} else {
				c[0] -= t;
				c[1] += t;
			}
		} else {
			if (t <= c[0]) {
				c[1] = 0;
				c[0] = t;
			} else if (t <= c[0] + c[1]) {
				c[1] = t - c[0];
			} else if (t <= c[0] + c[1] + c[0]) {
				Int64 delta = t - c[0] - c[1];
				c[0] -= delta;
				c[1] += delta;
			} else {
				return false;
			}
			cur <<= 1;
		}
	}
	return true;
}

void work() {
	std::vector<Int64> answer;

	for (Int64 i = 1; i <= cnt[1]; i++) {
		if (check(i)) {
			answer.push_back(i);
		}
	}
	if (answer.empty()) {
		std::cout << -1 << std::endl;
	} else {
		for (Int64 i = 0; i < (Int64)answer.size(); i++) {
			printf("%I64d%c", answer[i], " \n"[i + 1 == (Int64)answer.size()]);
		}
	}
}

int main() {
	//freopen("c.in", "r", stdin);

	init();
	work();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N=101110,K=50;

long long A[N],P[K];
int number[K],lower[K];
int n,inf,sup,mid,low,cnt;

bool Check(int val){
    int Min=val,cnt=0;
    for(int i=0;i<K;i++){
        cnt+=lower[i];
        cnt=max(0,cnt+number[i]-Min);
        Min=min(Min,number[i]);
    }
    return cnt==0;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("806C.inp","r",stdin);
        freopen("806C.out","w",stdout);
    #endif // ONLINE_JUDGE
    cin>>n;
    P[0]=1;
    for(int i=1;i<K;i++)
        P[i]=P[i-1]*2;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        for(int k=0;k<K;k++)
            if(A[i]==P[k]){
                A[i]=-k;
                break;
            }
        if(A[i]<=0){
            number[-A[i]]++;
            lower[-A[i]]+=cnt;
            cnt=0;
        }
        else
            cnt++;
    }
    low=-1;inf=1;sup=number[0];
    while(inf<=sup){
        mid=(inf+sup)/2;
        if(Check(mid)){
            low=mid;
            sup=mid-1;
        }
        else
            inf=mid+1;
    }
    if(low==-1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=low;i<=number[0];i++) cout<<i<<" ";
}


#include <bits/stdc++.h>

using namespace std;

const int N=101110,K=50;

long long A[N],P[K];
int number[K],lower[K];
int n,inf,sup,mid,low,cnt;

bool Check(int val){
    int Min=val,cnt=0;
    for(int i=0;i<K;i++){
        cnt+=lower[i];
        cnt=max(0,cnt+number[i]-Min);
        Min=min(Min,number[i]);
    }
    return cnt==0;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("806C.inp","r",stdin);
        freopen("806C.out","w",stdout);
    #endif // ONLINE_JUDGE
    cin>>n;
    P[0]=1;
    for(int i=1;i<K;i++)
        P[i]=P[i-1]*2;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        for(int k=0;k<K;k++){
            if(A[i]==P[k]){
                A[i]=-k;
                break;
            }
            else{
                if(k<K-1&&A[i]>P[k]&&A[i]<P[k+1])
                    lower[k+1]++;
            }
        }
        if(A[i]<=0)
            number[-A[i]]++;
    }
    low=-1;inf=1;sup=number[0];
    while(inf<=sup){
        mid=(inf+sup)/2;
        if(Check(mid)){
            low=mid;
            sup=mid-1;
        }
        else
            inf=mid+1;
    }
    if(low==-1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=low;i<=number[0];i++) cout<<i<<" ";
}


#include <bits/stdc++.h>

using namespace std;

const int N=101110,K=50;

long long A[N],P[K];
int number[K],lower[K];
int n,inf,sup,mid,low,cnt;

bool Check(int val){
    int Min=val,cnt=0;
    for(int i=0;i<K;i++){
        cnt+=lower[i];
        cnt=max(0,cnt+number[i]-Min);
        Min=min(Min,number[i]);
    }
    return cnt==0;
}

int main(){
    #ifndef ONLINE_JUDGE
        freopen("806C.inp","r",stdin);
        freopen("806C.out","w",stdout);
    #endif // ONLINE_JUDGE
    cin>>n;
    P[0]=1;
    for(int i=1;i<K;i++)
        P[i]=P[i-1]*2;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        for(int k=0;k<K;k++){
            if(A[i]==P[k]){
                A[i]=-k;
                break;
            }
            else{
                if(i<K-1&&A[i]>P[k]&&A[i]<P[k+1])
                    lower[k+1]++;
            }
        }
        if(A[i]<=0){
            number[-A[i]]++;
            lower[-A[i]]+=cnt;
            cnt=0;
        }
    }
    low=-1;inf=1;sup=number[0];
    while(inf<=sup){
        mid=(inf+sup)/2;
        if(Check(mid)){
            low=mid;
            sup=mid-1;
        }
        else
            inf=mid+1;
    }
    if(low==-1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=low;i<=number[0];i++) cout<<i<<" ";
}


#include <bits/stdc++.h>

using namespace std;

const int N=101110,K=50;

long long A[N],P[K];
int number[K],lower[K];
int n,inf,sup,mid,low,cnt;

bool Check(int val){
    int Min=val,cnt=0;
    for(int i=0;i<K;i++){
        cnt+=lower[i];
        cnt=max(0,cnt+number[i]-Min);
        Min=min(Min,number[i]);
    }
    return cnt==0;
}

int main(){
    #ifndef ONLINE_JUGDE
        freopen("806C.inp","r",stdin);
        freopen("806C.out","w",stdout);
    #endif // ONLINE_JUDGE
    cin>>n;
    P[0]=1;
    for(int i=1;i<K;i++)
        P[i]=P[i-1]*2;
    for(int i=1;i<=n;i++){
        cin>>A[i];
        for(int k=0;k<K;k++)
            if(A[i]==P[k]){
                A[i]=-k;
                break;
            }
        if(A[i]<=0){
            number[-A[i]]++;
            lower[-A[i]]+=cnt;
            cnt=0;
        }
        else
            cnt++;
    }
    low=-1;inf=1;sup=number[0];
    while(inf<=sup){
        mid=(inf+sup)/2;
        if(Check(mid)){
            low=mid;
            sup=mid-1;
        }
        else
            inf=mid+1;
    }
    if(low==-1){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=low;i<=number[0];i++) cout<<i<<" ";
}


#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;

int x[50],y[50];
int p[50],q[50];

bool check(int X){
	int i,j;

	REP(i,50){
		p[i] = x[i];
		q[i] = y[i];
	}

	REP(i,50){
		if(p[i] <= X){
			X = p[i];
		} else {
			int tmp = p[i] - X;
			p[i] = X;
			q[i] += tmp;
		}
	}

	vector <int> P,Q;
	REP(i,45){
		REP(j,p[i]-p[i+1]) P.push_back(i);
		REP(j,q[i]) Q.push_back(i);
	}

	if(P.size() < Q.size()) return false;
	int delta = P.size() - Q.size();
	REP(i,Q.size()) if(P[delta+i] < Q[i]) return false;
	return true;
}

int main(void){
	int N,i;

	cin >> N;

	REP(i,N){
		ll z;
		scanf("%I64d", &z); // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
		int t;
		for(t=50;;t--) if((1ll<<t) <= z) break;
		if((1ll<<t) == z) x[t]++; else y[t]++;
	}

	if(!check(x[0])){
		cout << -1 << endl;
		return 0;
	}

	int high = x[0], low = 0;
	while(high - low > 1){
		int mid = (low + high) / 2;
		if(check(mid)) high = mid; else low = mid;
	}

	for(i=high;i<=x[0];i++){
		printf("%d", i);
		if(i == x[0]) printf("\n"); else printf(" ");
	}

	return 0;
}


#include <bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define MOD 1000000007

#define eps 1e-7

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

typedef double DO;

#define NN 100100

INT a[NN];

int cnt[111], cc[111];

int main() {

	int n;

	scanf("%d", &n);

	for (int i=0; i<n; i++) scanf("%I64d", a+i);

	sort(a, a+n);

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

		if (__builtin_popcountll(a[i])==1) cnt[63-__builtin_clzll(a[i])]++;

		else cc[63-__builtin_clzll(a[i])]++;

	}

	int flag=0;

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

		int sum=n, ok=1, pre, now=0;

		for (int j=0; j<45; j++) {

			if (j) {

				if (pre>cnt[j]) {

					now-=min(now, pre-cnt[j]);

					now+=cc[j];

				} else {

					now+=cnt[j]-pre;

					now+=cc[j];

				}

				if (cnt[j]==0) {

					for (j++; j<45; j++) now+=cnt[j]+cc[j];

					break;

				}

			} else {

				if (cnt[0]<i) {ok=0;break;}

				sum-=i; pre=i;

				now+=cnt[0]-i;

			}

		}

		if (ok && !now) printf("%d ", i), flag=1;

	}

	if (!flag) puts("-1");

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define MOD 1000000007

#define eps 1e-7

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

typedef double DO;

#define NN 100100

INT a[NN];

int cnt[111], cc[111];

int main() {

	int n;

	scanf("%d", &n);

	for (int i=0; i<n; i++) scanf("%I64d", a+i);

	sort(a, a+n);

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

		if (__builtin_popcountll(a[i])==1) cnt[63-__builtin_clzll(a[i])]++;

		else cc[63-__builtin_clzll(a[i])]++;

	}

	int flag=0;

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

		int ok=1, pre, now=0;

		for (int j=0; j<45; j++) {

			if (j) {

				if (pre>cnt[j]) {

					now-=min(now, pre-cnt[j]);

					now+=cc[j];

					pre=cnt[j];

				} else {

					now+=cnt[j]-pre;

					now+=cc[j];

				}

				if (cnt[j]==0) {

					for (j++; j<45; j++) now+=cnt[j]+cc[j];

					break;

				}

			} else {

				if (cnt[0]<i) {ok=0;break;}

				pre=i;

				now+=cnt[0]-i;

			}

		}

		if (ok && !now) printf("%d ", i), flag=1;

	}

	if (!flag) puts("-1");

	return 0;

}


#include <bits/stdc++.h>

#define x first

#define y second

#define pb push_back

#define MOD 1000000007

#define eps 1e-7

using namespace std;

typedef long long INT;

typedef pair<int, int> pii;

typedef double DO;

#define NN 100100

INT a[NN];

int cnt[111], cc[111];

int main() {

	int n;

	scanf("%d", &n);

	for (int i=0; i<n; i++) scanf("%I64d", a+i);

	sort(a, a+n);

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

		if (__builtin_popcountll(a[i])==1) cnt[63-__builtin_clzll(a[i])]++;

		else cc[63-__builtin_clzll(a[i])]++;

	}

	int flag=0;

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

		int sum=n, ok=1, pre, now=0;

		for (int j=0; j<45; j++) {

			if (j) {

				if (pre>cnt[j]) {

					now-=min(now, pre-cnt[j]);

					now+=cc[j];

				} else {

					now+=cnt[j]-pre;

					now+=cc[j];

				}

				if (cnt[j]==0) break;

			} else {

				if (cnt[0]<i) {ok=0;break;}

				sum-=i; pre=i;

				now+=cnt[0]-i;

			}

		}

		if (ok && !now) printf("%d ", i), flag=1;

	}

	if (!flag) puts("-1");

	return 0;

}


#include <bits/stdc++.h>

#define INF 1111111111
#define EPS 1e-8

#define MX 100005

#define sqr(x) ((x) * (x))

using namespace std;

typedef long long LL;
typedef long double LD;

template <typename T>
inline void chkmax (T& x, T y) {
   if (x < y) x = y;
}

template <typename T>
inline void chkmin (T& x, T y) {
   if (x > y) x = y;
}

int N;
LL a[MX];

LL bit[50];
int cnt[50][2];
int qut[50][2];

void init () {
	bit[0] = 1LL;
	for (int i = 1; i < 40; i ++) bit[i] = bit[i - 1] * 2LL;
}

bool can (int n) {
	int i, j;
	for (i = 0; i < 40; i ++) qut[i][0] = qut[i][1] = 0;
	for (i = 0; i < 40; i ++) {
		if (n < cnt[i][0]) qut[i][1] = cnt[i][0] - n;
		else {
			qut[i][0] = n - cnt[i][0];
			n = cnt[i][0];
		}
	}
	int tot = 0;
	for (i = 0; i < 40; i ++) {
		if (i && qut[i][0]) {
			if (qut[i][0] < tot + cnt[i][1] - cnt[i - 1][1] - cnt[i - 1][0]) {
				tot = tot + cnt[i][1] - cnt[i - 1][1] - cnt[i - 1][0] - qut[i][0];
			}
			else {
				tot = 0;
			}
		}
		else tot += qut[i][1];
	}
	return !tot;
}

int main () {

//	freopen ("in.txt", "r", stdin);
//	freopen ("out.txt", "w", stdout);

	int i, j;

	init ();

	scanf ("%d", &N);
	for (i = 0; i < N; i ++) scanf ("%lld", a + i);

	for (i = 0; i < N; i ++) {
		for (j = 0; j < 40; j ++) {
			if (bit[j] == a[i]) cnt[j][0] ++;
			if (bit[j] > a[i]) cnt[j][1] ++;
		}
	}

	int flg = 0;
	for (i = 1; i <= cnt[0][0]; i ++) {
		if (can (i)) {
			if (flg) putchar (' ');
			else flg = 1;
			printf ("%d", i);
		}
	}
	if (flg) puts ("");
	else puts ("-1");

	return 0;

}


#include<bits/stdc++.h>
using namespace std;
const int M = 100000+10;
const int N = 55;

int a[N], a1[N], b[N];

int main() {
	int n; scanf("%d", &n);
	int m = 0;
	for (int i = 1; i <= n; i++) {
		long long x; scanf("%lld", &x);
		for (int j = 0; j < N; j++) {
			if ((1LL << j) >= x) {
				if (x < (1LL << j)) a1[j]++, ++m;
				else a[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < N; i ++) {
		int cur = 0;
		for (int j = i+1; j < N; j ++) {
			if (a[j] < a[i]) break;
			cur += a[j] - a[i];
		}
		if (cur > a[i]) return puts("-1"), 0;
	}
	int out = 0;
	for (int i = m; i <= a[0]; i ++) {
		int now = i;
		for (int j = 0; j < N; j++) now = min(now, a[j]), b[j] = now;
		int sum = 0, flg = 0;
		for (int j = N - 1; j >= 0; j--) {
			sum += a1[j + 1];
			sum += a[j] - b[j];
			if (sum > b[j]) {
				flg = 1;
				break;
			}
		}
		if (!flg) out = 1, printf("%d ", i);
	}
	if (!out) puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int M = 100000+10;
const int N = 55;

int a[N], b[N];

int main() {
	int n; scanf("%d", &n);
	int m = 0;
	for (int i = 1; i <= n; i++) {
		long long x; scanf("%lld", &x);
		for (int j = 0; j < N; j++) {
			if ((1LL << j) >= x) {
				if (x < (1LL << j)) ++m;
				a[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < N; i ++) {
		int cur = 0;
		for (int j = i+1; j < N; j ++) {
			if (a[j] < a[i]) break;
			cur += a[j] - a[i];
		}
		if (cur > a[i]) return puts("-1"), 0;
	}
	int out = 0;
	for (int i = m; i <= a[0]; i ++) {
		int now = i;
		for (int j = 0; j < N; j++) now = min(now, a[j]), b[j] = now;
		int sum = 0, flg = 0;
		for (int j = N - 1; j >= 0; j--) {
			sum += a[j] - b[j];
			if (sum > b[j]) {
				flg = 1;
				break;
			}
		}
		if (!flg) out = 1, printf("%d ", i);
	}
	if (!out) puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int M = 100000+10;
const int N = 55;

int a[N], a1[N], b[N];

int main() {
	int n; scanf("%d", &n);
	int m = 0;
	for (int i = 1; i <= n; i++) {
		long long x; scanf("%lld", &x);
		for (int j = 0; j < N; j++) {
			if ((1LL << j) >= x) {
				if (x < (1LL << j)) ++a1[j];
				else a[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < N; i ++) {
		int cur = 0;
		for (int j = i+1; j < N; j ++) {
			if (a[j] < a[i]) break;
			cur += a[j] - a[i];
		}
		if (cur > a[i]) return puts("-1"), 0;
	}
	int out = 0;
	for (int i = 0; i <= a[0]; i ++) {
		int now = i;
		for (int j = 0; j < N; j++) now = min(now, a[j]), b[j] = now;
		int sum = 0, flg = 0;
		for (int j = N - 1; j >= 0; j--) {
			sum += a1[j + 1];
			sum += a[j] - b[j];
			if (sum > b[j]) {
				flg = 1;
				break;
			}
		}
		if (!flg) out = 1, printf("%d ", i);
	}
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long a[110000];

int b[41], cnt[41];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	int L = 0, R = 0;
	for (int i = 1; i <= n; i++) {
		long long x = a[i], y = x & -x;
		if (x != y) {
			for (int j = 0; j < 41; j++) if (bitl(j) >= x) {
				cnt[j]++;
				break;
			}
		} else {
			cnt[ctzl(x)]++;
		}
	}
	for (int j = 0; j < 41; j++) {
		int sum = 0;
		for (int k = j+1; k < 41; k++) {
			if (cnt[k] < cnt[j]) break;
			sum += cnt[k] - cnt[j];
		}
		if (sum > cnt[j]) return puts("-1"), 0;
	}
	R += cnt[0];
	for (int k = 0; k <= R-L; k++) {
		int cur = k;
		for (int j = 0; j < 41; j++) chkmin(cur, cnt[j]), b[j] = cur;
		int sum = 0;
		bool flg = 1;
		for (int j = 40; flg && j >= 0; j--) {
			sum += cnt[j] - b[j];
			if (sum > b[j]) flg = 0;
		}
		if (flg) {
			L += k;
			break;
		}
	}
	while (L <= R) printf("%d ", L), L++;
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long a[110000];

int b[41], cnt[41], cnt1[42];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; i++) {
		long long x = a[i];
		for (int j = 0; j < 41; j++) if (bitl(j) >= x) {
			if (bitl(j) > x) cnt1[j]++;
			else cnt[j]++;
			break;
		}
	}
	bool found = 0;
	for (int k = 0; k <= cnt[0]; k++) {
		int cur = k;
		for (int j = 0; j < 41; j++) chkmin(cur, cnt[j]), b[j] = cur;
		int sum = 0;
		bool flg = 1;
		for (int j = 40; flg && j >= 0; j--) {
			sum += max(0, cnt1[j+1] - b[j]);
			sum += cnt[j] - b[j];
			if (sum > b[j]) flg = 0;
		}
		if (flg) printf("%d ", k), found = 1;
	}
	if (!found) puts("-1");
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long a[110000];

int b[41], cnt[41];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; i++) {
		long long x = a[i];
		for (int j = 0; j < 41; j++) if (bitl(j) >= x) {
			cnt[j]++;
			break;
		}
	}
	bool found = 0;
	for (int k = 0; k <= cnt[0]; k++) {
		int cur = k;
		for (int j = 0; j < 41; j++) chkmin(cur, cnt[j]), b[j] = cur;
		int sum = 0;
		bool flg = 1;
		for (int j = 40; flg && j >= 0; j--) {
			sum += cnt[j] - b[j];
			if (sum > b[j]) flg = 0;
		}
		if (flg) printf("%d ", k), found = 1;
	}
	if (!found) puts("-1");
	return 0;
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef vector<int> VI;
typedef vector<PII> VPII;
typedef double DB;

#define pb push_back
#define mset(a, b) memset(a, b, sizeof a)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1 << (x))
#define bitl(x) (1LL << (x))
#define sqr(x) ((x) * (x))
#define sz(x) ((int)(x.size()))
#define cnti(x) (__builtin_popcount(x))
#define cntl(x) (__builtin_popcountll(x))
#define clzi(x) (__builtin_clz(x))
#define clzl(x) (__builtin_clzll(x))
#define ctzi(x) (__builtin_ctz(x))
#define ctzl(x) (__builtin_ctzll(x))

#define X first
#define Y second

#define Error(x) cout << #x << " = " << x << endl

template <typename T, typename U>
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}

template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

long long a[110000];

int b[41], cnt[41], cnt1[42];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
	for (int i = 1; i <= n; i++) {
		long long x = a[i];
		for (int j = 0; j < 41; j++) if (bitl(j) >= x) {
			if (bitl(j) > x) cnt1[j]++;
			else cnt[j]++;
			break;
		}
	}
	bool found = 0;
	for (int k = 0; k <= cnt[0]; k++) {
		int cur = k;
		for (int j = 0; j < 41; j++) chkmin(cur, cnt[j]), b[j] = cur;
		int sum = 0;
		bool flg = 1;
		for (int j = 40; flg && j >= 0; j--) {
			sum += cnt1[j+1];
			sum += cnt[j] - b[j];
			if (sum > b[j]) flg = 0;
		}
		if (flg) printf("%d ", k), found = 1;
	}
	if (!found) puts("-1");
	return 0;
}


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

vector < int > all;
long long pw[LIM + 3];
int a[LIM + 3] , b[LIM + 3] , n;

void prepare(){
	pw[0] = 1;
	for(int i = 1 ; i <= LIM ; i++) pw[i] = pw[i - 1]*2;
}

void input(){
	cin>>n;
	for(int i = 1 ; i <= n ; i++){
		long long x;
		cin>>x;
		bool ck = false;
		for(int j = 0 ; j <= LIM ; j++)	if(x == pw[j]){
			a[j]++;
			ck = true;
			break;
		}
		if(!ck){
			for(int j = 0 ; j <= LIM ; j++) if(2*pw[j] >= x){
				b[j]++;
				ck = true;
				break;
			}
		}
	}
}

bool ck(int Len){
	if(Len > a[0])	return false;
	b[0] += (a[0] - Len); a[0] = Len;
	for(int i = 1 ; i <= LIM ; i++)
		if(a[i] > a[i - 1]){
			b[i - 1] += (a[i] - a[i - 1]);
			a[i] = a[i - 1];
		}
	int need = 0 , cur = 0;
	for(int i = LIM ; i >= 0 ; i--){
		need += b[i];
		cur += (a[i] - a[i + 1]);
		if(need > cur)	return false;
	}
	return true;
}

int main(){
//	freopen("test.inp","r",stdin);
	prepare();
	input();
	for(int i = n ; i >= 1 ; i--)	if(ck(i))	all.push_back(i);
	if(all.size() == 0)	cout<<-1;
	else for(int i = all.size() - 1 ; i >= 0 ; i--)	cout<<all[i]<<' ';
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;sort(ai+1,ai+n+1);
    PER(i,n,1) {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0 || (1LL<<(mx+1))<ai[i]) {
            printf("-1\n");return 0;
        }
        REP(j,0,mx) cnt[j]--;
    }
    int r=cnt[0],l=0;
    while(cnt[0]) {
        while(mx>=0 && !cnt[mx]) mx--;++l;
        int ps=0;
        REP(j,0,mx) {
            cnt[j]--;if(cnt[j]>cnt[ps]) ps=j;
        } if(cnt[ps]) cnt[ps]--;
    } REP(i,l,r) printf("%d ",i+n);putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;
    sort(ai+1,ai+n+1);
    int s=0;
    do {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0) {
            if(!n) printf("%d\n",s);
            else printf("-1\n");return 0;
        }
        while(n>=1 && ai[n]>(1LL<<mx)) {
            ++s;--n;REP(j,0,mx) cnt[j]--;
        }
        REP(j,0,mx) if(cnt[j]<0) {
            printf("-1\n");return 0;
        }
    } while(!cnt[mx]);
    REP(i,1,n) {
        REP(j,0,60) if(ai[i]<=(1LL<<j)) {
            bi[j]++;break;
        }
    } int res=0;
    REP(i,1,cnt[0]) if(i>=cnt[0]-i+n) {
        REP(j,0,mx) ci[j]=bi[j];
        int now=i,fl=1,su=0;
        REP(j,0,mx) {
            su+=ci[j];
            int k=now-cnt[j];
            if(k<0) su+=-k;
            else {
                su-=k;
                now=cnt[j];
            }
        }
        if(now<su) continue;
        printf("%d ",i);++res;
    } if(!res) printf("-1\n"); else putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;
    sort(ai+1,ai+n+1);
    int s=0;
    do {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0) {
            if(!n) printf("%d\n",s);
            else printf("-1\n");return 0;
        }
        while(n>=1 && ai[n]>(1LL<<mx)) {
            ++s;--n;REP(j,0,mx) cnt[j]--;
        }
        REP(j,0,mx) if(cnt[j]<0) {
            printf("-1\n");return 0;
        }
    } while(!cnt[mx]);
    REP(i,1,n) {
        REP(j,0,60) if(ai[i]<=(1LL<<j)) {
            bi[j]++;break;
        }
    } int res=0;
    REP(i,1,cnt[0]) if(i>=cnt[0]-i+n) {
        REP(j,0,mx) ci[j]=bi[j];
        int now=i;
        REP(j,0,mx) {
            su+=ci[j];
            int k=now-cnt[j];
            if(k<0) su+=-k;
            else {
                su-=k;
                now=cnt[j];
            }
        }
        if(now<su) continue;
        printf("%d ",i);++res;
    } if(!res) printf("-1\n"); else putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;sort(ai+1,ai+n+1);
    PER(i,n,1) {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0 || (1LL<<(mx+1))<ai[i]) {
            printf("-1\n");return 0;
        }
        REP(j,0,mx) cnt[j]--;
    }

    int r=cnt[0],l=0;
    while(cnt[0]) {
        while(mx>=0 && !cnt[mx]) mx--;++l;
        int ps=0;
        REP(j,0,mx) {
            cnt[j]--;if(cnt[j]>=cnt[ps]) ps=j;
        } if(cnt[ps]) cnt[ps]--;
    } REP(i,l,r) printf("%d ",i+n);putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;
    sort(ai+1,ai+n+1);
    int s=0;
    do {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0) {
            if(!n) printf("%d\n",s);
            else printf("-1\n");return 0;
        }
        while(n>=1 && ai[n]>(1LL<<mx)) {
            ++s;--n;REP(j,0,mx) cnt[j]--;
        }
        REP(j,0,mx) if(cnt[j]<0) {
            printf("-1\n");return 0;
        }
    } while(!cnt[mx]);
    REP(i,1,n) {
        REP(j,0,60) if(ai[i]<=(1LL<<j)) {
            bi[j]++;break;
        }
    } int res=0;
    REP(i,1,cnt[0]) if(i>=cnt[0]-i+n) {
        REP(j,0,mx) ci[j]=bi[j];
        int now=i,su=0;
        REP(j,0,mx) {
            su+=ci[j];
            int k=now-cnt[j];
            if(k<0) su+=-k;
            else {
                su-=k;
                now=cnt[j];
            }
        } //printf("%d : %d %d %d\n",i,now,su,s);
        if(now<su || su<0) continue;
        printf("%d ",i+s);++res;
    } if(!res) printf("-1\n"); else putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;
    sort(ai+1,ai+n+1);
    int s=0;
    do {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0) {
            if(!n) printf("%d\n",s);
            else printf("-1\n");return 0;
        }
        while(n>=1 && ai[n]>(1LL<<mx)) {
            ++s;--n;REP(j,0,mx) cnt[j]--;
        }
        REP(j,0,mx) if(cnt[j]<0) {
            printf("-1\n");return 0;
        }
    } while(!cnt[mx]);
    REP(i,1,n) {
        REP(j,0,60) if(ai[i]<=(1LL<<j)) {
            bi[j]++;break;
        }
    } int res=0;
    REP(i,1,cnt[0]) if(i>=cnt[0]-i+n) {
        REP(j,0,mx) ci[j]=bi[j];
        int now=i,su=0;
        REP(j,0,mx) {
            su+=ci[j];
            int k=now-cnt[j];
            if(k<0) su+=-k;
            else {
                su-=k;
                now=cnt[j];
            }
        }
        if(now<su) continue;
        printf("%d ",i+s);++res;
    } if(!res) printf("-1\n"); else putchar('\n');
    return 0;
}


#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
LL ai[maxn];
int cnt[100],bi[100],ci[100];

inline int chk(LL x) {
    int cnt=0;
    while(x%2==0) x/=2,++cnt;
    if(x>1) return -1; return cnt;
}

int main() {
    int n,tot=0;
    read(n);
    REP(i,1,n) {
        LL x;
        read(x);
        int g=chk(x);
        if(g>=0) cnt[g]++;
        else ai[++tot]=x;
    }
    int mx=60;
    while(mx>=0 && !cnt[mx]) mx--;
    REP(i,1,mx) {
        int dt=max(0,cnt[i]-cnt[i-1]);cnt[i]-=dt;
        while(dt--) ai[++tot]=(1LL<<i);
    } n=tot;
    sort(ai+1,ai+n+1);
    int s=0;
    do {
        while(mx>=0 && !cnt[mx]) mx--;
        if(mx<0) {
            if(!n) printf("%d\n",s);
            else printf("-1\n");return 0;
        }
        while(n>=1 && ai[n]>(1LL<<mx)) {
            ++s;--n;REP(j,0,mx) cnt[j]--;
        }
        REP(j,0,mx) if(cnt[j]<0) {
            printf("-1\n");return 0;
        }
    } while(!cnt[mx]);
    REP(i,1,n) {
        REP(j,0,60) if(ai[i]<=(1LL<<j)) {
            bi[j]++;break;
        }
    } int res=0;
    REP(i,1,cnt[0]) if(i>=cnt[0]-i+n) {
        REP(j,0,mx) ci[j]=bi[j];
        int now=i,su=0;
        REP(j,0,mx) {
            su+=ci[j];
            int k=now-cnt[j];
            if(k<0) su+=-k;
            else {
                su-=k;
                now=cnt[j];
            }
        }
        if(now<su) continue;
        printf("%d ",i);++res;
    } if(!res) printf("-1\n"); else putchar('\n');
    return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int tot1[N],tot2[N],tot[N];
int n;

il bool check(int x){
	tot[0]=x;
	rep(i,1,40) tot[i]=qmin(tot[i-1],tot1[i]);
	int s=0;
	per(i,40,0){
		s+=tot1[i]-tot[i]+tot2[i];
		if(s>tot[i]) return false;
	}
	return true;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		ll x;
		scanf("%lld",&x);
		int id=-1,dig=0;
		while(x){
			dig+=x&1;
			++id;
			x>>=1;
		}
		if(dig==1) ++tot1[id];else ++tot2[id];
	}
	int ul=0,ur=tot1[0]+1;
	while(ur-ul>1){
		int mid=ul+ur>>1;
		if(check(mid)) ur=mid;else ul=mid;
	}
	if(ur>tot1[0]) return puts("-1"),0;
	rep(i,ur,tot1[0]) printf("%d ",i);
	puts("");
	return 0;
}


#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int tot1[N],tot2[N],tot[N];
int n;

il bool check(int x){
	tot[0]=x;
	rep(i,1,40) tot[i]=qmin(tot[i-1],tot1[i]);
	int s=0;
	per(i,40,1){
		s+=tot1[i]-tot[i]+tot2[i];
		if(s>tot[i]) return false;
	}
	return true;
}

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		int x;
		scanf("%d",&x);
		int id=-1,dig=0;
		while(x){
			dig+=x&1;
			++id;
			x>>=1;
		}
		if(dig==1) ++tot1[id];else ++tot2[id];
	}
	int ul=0,ur=tot1[0]+1;
	while(ur-ul>1){
		int mid=ul+ur>>1;
		if(check(mid)) ur=mid;else ul=mid;
	}
	if(ur>tot1[0]) return puts("-1"),0;
	rep(i,ur,tot1[0]) printf("%d ",i);
	puts("");
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxb = 42;

int cnt[Maxb];
multiset <ll> S;
int n;
int A, B;
vector <int> V;

int getPw(ll a)
{
	for (ll i = 0; i < Maxb; i++)
		if (a == 1ll << i) return i;
	return -1;
}

bool Check()
{
	for (int i = 0; i + 1 < Maxb; i++)
		for (int j = cnt[i]; j > cnt[i + 1]; j--) {
			ll got = 1ll << ll(i + 1);
			multiset <ll>::iterator it = S.upper_bound(got);
			if (it != S.begin()) {
				it--; S.erase(it);
			}
		}
	return S.empty();
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		ll a; scanf("%I64d", &a);
		int p = getPw(a);
		if (p == -1) { B++; S.insert(a); }
		else cnt[p]++;
	}
	for (int i = 0; i + 1 < Maxb; i++)
		while (cnt[i] < cnt[i + 1]) {
			B++; S.insert(1ll << ll(i + 1));
			cnt[i + 1]--;
		}
	if (!Check()) { printf("-1\n"); return 0; }
	for (int i = 0; i + 1 < Maxb; i++)
		A += cnt[i] - cnt[i + 1];
	while (A >= B) {
		V.push_back(A);
		for (int i = 0; i + 1 < Maxb; i++)
			if (cnt[i] > cnt[i + 1]) {
				A--;
				for (int j = 0; j <= i; j++) {
					cnt[j]--; B++;
				}
				break;
			}
	}
	if (V.empty()) printf("-1\n");
	else {
		sort(V.begin(), V.end());
		for (int i = 0; i < V.size(); i++)
			printf("%d%c", V[i], i + 1 < V.size()? ' ': '\n');
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxb = 42;

int cnt[Maxb];
multiset <ll> S;
int n;
int A, B;
vector <int> V;

int getPw(ll a)
{
	for (ll i = 0; i < Maxb; i++)
		if (a == 1ll << i) return i;
	return -1;
}

bool Check()
{
	for (int i = 0; i + 1 < Maxb; i++)
		for (int j = cnt[i]; j > cnt[i + 1]; j--) {
			ll got = 1ll << ll(i + 1);
			multiset <ll>::iterator it = S.lower_bound(got);
			if (it != S.begin()) {
				it--; S.erase(it);
			}
		}
	return S.empty();
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		ll a; scanf("%I64d", &a);
		int p = getPw(a);
		if (p == -1) { B++; S.insert(a); }
		else cnt[p]++;
	}
	for (int i = 0; i + 1 < Maxb; i++)
		while (cnt[i] < cnt[i + 1]) {
			B++; S.insert(1ll << ll(i + 1));
			cnt[i + 1]--;
		}
	if (!Check()) { printf("-1\n"); return 0; }
	for (int i = 0; i + 1 < Maxb; i++)
		A += cnt[i] - cnt[i + 1];
	while (A >= B) {
		V.push_back(A);
		for (int i = 0; i + 1 < Maxb; i++)
			if (cnt[i] > cnt[i + 1]) { A--; cnt[i]--; B += (i + 1); break; }
	}
	if (V.empty()) printf("-1\n");
	else {
		sort(V.begin(), V.end());
		for (int i = 0; i < V.size(); i++)
			printf("%d%c", V[i], i + 1 < V.size()? ' ': '\n');
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxb = 42;

int cnt[Maxb];
multiset <ll> S;
int n;
int A, B;
vector <int> V;

int getPw(ll a)
{
	for (ll i = 0; i < Maxb; i++)
		if (a == 1ll << i) return i;
	return -1;
}

bool Check()
{
	for (int i = 0; i + 1 < Maxb; i++)
		for (int j = cnt[i]; j > cnt[i + 1]; j--) {
			ll got = 1ll << ll(i + 1);
			multiset <ll>::iterator it = S.upper_bound(got);
			if (it != S.begin()) {
				it--; S.erase(it);
			}
		}
	return S.empty();
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		ll a; scanf("%I64d", &a);
		int p = getPw(a);
		if (p == -1) { B++; S.insert(a); }
		else cnt[p]++;
	}
	for (int i = 0; i + 1 < Maxb; i++)
		while (cnt[i] < cnt[i + 1]) {
			B++; S.insert(1ll << ll(i + 1));
			cnt[i + 1]--;
		}
	if (!Check()) { printf("-1\n"); return 0; }
	for (int i = 0; i + 1 < Maxb; i++)
		A += cnt[i] - cnt[i + 1];
	while (A >= B) {
		V.push_back(A);
		for (int i = 0; i + 1 < Maxb; i++)
			if (cnt[i] > cnt[i + 1]) { A--; cnt[i]--; B += (i + 1); break; }
	}
	if (V.empty()) printf("-1\n");
	else {
		sort(V.begin(), V.end());
		for (int i = 0; i < V.size(); i++)
			printf("%d%c", V[i], i + 1 < V.size()? ' ': '\n');
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxn 100005
#define maxs 55
#define ll long long
using namespace std;

ll a[maxn];

int cnt1[maxs],cnt2[maxs];

int n;

int ans[maxn];

int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%I64d",&a[i]);
	ll wz=0;
	fo(i,1,n) {
		while ((1 << wz)<a[i]) wz++;
		cnt2[wz]++;
		if (a[i]==(1 << wz)) cnt1[wz]++;
	}
	fo(i,1,cnt1[0]){
		int nowg=i;
		int totl=0;
		fo(j,0,wz+1) {
			totl+=cnt2[j]-nowg;
			if (totl<0) totl=0;
			nowg=min(nowg,cnt1[j]);
		}
		if (totl<=0) ans[++ans[0]]=i;
	}
	if (ans[0]==0) ans[++ans[0]]=-1;
	fo(i,1,ans[0]) printf("%d ",ans[i]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxn 100005
#define maxs 55
#define ll long long
using namespace std;

ll a[maxn];

int cnt1[maxs],cnt2[maxs];

int n;

int ans[maxn];

int main(){
	scanf("%d",&n);
	fo(i,1,n) scanf("%I64d",&a[i]);
	ll wz=0;
	fo(i,1,n) {
		while ((1ll << wz)<a[i]) wz++;
		cnt2[wz]++;
		if (a[i]==(1ll << wz)) cnt1[wz]++;
	}
	fo(i,1,cnt1[0]){
		int nowg=i;
		int totl=0;
		fo(j,0,wz+1) {
			totl+=cnt2[j]-nowg;
			if (totl<0) totl=0;
			nowg=min(nowg,cnt1[j]);
		}
		if (totl<=0) ans[++ans[0]]=i;
	}
	if (ans[0]==0) ans[++ans[0]]=-1;
	fo(i,1,ans[0]) printf("%d ",ans[i]);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 100005

ll n, num = 0;
ll a[maxn], d[maxn];

bool can(int x){
	ll cur = x, le = 0, need = 1;
	For(i, 1, n){
		if(a[i] == a[i - 1]) continue;
		if(a[i] == need){
			if(d[i] >= cur){
				le += d[i] - cur;
			} else{
				le = max(0ll, le - (cur - d[i]));
				cur = d[i];
			}
			need += need;
		} else{
			le += d[i];
		}
	}
	return cur >= le;
}

int main()
{
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	For(i, 1, n){
		cin >> a[i];
		if(a[i] == 1) num++;
	}

	a[n + 1] = -1;
	a[0] = -1;
	Ford(i, n, 1){
		if(a[i] == a[i + 1]) d[i] = d[i + 1] + 1;
		else d[i] = 1;
	}

	ll l = 0, r = num + 1, mid;

	while(l < r){
		mid = (l + r) >> 1;
		if(can(mid)) r = mid;
		else l = mid + 1;
	}
	if(l > num){
		cout << -1 << endl;
	}
	else{
		For(i, l, num) cout << i << " ";
	}

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define eps 1e-12
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 100005

ll n, num = 0;
ll a[maxn], d[maxn];

bool can(int x){
	ll cur = x, le = 0, need = 1;
	For(i, 1, n){
		if(a[i] > need) return 0;
		if(a[i] == a[i - 1]) continue;
		if(a[i] == need){
			if(d[i] >= cur){
				le += d[i] - cur;
			} else{
				le = max(0ll, le - (cur - d[i]));
				cur = d[i];
			}
			need += need;
		} else{
			le += d[i];
		}
	}
	return cur >= le;
}

int main()
{
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	For(i, 1, n){
		cin >> a[i];
		if(a[i] == 1) num++;
	}

	a[n + 1] = -1;
	a[0] = -1;
	Ford(i, n, 1){
		if(a[i] == a[i + 1]) d[i] = d[i + 1] + 1;
		else d[i] = 1;
	}

	ll l = 0, r = num + 1, mid;

	while(l < r){
		mid = (l + r) >> 1;
		if(can(mid)) r = mid;
		else l = mid + 1;
	}
	if(l > num){
		cout << -1 << endl;
	}
	else{
		For(i, l, num) cout << i << " ";
	}

  return 0;
}


// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

LL a[100111];
int n,cnt[45],ck[45],tcnt[45],tck[45];
bool check(int x)
{
	int mn=x;memcpy(tck,ck,sizeof(tck));
	for(int i=0;i<45;i++)
	{
		if(cnt[i]>mn)
		{
			tcnt[i]=mn;
			tck[i+1]+=cnt[i]-mn;
		}
		else
			tcnt[i]=mn=cnt[i];
	}
	int use=0;
	for(int j=43;j>=0;j--)
	{
		if(tcnt[j]-use<tck[j+1])return false;
		use+=tck[j+1];
	}
	return true;
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		get1(a[i]);
		int t=0;
		while((1ll<<t)<a[i])t++;
		if((1ll<<t)==a[i])cnt[t]++;
		else ck[t]++;
	}
	bool ok=0;
	for(int i=1;i<=cnt[0];i++)
	{
		if(check(i))
		{
			ok=1;
			printf("%d ",i);
		}
	}
	if(!ok)puts("-1");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1015
#define MP make_pair
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lp(i,n) for(int i=0;i<n;i++)
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
const double EPS = 1e-9;

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
#define N (100*K)
int n,m,k;
ll arr[N];
ll numpo[N];
ll fail[N];
ll ex[N];
vector<int> ans;
int main() {
    //read();
    //FASTIO;
    int n;
    int po=0;
    ll tmp=1;
    cin>>n;
    int maxpo=-1;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        while(tmp<x)tmp*=2,po++;
        if(x==tmp){
            numpo[po]++;
        }
        else
            fail[po]++;
            maxpo=po;
    }
    if(maxpo==-1){
        cout<<-1<<endl;
        return 0;
    }
    ll taken=0;
    for(int i=maxpo;i>=0;i--){
        ex[i]=numpo[i]-taken;
        taken+=ex[i];
        if(ex[i]<0){
            cout<<-1<<endl;
            return 0;
        }
    }
    int cur=0;
    for(int j=numpo[0];j>0;j--){
        ll tmp=fail[0];
        for(int i=0;i<maxpo+5;i++){
           // cout<<ex[i]<<" "<<fail[i]<<" "<<tmp<<" "<<endl;
            tmp+=fail[i+1];
            tmp-=ex[i];
            tmp=max(tmp,0ll);
        }
       // cout<<tmp<<" "<<j<<" "; cin>>m;
        if(tmp==0)
            ans.push_back(j);
        else
            break;
        bool done=0;
        while(ex[cur]!=0){
            if(cur==maxpo+5){
                done=1;
                break;
            }
            cur++;
        }
        if(done)break;
        ex[cur]--;
        for(int i=0;i<=cur;i++)fail[cur]++;
    }
    if(ans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1015
#define MP make_pair
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lp(i,n) for(int i=0;i<n;i++)
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
const double EPS = 1e-9;

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
#define N (100*K)
int n,m,k;
ll arr[N];
ll numpo[N];
ll fail[N];
ll ex[N];
void show(int maxpo){
      for(int i=0;i<maxpo+5;i++)
           cout<<i<<": "<<ex[i]<<" "<<fail[i]<<" "<<endl;
}
vector<int> ans;
int main() {
    //read();
    //FASTIO;
    int n;
    int po=0;
    ll tmp=1;
    cin>>n;
    int maxpo=-1;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        while(tmp<x)tmp*=2,po++;
        if(x==tmp){
            numpo[po]++;
        }
        else
            fail[po]++;
            maxpo=po;
    }
    ll taken=0;
    for(int i=0;i<maxpo+5;i++){
        if(numpo[i+1]>numpo[i]){
            fail[i+1]+=numpo[i+1]-numpo[i];
            numpo[i+1]=numpo[i];
        }
    }
    for(int i=maxpo;i>=0;i--){
        ex[i]=numpo[i]-taken;
        taken+=ex[i];
    }
    int cur=0;
    for(int j=numpo[0];j>0;j--){
        ll tmp=fail[0];
        show(maxpo+5);
        for(int i=0;i<maxpo+5;i++){
           tmp+=fail[i+1];
            tmp-=ex[i];
            tmp=max(tmp,0ll);
        }
       // cout<<tmp<<" "<<j<<" "; cin>>m;
        if(tmp==0)
            ans.push_back(j);
        else
            break;
        bool done=0;
        while(ex[cur]==0){
            if(cur==maxpo+5){
                done=1;
                break;
            }
            cur++;
        }
        if(done)break;
        ex[cur]--;
        for(int i=0;i<=cur;i++)fail[i]++;
    }
    if(ans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1015
#define MP make_pair
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lp(i,n) for(int i=0;i<n;i++)
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
const double EPS = 1e-9;

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
#define N (100*K)
int n,m,k;
ll arr[N];
ll numpo[N];
ll fail[N];
ll ex[N];
void show(int maxpo){
      for(int i=0;i<maxpo+5;i++)
           cout<<i<<": "<<ex[i]<<" "<<fail[i]<<" "<<endl;
}
vector<int> ans;
int main() {
    //read();
    //FASTIO;
    int n;
    int po=0;
    ll tmp=1;
    cin>>n;
    int maxpo=-1;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        while(tmp<x)tmp*=2,po++;
        if(x==tmp){
            numpo[po]++;
        }
        else
            fail[po]++;
            maxpo=po;
    }
    ll taken=0;
    for(int i=0;i<maxpo+5;i++){
        if(numpo[i+1]>numpo[i]){
            fail[i+1]+=numpo[i+1]-numpo[i];
            numpo[i+1]=numpo[i];
        }
    }
    for(int i=maxpo;i>=0;i--){
        ex[i]=numpo[i]-taken;
        taken+=ex[i];
    }
    int cur=0;
    for(int j=numpo[0];j>0;j--){
        ll tmp=fail[0];
     ///   show(maxpo+5);
        for(int i=0;i<maxpo+5;i++){
           tmp+=fail[i+1];
            tmp-=ex[i];
            tmp=max(tmp,0ll);
        }
       // cout<<tmp<<" "<<j<<" "; cin>>m;
        if(tmp==0)
            ans.push_back(j);
        else
            break;
        bool done=0;
        while(ex[cur]==0){
            if(cur==maxpo+5){
                done=1;
                break;
            }
            cur++;
        }
        if(done)break;
        ex[cur]--;
        for(int i=0;i<=cur;i++)fail[i]++;
    }
    if(ans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1015
#define MP make_pair
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lp(i,n) for(int i=0;i<n;i++)
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
const double EPS = 1e-9;

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
#define N (100*K)
int n,m,k;
ll arr[N];
ll numpo[N];
ll fail[N];
ll ex[N];
void show(int maxpo){
      for(int i=0;i<maxpo+5;i++)
           cout<<i<<": "<<ex[i]<<" "<<fail[i]<<" "<<endl;
}
vector<int> ans;
int main() {
    //read();
    //FASTIO;
    int n;
    int po=0;
    ll tmp=1;
    cin>>n;
    int maxpo=-1;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        while(tmp<x)tmp*=2,po++;
        if(x==tmp){
            numpo[po]++;
        }
        else
            fail[po]++;
            maxpo=po;
    }
    if(maxpo==-1){
        cout<<-1<<endl;
        return 0;
    }
    ll taken=0;
    for(int i=maxpo;i>=0;i--){
        ex[i]=numpo[i]-taken;
        taken+=ex[i];
        if(ex[i]<0){
            cout<<-1<<endl;
            return 0;
        }
    }
    int cur=0;
    for(int j=numpo[0];j>0;j--){
        ll tmp=fail[0];
    //    show(maxpo+5);
        for(int i=0;i<maxpo+5;i++){
           tmp+=fail[i+1];
            tmp-=ex[i];
            tmp=max(tmp,0ll);
        }
       // cout<<tmp<<" "<<j<<" "; cin>>m;
        if(tmp==0)
            ans.push_back(j);
        else
            break;
        bool done=0;
        while(ex[cur]==0){
            if(cur==maxpo+5){
                done=1;
                break;
            }
            cur++;
        }
        if(done)break;
        ex[cur]--;
        for(int i=0;i<=cur;i++)fail[i]++;
    }
    if(ans.size()==0){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define K 1015
#define MP make_pair
#define F first
#define S second
#define FASTIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define lp(i,n) for(int i=0;i<n;i++)
const long long MOD = 1e9 + 7;
const long long mod = 1e9 + 7;
const double EPS = 1e-9;

void read() {
    freopen("in", "r", stdin);
}
typedef long long ll;
typedef pair<int, int> pi;
#define N (100*K)
int n,m,k;
ll arr[N];
ll numpo[N];
ll fail[N];
ll ex[N];
vector<int> ans;
int main() {
    //read();
    //FASTIO;
    int n;
    int po=0;
    ll tmp=1;
    cin>>n;
    int maxpo=-1;
    for(int i=0;i<n;i++){
        ll x;
        cin>>x;
        while(tmp<x)tmp*=2,po++;
        if(x==tmp){
            numpo[po]++;
        }
        else
            fail[po]++;
            maxpo=po;
    }
    if(maxpo==-1){
        cout<<-1<<endl;
        return 0;
    }
    ll taken=0;
    for(int i=maxpo;i>=0;i--){
        ex[i]=numpo[i]-taken;
        taken+=ex[i];
        if(ex[i]<0){
            cout<<-1<<endl;
            return 0;
        }
    }
    int cur=0;
    for(int j=numpo[0];j>0;j--){
        ll tmp=fail[0];
        for(int i=0;i<maxpo+5;i++){
           // cout<<ex[i]<<" "<<fail[i]<<" "<<tmp<<" "<<endl;
            tmp+=fail[i+1];
            tmp-=ex[i];
            tmp=max(tmp,0ll);
        }
       // cout<<tmp<<" "<<j<<" "; cin>>m;
        if(tmp==0)
            ans.push_back(j);
        else
            break;
        bool done=0;
        while(ex[cur]!=0){
            if(cur==maxpo+5){
                done=1;
                break;
            }
            cur++;
        }
        if(done)break;
        ex[cur]--;
        for(int i=0;i<=cur;i++)fail[cur]++;
    }
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<" ";
    return 0;
}


import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static int status(int start, int a, int b, int t){
        if(b > t)
            return start;
        if (b == t)
            return (start + 1) % 2;
        int x = (t - b) / a;
        return (start + x) % 2;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String lamps = scanner.next();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int max = 0, current;
        for (int i = 0; i <= 33554437; i++) {
            current = 0;
            for (int j = 0; j < n; j++)
                current += status(lamps.charAt(j) - '0', a[j], b[j], i);
            max = Math.max(max, current);
        }
        System.out.println(max);

    }
}


import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static int status(int start, int a, int b, int t){
        if(b + a > t)
            return start;
        int x = (t - b) / a;
        return (start + x) % 2;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String lamps = scanner.next();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int max = 0, current;
        for (int i = 0; i <= 1E6; i++) {
            current = 0;
            for (int j = 0; j < n; j++)
                current += status(lamps.charAt(j) - '0', a[j], b[j], i);
            max = Math.max(max, current);
        }
        System.out.println(max);

    }
}


import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static int status(int start, int a, int b, int t){
        if(b > t)
            return start;
        int x = (t - b) / a;
        if (x == 0)
            return (start + 1) % 2;
        return (start + x) % 2;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String lamps = scanner.next();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int max = 0, current;
        for (int i = 0; i <= 1E6; i++) {
            current = 0;
            for (int j = 0; j < n; j++) {
                current += status(lamps.charAt(j) - '0', a[j], b[j], i);
            }
            max = Math.max(max, current);
        }
        System.out.println(max);

    }
}


import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    private static int status(int start, int a, int b, int t) {
        if (b > t)
            return start;
        int x = (t - b) / a;
        x += 1;
        return (start + x) % 2;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        String lamps = scanner.next();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            b[i] = scanner.nextInt();
        }
        int max = 0, current;
        for (int i = 0; i <= 1E6; i++) {
            current = 0;
            for (int j = 0; j < n; j++) {
                current += status(lamps.charAt(j) - '0', a[j], b[j], i);
            }
            max = Math.max(max, current);
        }
        System.out.println(max);

    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Koala_and_Lights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int[][] ar=new int[n][2];

        for(int i=0;i<n;i++){
            ar[i][0]=sc.nextInt();
            ar[i][1]=sc.nextInt();
        }
        String tt="";
        int max=0;
        for(int i=0;i<s.length();i++){
            String temp=s.charAt(i)+"";
            tt=temp+tt;
            if(temp.equals(1)){
                max++;
            }
        }
        if(max==n)
        {
            System.out.println(n);
        }
        else{
            int[][] val=new int[n][600];
            for(int k=0;k<n;k++){
                for(int l=0;l<550;l++){
                    val[k][l]=0;
                }
            }

            for(int i=0;i<n;i++)
            {
                String temp=s.charAt(i)+"";
                int toggle=ar[i][0];
                int start=ar[i][1];
                int j=0;
                boolean flag=true;
                if(temp.equals("1"))
                {
                    boolean tog=false;
                    while(j<=550)
                    {
                        if(flag)
                        {
                            for(int k=j;k<start;k++)
                            {
                                val[i][k]=1;
                            }
                            flag=false;
                            j=j+start;
                            tog=true;
                        }
                        if(tog){
                            j=j+toggle;
                            tog=false;
                        }

                        else
                        {
                            for(int k=j;k<j+toggle;k++)
                            {
                                val[i][k]=1;
                            }
                            j=j+toggle;
                            tog=true;
                        }

                    }

                }
                else
                    {
                    boolean tog=true;
                    while(j<=550){
                        if(flag){
                            j=j+start;
                            flag=false;
                        }
                        else
                        {
                            if(tog){
                                for(int k=j;k<j+toggle;k++){
                                    val[i][k]=1;
                                }
                                j=j+toggle;
                                tog=false;
                            }
                            else{
                                tog=true;
                                j=j+toggle;
                            }

                        }
                    }
                }
            }

            int count=0;

            for(int i=0;i<550;i++){
                for(int j=0;j<n;j++){
                    if(val[j][i]==1){
                        count++;
                    }
                }
                max=Math.max(max,count);
                count=0;

            }
            System.out.println(max);
        }

    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class Koala_and_Lights {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int[][] ar=new int[n][2];

        for(int i=0;i<n;i++){
            ar[i][0]=sc.nextInt();
            ar[i][1]=sc.nextInt();
        }
        String tt="";
        int max=0;
        for(int i=0;i<s.length();i++){
            String temp=s.charAt(i)+"";
            tt=temp+tt;
            if(temp.equals(1)){
                max++;
            }
        }
        if(max==n)
        {
            System.out.println(n);
        }
        else{
            s=tt;
            int[][] val=new int[n][30];
            for(int k=0;k<n;k++){
                for(int l=0;l<30;l++){
                    val[k][l]=0;
                }
            }

            for(int i=0;i<n;i++)
            {
                String temp=s.charAt(i)+"";
                int toggle=ar[i][0];
                int start=ar[i][1];
                int j=0;
                boolean flag=true;
                if(temp.equals("1"))
                {
                    boolean tog=false;
                    while(j<=20)
                    {
                        if(flag)
                        {
                            for(int k=j;k<start;k++)
                            {
                                val[i][k]=1;
                            }
                            flag=false;
                            j=j+start;
                            tog=true;
                        }
                        if(tog){
                            j=j+toggle;
                            tog=false;
                        }

                        else
                        {
                            for(int k=j;k<j+toggle;k++)
                            {
                                val[i][k]=1;
                            }
                            j=j+toggle;
                            tog=true;
                        }

                    }

                }
                else
                    {
                    boolean tog=true;
                    while(j<=20){
                        if(flag){
                            j=j+start;
                            flag=false;
                        }
                        else
                        {
                            if(tog){
                                for(int k=j;k<j+toggle;k++){
                                    val[i][k]=1;
                                }
                                j=j+toggle;
                                tog=false;
                            }
                            else{
                                tog=true;
                                j=j+toggle;
                            }

                        }
                    }
                }

            }
            int count=0;

            for(int i=0;i<20;i++){
                for(int j=0;j<n;j++){
                    if(val[j][i]==1){
                        count++;
                    }
                }
                max=Math.max(max,count);
                count=0;

            }
            System.out.println(max);
        }

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{       static PrintWriter out=new PrintWriter(System.out);static FastScanner in = new FastScanner(System.in);static class FastScanner {BufferedReader br;StringTokenizer stok;FastScanner(InputStream is) {br = new BufferedReader(new InputStreamReader(is));}
        String next() throws IOException {while (stok == null || !stok.hasMoreTokens()) {String s = br.readLine();if (s == null) {return null;}
                stok = new StringTokenizer(s);}return stok.nextToken();}
        int ni() throws IOException {return Integer.parseInt(next());}long nl() throws IOException {return Long.parseLong(next());}double nd() throws IOException {return Double.parseDouble(next());}char nc() throws IOException {return (char) (br.read());}String ns() throws IOException {return br.readLine();}
        int[] nia(int n) throws IOException{int a[] = new int[n];for (int i = 0; i < n; i++)a[i] = ni();return a;}long[] nla(int n) throws IOException {long a[] = new long[n];for (int i = 0; i < n; i++)a[i] = nl();return a;}
        double[] nda(int n)throws IOException {double a[] = new double[n];for (int i = 0; i < n; i++)a[i] = nd();return a;}int [][] imat(int n,int m) throws IOException{int mat[][]=new int[n][m];for(int i=0;i<n;i++){for(int j=0;j<m;j++)mat[i][j]=ni();}return mat;}
    }
	static long mod=Long.MAX_VALUE;
	public static void main (String[] args) throws java.lang.Exception
	{   int i,j;
	    HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
		/*  if(hm.containsKey(z))
		        hm.put(z,hm.get(z)+1);
		    else
		        hm.put(z,1);
		 */
        ArrayList<Integer> arr=new ArrayList<Integer>();
        HashSet<Integer> set=new HashSet<Integer>();
        PriorityQueue<Integer> pq=new PriorityQueue<Integer>();
        int n=in.ni();
        String s=in.next();
        int a[][]=new int[n][500];
        for(i=0;i<n;i++)
        {   int p=in.ni();
            int q=in.ni();
            if(s.charAt(i)=='1')
            {
                for(j=1;j<=q;j++)
                    a[i][j]=1;
                for(int k=1;k<=100;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<500)
                            a[i][j]=1;
                    }
                }
            }
            else
            {
                for(int k=0;k<=100;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<500)
                            a[i][j]=1;
                    }
                }
            }
        }
        int ans=0;
        for(j=0;j<=450;j++)
        {   int count=0;
            for(i=0;i<n;i++)
                if(a[i][j]==1)
                    count++;
            ans=Math.max(ans,count);
        }
        out.println(ans);

        out.close();
	}
	static class pair implements Comparable<pair>{
		int x, y;
		public pair(int x, int y){this.x = x; this.y = y;}
		@Override
		public int compareTo(pair arg0)
		{   if(x<arg0.x)    return -1;
		    else if(x==arg0.x)
		    {   if(y<arg0.y)    return -1;
		        else if(y>arg0.y)   return 1;
		        else    return 0;
		    }
		    else    return 1;
		}
	}
	static long gcd(long a,long b)
	{   if(b==0)
	        return a;
	    return gcd(b,a%b);
	}
	static long exponent(long a,long n)
	{   long ans=1;
	    while(n!=0)
	    {   if(n%2==1)
	            ans=(ans*a)%mod;
	       a=(a*a)%mod;
	       n=n>>1;
	    }
	    return ans;
	}
	static int binarySearch(int a[], int item, int low, int high)
    {   if (high <= low)
            return (item > a[low])?  (low + 1): low;
        int mid = (low + high)/2;
        if(item == a[mid])
            return mid+1;
        if(item > a[mid])
            return binarySearch(a, item, mid+1, high);
        return binarySearch(a, item, low, mid-1);
    }
    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2];

        for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) {   if (L[i] <= R[j]) {   arr[k] = L[i]; i++; } else{   arr[k] = R[j]; j++; } k++; } while (i < n1){   arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j];   j++;     k++; }
    }
    static void Sort(int arr[], int l, int r) {if (l < r) {   int m = (l+r)/2; Sort(arr, l, m); Sort(arr , m+1, r); merge(arr, l, m, r); } }

    static void sort(int a[])
    {Sort(a,0,a.length-1);}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{       static PrintWriter out=new PrintWriter(System.out);static FastScanner in = new FastScanner(System.in);static class FastScanner {BufferedReader br;StringTokenizer stok;FastScanner(InputStream is) {br = new BufferedReader(new InputStreamReader(is));}
        String next() throws IOException {while (stok == null || !stok.hasMoreTokens()) {String s = br.readLine();if (s == null) {return null;}
                stok = new StringTokenizer(s);}return stok.nextToken();}
        int ni() throws IOException {return Integer.parseInt(next());}long nl() throws IOException {return Long.parseLong(next());}double nd() throws IOException {return Double.parseDouble(next());}char nc() throws IOException {return (char) (br.read());}String ns() throws IOException {return br.readLine();}
        int[] nia(int n) throws IOException{int a[] = new int[n];for (int i = 0; i < n; i++)a[i] = ni();return a;}long[] nla(int n) throws IOException {long a[] = new long[n];for (int i = 0; i < n; i++)a[i] = nl();return a;}
        double[] nda(int n)throws IOException {double a[] = new double[n];for (int i = 0; i < n; i++)a[i] = nd();return a;}int [][] imat(int n,int m) throws IOException{int mat[][]=new int[n][m];for(int i=0;i<n;i++){for(int j=0;j<m;j++)mat[i][j]=ni();}return mat;}
    }
	static long mod=Long.MAX_VALUE;
	public static void main (String[] args) throws java.lang.Exception
	{   int i,j;
	    HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
		/*  if(hm.containsKey(z))
		        hm.put(z,hm.get(z)+1);
		    else
		        hm.put(z,1);
		 */
        ArrayList<Integer> arr=new ArrayList<Integer>();
        HashSet<Integer> set=new HashSet<Integer>();
        PriorityQueue<Integer> pq=new PriorityQueue<Integer>();
        int n=in.ni();
        String s=in.next();
        int a[][]=new int[n][1000];
        for(i=0;i<n;i++)
        {   int p=in.ni();
            int q=in.ni();
            if(s.charAt(i)=='1')
            {
                for(j=1;j<=q;j++)
                    a[i][j]=1;
                for(int k=1;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
            else
            {
                for(int k=0;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+q;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
        }
        int ans=0;
        for(j=0;j<=450;j++)
        {   int count=0;
            for(i=0;i<n;i++)
                if(a[i][j]==1)
                    count++;
            ans=Math.max(ans,count);
        }
        out.println(ans);

        out.close();
	}
	static class pair implements Comparable<pair>{
		int x, y;
		public pair(int x, int y){this.x = x; this.y = y;}
		@Override
		public int compareTo(pair arg0)
		{   if(x<arg0.x)    return -1;
		    else if(x==arg0.x)
		    {   if(y<arg0.y)    return -1;
		        else if(y>arg0.y)   return 1;
		        else    return 0;
		    }
		    else    return 1;
		}
	}
	static long gcd(long a,long b)
	{   if(b==0)
	        return a;
	    return gcd(b,a%b);
	}
	static long exponent(long a,long n)
	{   long ans=1;
	    while(n!=0)
	    {   if(n%2==1)
	            ans=(ans*a)%mod;
	       a=(a*a)%mod;
	       n=n>>1;
	    }
	    return ans;
	}
	static int binarySearch(int a[], int item, int low, int high)
    {   if (high <= low)
            return (item > a[low])?  (low + 1): low;
        int mid = (low + high)/2;
        if(item == a[mid])
            return mid+1;
        if(item > a[mid])
            return binarySearch(a, item, mid+1, high);
        return binarySearch(a, item, low, mid-1);
    }
    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2];

        for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) {   if (L[i] <= R[j]) {   arr[k] = L[i]; i++; } else{   arr[k] = R[j]; j++; } k++; } while (i < n1){   arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j];   j++;     k++; }
    }
    static void Sort(int arr[], int l, int r) {if (l < r) {   int m = (l+r)/2; Sort(arr, l, m); Sort(arr , m+1, r); merge(arr, l, m, r); } }

    static void sort(int a[])
    {Sort(a,0,a.length-1);}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Codechef
{       static PrintWriter out=new PrintWriter(System.out);static FastScanner in = new FastScanner(System.in);static class FastScanner {BufferedReader br;StringTokenizer stok;FastScanner(InputStream is) {br = new BufferedReader(new InputStreamReader(is));}
        String next() throws IOException {while (stok == null || !stok.hasMoreTokens()) {String s = br.readLine();if (s == null) {return null;}
                stok = new StringTokenizer(s);}return stok.nextToken();}
        int ni() throws IOException {return Integer.parseInt(next());}long nl() throws IOException {return Long.parseLong(next());}double nd() throws IOException {return Double.parseDouble(next());}char nc() throws IOException {return (char) (br.read());}String ns() throws IOException {return br.readLine();}
        int[] nia(int n) throws IOException{int a[] = new int[n];for (int i = 0; i < n; i++)a[i] = ni();return a;}long[] nla(int n) throws IOException {long a[] = new long[n];for (int i = 0; i < n; i++)a[i] = nl();return a;}
        double[] nda(int n)throws IOException {double a[] = new double[n];for (int i = 0; i < n; i++)a[i] = nd();return a;}int [][] imat(int n,int m) throws IOException{int mat[][]=new int[n][m];for(int i=0;i<n;i++){for(int j=0;j<m;j++)mat[i][j]=ni();}return mat;}
    }
	static long mod=Long.MAX_VALUE;
	public static void main (String[] args) throws java.lang.Exception
	{   int i,j;
	    HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>();
		/*  if(hm.containsKey(z))
		        hm.put(z,hm.get(z)+1);
		    else
		        hm.put(z,1);
		 */
        ArrayList<Integer> arr=new ArrayList<Integer>();
        HashSet<Integer> set=new HashSet<Integer>();
        PriorityQueue<Integer> pq=new PriorityQueue<Integer>();
        int n=in.ni();
        String s=in.next();
        int a[][]=new int[n][1000];
        for(i=0;i<n;i++)
        {   int p=in.ni();
            int q=in.ni();
            if(s.charAt(i)=='1')
            {
                for(j=1;j<=q;j++)
                    a[i][j]=1;
                for(int k=1;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+p;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
            else
            {
                for(int k=0;k<=1000;k+=2)
                {   int next=k*p+q+1;
                    for(j=next;j<next+p;j++)
                    {   if(j<1000)
                            a[i][j]=1;
                    }
                }
            }
        }
        int ans=0;
        for(j=0;j<=999;j++)
        {   int count=0;
            for(i=0;i<n;i++)
                if(a[i][j]==1)
                    count++;
            ans=Math.max(ans,count);
        }
        out.println(ans);

        out.close();
	}
	static class pair implements Comparable<pair>{
		int x, y;
		public pair(int x, int y){this.x = x; this.y = y;}
		@Override
		public int compareTo(pair arg0)
		{   if(x<arg0.x)    return -1;
		    else if(x==arg0.x)
		    {   if(y<arg0.y)    return -1;
		        else if(y>arg0.y)   return 1;
		        else    return 0;
		    }
		    else    return 1;
		}
	}
	static long gcd(long a,long b)
	{   if(b==0)
	        return a;
	    return gcd(b,a%b);
	}
	static long exponent(long a,long n)
	{   long ans=1;
	    while(n!=0)
	    {   if(n%2==1)
	            ans=(ans*a)%mod;
	       a=(a*a)%mod;
	       n=n>>1;
	    }
	    return ans;
	}
	static int binarySearch(int a[], int item, int low, int high)
    {   if (high <= low)
            return (item > a[low])?  (low + 1): low;
        int mid = (low + high)/2;
        if(item == a[mid])
            return mid+1;
        if(item > a[mid])
            return binarySearch(a, item, mid+1, high);
        return binarySearch(a, item, low, mid-1);
    }
    static void merge(int arr[], int l, int m, int r) {
        int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2];

        for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) {   if (L[i] <= R[j]) {   arr[k] = L[i]; i++; } else{   arr[k] = R[j]; j++; } k++; } while (i < n1){   arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j];   j++;     k++; }
    }
    static void Sort(int arr[], int l, int r) {if (l < r) {   int m = (l+r)/2; Sort(arr, l, m); Sort(arr , m+1, r); merge(arr, l, m, r); } }

    static void sort(int a[])
    {Sort(a,0,a.length-1);}
}