#include<iostream>
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define fo(i,n) for(i=0;i<(n);++i)
#define repA(i,j,n) for(i=(j);i<=(n);++i)
#define repD(i,j,n) for(i=(j);i>=(n);--i)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"
#define PI 3.1415926535897932384626433832795
typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;
const int me = 20;
struct Gauss {
int table[me];
Gauss() {
for(int i = 0; i < me; i++) {
table[i] = 0;
}
}
int size() {
int ans = 0;
for(int i = 0; i < me; i++) {
if(table[i]) ans++;
}
return ans;
}
bool can(int x) {
for(int i = me-1; i >= 0; i--) {
x = std::min(x, x ^ table[i]);
}
return x == 0;
}
void add(int x) {
for(int i = me-1; i >= 0 && x; i--) {
if(table[i] == 0) {
table[i] = x;
x = 0;
} else {
x = std::min(x, x ^ table[i]);
}
}
}
int best() {
int x = 0;
for(int i = me-1; i >= 0; i--) {
x = std::max(x, x ^ table[i]);
}
return x;
}
void prt()
{
for(int i = me-1; i >= 0; i--) {
if(table[i])
cout<<table[i]<<" ";
}
cout<<endl;
}
};
int main(void) {
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
Gauss test;
test.add(4);
test.prt();
test.add(1);
test.prt();
test.add(8);
test.prt();
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlPHN0ZGlvLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgZm8oaSxuKSAgIGZvcihpPTA7aTwobik7KytpKQojZGVmaW5lIHJlcEEoaSxqLG4pICAgZm9yKGk9KGopO2k8PShuKTsrK2kpCiNkZWZpbmUgcmVwRChpLGosbikgICBmb3IoaT0oaik7aT49KG4pOy0taSkKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSBtcCBtYWtlX3BhaXIKI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