#include <iostream>
#include <cstdio>

using namespace std;

int pos[50];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif // ONLINE_JUDGE

    long long N, nr;
    cin >> N;

    for(long long i = 1; i <= N; ++i) {
        cin >> nr;
        pos[0] = 0;

        for(long long j = 1; j <= nr; j *= 2LL) {
            if(j & nr) {
                pos[++pos[0]] = 1;
            }
            else {
                pos[++pos[0]] = 0;
            }
        }

        int a = pos[0], b = 0;

        for(long long j = 1; j <= pos[0]; ++j) {
            if(pos[j] == 1) {
                a = j;
                break;
            }
        }

        for(long long j = pos[0]; j > 0; --j) {
            if(pos[j] == 0) {
                b = j;
                break;
            }
        }

        nr = max(nr, nr - 1LL * (1 << (a - 1)) + 1LL * (1 << (b - 1)));

        cout << nr << ' ';
    }

    cout << '\n';

    return 0;
}