#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
ll dp[1 << 18];
int a[1 << 18];
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, c = 0;
    ll mx;
    cin >> n;
    mx = (1 << n);
    for (int i = 0; i < mx; i++) {
        cin >> a[i];
    }
    for(int i = 0; i < mx; i++) dp[i] = mx*i;
    ll ans = 0;
    for(int s = 1; s < mx; s++) {
        for(int i = 0; i < n; i++) {
            if((s >> i) & 1) {
                int s0 = s ^ (1 << i);
                ll tmp[4] = {dp[s0]%mx, dp[s0]/mx, dp[s]/mx, dp[s]%mx};
                sort(tmp, tmp + 4, [&](ll x, ll y){return a[x]>a[y];});
                unique(tmp, tmp + 4);
                dp[s] = tmp[0]+tmp[1]*mx;
            }
        }
        ll res = a[dp[s]/mx] + a[dp[s]%mx];
        ans = max(ans, res);
        cout << ans << endl;
    }
    return 0;
}