#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int a[maxn];
bool mark[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  vector<int> vans;
  for (int bs = 1; bs < 20; bs++) {
    vector<int> vec;
    vector<int> inn;
    memset(mark, 0, sizeof mark);
    inn.push_back(0);
    mark[0] = 1;
    for (int i = 0; i < n; i++) {
      if (a[i] < (1 << bs) && mark[a[i]] == 0) {
        for (int j = int((inn).size()) - 1; j >= 0; j--)
          mark[inn[j] ^ a[i]] = 1, inn.push_back(inn[j] ^ a[i]);
        int SZ = int((vec).size());
        vec.push_back(a[i]);
        for (int i = SZ - 1; i >= 0; i--) vec.push_back(vec[i]);
      }
    }
    if ((1 << bs) - 1 == int((vec).size())) vans = vec, ans = bs;
  }
  int nw = 0;
  cout << ans << endl << 0 << " ";
  for (int x : vans) {
    nw ^= x;
    cout << nw << " ";
  }
  return cout << endl, 0;
}
