#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const int maxn = 1e6 + 5;
int n;
int a[maxn];
vector<int> basis, vec;
void add(int x) {
  int save = x;
  for (int b : basis) {
    x = min(x, x ^ b);
  }
  if (x > 0) {
    basis.push_back(x);
    vec.push_back(save);
    sort(basis.rbegin(), basis.rend());
  }
}
vector<int> res;
bool viz[maxn];
int dim;
void dfs(int x) {
  if (viz[x]) {
    return;
  }
  viz[x] = true;
  res.push_back(x);
  if ((int)res.size() == (1 << dim)) {
    return;
  }
  for (int v : vec) {
    dfs(v ^ x);
  }
}
vector<int> gray_code(int x) {
  dim = x;
  dfs(0);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int x = 0;
  int p = 0;
  for (int i = 1; i < 20; i++) {
    for (; p < n && a[p] < 1 << i; p++) {
      add(a[p]);
    }
    if ((int)basis.size() == i) {
      x = i;
    }
  }
  basis.clear();
  vec.clear();
  for (int i = 0; i < n; i++) {
    if (a[i] < (1 << x)) {
      add(a[i]);
    }
  }
  vector<int> res = gray_code(x);
  cout << x << "\n";
  for (int i : res) cout << i << " ";
  cout << endl;
  return 0;
}
