#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005, B = 18;
int n, a[MAXN], val[1 << B], gray[1 << B];
struct XorBasis {
  int d[B], c[B], siz;
  void insert(int x) {
    for (int i = B - 1, s = 1 << siz; i >= 0; i--)
      if (x & 1 << i) {
        if (d[i])
          x ^= d[i], s ^= c[i];
        else {
          d[i] = x, c[i] = s, siz++;
          break;
        }
      }
  }
  int query(int x) {
    int s = 0;
    for (int i = B - 1; i >= 0; i--)
      if (x & 1 << i && d[i]) x ^= d[i], s ^= c[i];
    return s;
  }
} xb;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int mx = 0;
  for (int k = 1, i = 0; k <= B; k++) {
    while (i < n && a[i] < 1 << k) xb.insert(a[i++]);
    if (xb.siz == k) mx = k;
  }
  for (int i = 0; i < 1 << mx; i++) val[xb.query(i)] = i;
  for (int k = 1; k < 1 << mx; k <<= 1) {
    for (int i = 0; i < k; i++) gray[(k << 1) - i - 1] = gray[i] | k;
  }
  printf("%d\n", mx);
  for (int i = 0; i < 1 << mx; i++) printf("%d ", val[gray[i]]);
  putchar('\n');
  return 0;
}
