#include <bits/stdc++.h>
using namespace std;
inline void open(char* s) { static char str[20]; }
inline int rd() {
  int x = 0, f = 1;
  char ch = getchar();
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  return x * f;
}
const int N = 200010, B = 20;
int n, m = 0, a[B + 1], b[B + 1];
inline void ins(int x) {
  int y = x;
  for (int i = B; i >= 0; --i)
    if (x >> i & 1) {
      if (!a[i]) {
        a[i] = x, b[i] = y;
        break;
      }
      if (y < b[i]) swap(a[i], x), swap(b[i], y);
      x ^= a[i];
    }
}
inline bool check(int x) {
  for (int i = 0; i <= x - 1; ++i)
    if (!b[i] || b[i] >= (1 << x)) return 0;
  return 1;
}
bool vis[N << 1];
void dfs(int u, int x) {
  cout << u << ' ';
  vis[u] = 1;
  if (x == (1 << m) - 1) return;
  for (int i = 0; i <= m - 1; ++i)
    if (!vis[u ^ b[i]]) {
      dfs(u ^ b[i], x + 1);
      return;
    }
}
int main() {
  open("hh");
  n = rd();
  for (int i = 1; i <= n; ++i) ins(rd());
  m = B;
  while (!check(m)) --m;
  cout << m << endl;
  dfs(0, 0);
  return 0;
}
