#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 5e5 + 7;
const int maxm = 8e5 + 7;
const long long mod = 998244353;
const double pi = acos(-1.0);
const double eps = 1e-12;
int n, x;
int a[maxn], basis[27], vis[maxn];
vector<int> G;
void add(int val) {
  int tmp = val;
  for (int i = 19; i >= 0; i--)
    if (val & (1 << i)) {
      if (basis[i])
        val ^= basis[i];
      else {
        G.push_back(tmp);
        basis[i] = val;
        break;
      }
    }
}
void dfs(int v, int depth) {
  printf("%d ", v);
  vis[v] = 1;
  if (depth == (1 << x)) return;
  for (int i = 0; i < G.size(); i++)
    if (!vis[v ^ G[i]]) {
      dfs(v ^ G[i], depth + 1);
      break;
    }
}
int main(int argc, char const *argv[]) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + n + 1);
  int p = 1;
  for (int i = 1; i <= 19; i++) {
    while (p <= n && a[p] < (1 << i)) add(a[p++]);
    bool flag = 1;
    for (int j = 0; j < i; j++)
      if (!basis[j]) flag = 0;
    if (flag) x = i;
  }
  memset(basis, 0, sizeof(basis));
  G.clear();
  for (int i = 1; i <= n; i++)
    if (a[i] < (1 << x)) G.push_back(a[i]);
  printf("%d\n", x);
  dfs(0, 1);
  return 0;
}
