#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
int a[N], base[20], v[20], x, num, vis[N << 1];
void ins(int x) {
  int tp = x;
  for (int i = 19; ~i; i--)
    if (x >> i & 1) {
      if (base[i]) {
        x ^= base[i];
        continue;
      }
      base[i] = x;
      v[i] = tp;
      num++;
      break;
    }
}
void dfs(int t) {
  vis[t] = 1;
  cout << t << ' ';
  for (int i = 0; i < x; i++)
    if (!vis[t ^ v[i]]) dfs(t ^ v[i]);
}
int main() {
  std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (int i = 1, j = 1; i < 20; i++) {
    for (; j <= n && a[j] < (1 << i); j++) ins(a[j]);
    if (num == i) x = i;
  }
  cout << x << '\n';
  dfs(0);
  return 0;
}
