#include <bits/stdc++.h>
using namespace std;
vector<int> V;
vector<int> B, B1;
void add(int k) {
  int t = k;
  for (auto v : B) k = min(k, k ^ v);
  if (k > 0) {
    B.emplace_back(k);
    B1.emplace_back(t);
    sort(B.begin(), B.end(), greater<int>());
  }
}
void construct(int x) {
  V.emplace_back(0);
  for (int i = 0; i < x; i++) {
    for (int j = (1 << i) - 1; j >= 0; j--) {
      V.emplace_back(V[j] ^ B1[i]);
    }
  }
  for (auto k : V) cout << k << " ";
  cout << endl;
}
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  V.resize(n);
  for (int i = 0; i < n; i++) cin >> V[i];
  sort(V.begin(), V.end());
  int x = 0, k = 0;
  for (int i = 1; i < 22; i++) {
    for (; k < V.size() && V[k] < (1 << i); k++) {
      add(V[k]);
    }
    if (B.size() == i) x = i;
  }
  B.clear();
  for (int i = 0; i < V.size() && V[i] < (1 << x); i++) add(V[i]);
  V.clear();
  cout << x << endl;
  construct(x);
}
