#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, s[maxn];
vector<int> cur;
vector<int> keep;
vector<int> basis;
void ins(int x) {
  int now = x;
  for (int i : basis) x = min(x, x ^ i);
  if (x > 0) {
    keep.push_back(now);
    basis.push_back(x);
    for (int i = (int)basis.size() - 1; i > 0; i--) {
      if (basis[i] > basis[i - 1])
        swap(basis[i], basis[i - 1]);
      else
        break;
    }
  }
}
void make_graycode(int x) {
  if (x == 0) return;
  make_graycode(x - 1);
  for (int j = (int)cur.size() - 1; j >= 0; j--) {
    cur.push_back(cur[j] * 2 + 1);
    cur[j] <<= 1;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &s[i]);
  }
  sort(s + 1, s + 1 + n);
  int has = 0, pt = 1;
  for (int i = 1; i <= 19; i++) {
    while (pt <= n && s[pt] < (1 << i)) {
      ins(s[pt++]);
    }
    if ((int)basis.size() == i) has = i;
  }
  if (has == 0) return !printf("0 \n0");
  printf("%d\n", has);
  cur = {0, 1};
  make_graycode(has - 1);
  int toprint = 0;
  for (int i : cur) {
    toprint = 0;
    for (int j = 0; j < has; j++) {
      if (i >> j & 1) toprint ^= keep[j];
    }
    printf("%d ", toprint);
  }
}
