#include <bits/stdc++.h>
using namespace std;
vector<int> basis, b;
int v[200005], used[2000005];
void add(int u) {
  int x = u;
  for (auto &v : basis) u = min(u, u ^ v);
  if (u) {
    basis.push_back(u);
    b.push_back(x);
    for (int i = basis.size() - 1; i > 0; i--)
      if (basis[i] > basis[i - 1]) swap(basis[i], basis[i - 1]);
  }
}
int size = 0;
vector<int> ans;
void dfs(int at) {
  if (used[at]) return;
  used[at] = 1;
  ans.push_back(at);
  if (ans.size() == (1 << size)) return;
  for (auto &c : b) {
    if (used[c ^ at] == 0) {
      dfs(c ^ at);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  for (int x = 20; x >= 0; x--) {
    basis.clear();
    b.clear();
    for (int i = 0; i < n; i++) {
      if (v[i] < (1 << x)) add(v[i]);
    }
    if (basis.size() < x) continue;
    size = x;
    printf("%d\n", x);
    dfs(0);
    for (auto &c : ans) {
      printf("%d ", c);
    }
    puts("");
    return 0;
  }
  return 0;
}
