#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
const int lg = 18;
const int N = 1 << lg;
int n;
bool can[N];
vi span, basis, a;
int main(int argc, char const* argv[]) {
  span = {0}, can[0] = 1;
  scanf("%d", &n);
  a.resize(n);
  for (int& x : a) scanf("%d", &x);
  sort(begin(a), end(a));
  int k = 0;
  for (int& x : a) {
    if (can[x]) continue;
    int sz = (int)span.size();
    basis.emplace_back(x);
    for (int j = 0; j < sz; ++j) {
      span.push_back(span[j] ^ x);
      can[span[j] ^ x] = 1;
    }
    if (span.size() == (1 << (32 - __builtin_clz(x)))) {
      k = 32 - __builtin_clz(x);
    }
  }
  while (basis.size() > k) basis.pop_back();
  printf("%d\n", k);
  vi gray = {0};
  for (int i = 0; i < k; ++i) {
    vi tmp(gray.rbegin(), gray.rend());
    for (int& y : tmp) y ^= basis[i];
    gray.insert(gray.begin(), tmp.begin(), tmp.end());
  }
  for (int x : gray) printf("%d ", x);
  return 0;
}
