#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> b;
int l(int x) { return 1 << (31 - __builtin_clz(x)); }
bool check(int x) {
  for (auto y : b) {
    if (x & l(y)) x ^= y;
  }
  return !x;
}
bool add(int x) {
  for (auto y : b) {
    if (x & l(y)) x ^= y;
  }
  if (!x) return 0;
  for (auto& y : b)
    if (y & l(x)) y ^= x;
  b.push_back(x);
  return 1;
}
int g(int n) { return n ^ (n >> 1); }
int main() {
  scanf("%d", &n);
  vector<int> v, a;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a.push_back(x);
    add(x);
  }
  int ans = 0;
  bool flag = 1;
  while (flag) {
    for (int i = (1 << ans); i < (1 << (ans + 1)); i++) {
      if (!check(i)) {
        flag = 0;
        break;
      }
    }
    if (flag) ans++;
  }
  printf("%d\n", ans);
  b.clear();
  for (auto x : a) {
    if (x >= (1 << ans)) continue;
    if (add(x)) v.push_back(x);
  }
  vector<int> v2;
  for (auto x : v) {
    if (x < (1 << ans)) v2.push_back(x);
  }
  v = v2;
  printf("0 ");
  int last = 0;
  map<int, int> aaa;
  for (int i = 0; i < 20; i++) aaa[1 << i] = i;
  for (int i = 1; i < (1 << ans); i++) {
    int bit = g(i) ^ g(i - 1);
    bit = aaa[bit];
    last ^= v[bit];
    printf("%d ", last);
  }
  puts("");
  return 0;
}
