//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

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

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
template<typename T>
void _scan( vector<T> &v ){
	for(int i=0; i<(int)v.size(); i++) _scan(v[i]);
}
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h)
	{ cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr<<#x<<" = "; for(auto _i:x) cerr<<_i<<", ";cerr<<"\n";}}
#define debuga(x, sz) {{cerr<<#x<<" = ";for(int _i=0;_i<sz;_i++)cerr<<x[_i]<<", ";cerr<<"\n";}}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

ll MOD = 1e9+7;

inline ll Msum(ll x){return x;}
template<typename... Rest>
inline ll Msum(ll x, Rest... rest){ return (x + Msum(rest...)) % MOD; }

inline ll Mprod(ll x){return x;}
template<typename... Rest>
inline ll Mprod(ll x, Rest... rest){ return x * Mprod(rest...) % MOD; }

inline ll Mnorm(ll x){ return (x%MOD + MOD) %MOD; }
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

const int MAXN = (1<<18)+1;

int tn=1, t[MAXN*4][2];
vi tv[MAXN*4];
vector<ii> dp[MAXN*4];
vector<int> dp2[MAXN*4];

void insert(int p, int x){
	int v=0;
	for(int i=17; i>-1; i--){
		if(tv[v][0] <= x){
			tv[v][1] = tv[v][0];
			tv[v][0] = x;
		}else if(tv[v][1] < x) tv[v][1] = x;

		int b = (p>>i)&1;
		if(t[v][b] == -1){
			t[v][b] = tn;
			tv[tn] = {-1, -1};
			dp[tn].resize(1<<i, {-1,-1});
			dp2[tn].resize(1<<i, -1);
			tn++;
		}
		v = t[v][b];
	}
	tv[v][0] = x;
}


int sumnode(int v){
	return tv[v][0] + tv[v][1];
}

//int anss;
//
ii merge(ii x, ii y){
	vi v = {x.fst, x.snd, y.fst, y.snd};
	sort(all(v));
	return {v[3], v[2]};
}

ii getpair(int v, int k, int bi){
	if(bi == -1) return {tv[v][0], -1};
	//debug(v, k, bi, dp[v][k].fst);
	if(dp[v][k].fst != -1){
		return dp[v][k];
	}

	ii &ret = dp[v][k];
	int b = (k>>bi)&1;
	int nk = k - (b<<bi);

	if(b==0){
		ret = getpair(t[v][0], nk, bi-1);
	}else{
		//mxze(anss, sumnode(t[v][0]));
		ret = merge(getpair(t[v][0], nk, bi-1),
				getpair(t[v][1], nk, bi-1));
	}
	return ret;
}

int get2(int v, int k, int bi){
	if(bi == 0) return -1;
	if(dp2[v][k] != -1){
		return dp2[v][k];
	}

	int &ret = dp2[v][k];
	int b = (k>>bi)&1;
	int nk = k - (b<<bi);

	if(b==0){
		ret = get2(t[v][0], nk, bi-1);
	}else{
		//mxze(anss, sumnode(t[v][0]));
		ret = max(sumnode(t[v][0]),
				get2(t[v][1], nk, bi-1));
	}
	return ret;
}

int n, a[MAXN];

int getpairr(int k){
	ii tmp = getpair(0, k, 17);
	//debug(k);
	//debug(tmp.fst, tmp.snd);
	int ans = tmp.fst + tmp.snd;
	for(int b=17; b>0; b--){
		if(k & (1<<b)){
			int nk = (k - (1<<b)) | ((1<<b)-1);
			tmp = getpair(0, nk, 17);
			mxze(ans,  tmp.fst + tmp.snd);
		}
	}
	return ans;

}

int main(){
	scan(n);
	ms(t, -1);
	tv[0] = {-1, -1};
	dp[0].resize(1<<n, {-1, -1});
	dp2[0].resize(1<<n, -1);
	for(int i=0; i<(1<<n); i++) scan(a[i]);
	for(int i=0; i<(1<<n); i++) insert(i, a[i]);

	for(int i=1; i<(1<<n); i++){
		fflush(stdout);
		if(i == (1<<n)-1){
			printf("%d\n", sumnode(0));
		}else{
			//ii ans = getpairr(0, i, 17);
			int ans = getpairr(i);
			//debug(i);
			//debug(getpairr(i));

			mxze(ans, get2(0, i+1, 17));
			//debug(get2(0, i+1, 17));

			printf("%d\n", ans);
		}
	}
}


Measured memory_bytes: 183424