#include <bits/stdc++.h>
using namespace std;
const int N = 6e5;
int w[N], vis[N], a[30], tw[N], n, cov[30], tcov[N], cons[N], ans[N], tmp[N],
    size;
void ins(int w) {
  int S = 0;
  for (int i = 17; i >= 0; i--)
    if (w >> i & 1) {
      if (!a[i]) {
        a[i] = w, cov[i] = S ^ (1 << i);
        ++size;
        return;
      }
      w ^= a[i];
      S ^= cov[i];
    }
}
void print(int t) {
  cout << t << endl;
  for (int i = 0; i < t; i++) tw[1 << i] = a[i], tcov[1 << i] = cov[i];
  for (int S = 0; S < (1 << t); S++) {
    if (S)
      w[S] = w[S ^ (S & -S)] ^ tw[S & -S],
      cons[S] = cons[S ^ (S & -S)] ^ tcov[S & -S];
    else
      w[S] = cons[S] = 0;
    ans[cons[S]] = w[S];
  }
  for (int S = 0; S < (1 << t); S++) printf("%d ", ans[S ^ (S >> 1)]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", tmp + i);
  sort(tmp + 1, tmp + n + 1);
  int tans = 0;
  for (int i = 0, j = 1; i <= 18; i++) {
    while (j <= n && tmp[j] < (1 << i)) ins(tmp[j]), j++;
    if (size == i) tans = i;
  }
  print(tans);
}
