#include <bits/stdc++.h>
using namespace std;
vector<int> basis, vec;
void add(int v) {
  int tmp = v;
  for (int i = 0; i < basis.size(); i++) tmp = min(tmp, tmp ^ basis[i]);
  if (tmp > 0) {
    vec.push_back(v);
    basis.push_back(tmp);
    for (int i = basis.size() - 1; i > 0; i--) {
      if (basis[i] > basis[i - 1])
        swap(basis[i], basis[i - 1]);
      else
        break;
    }
  }
}
void graycode(int ans) {
  cout << ans << endl;
  vector<int> otv = {0};
  for (int i = 0; i < ans; i++) {
    for (int j = otv.size() - 1; j >= 0; j--) otv.push_back(otv[j] ^ vec[i]);
  }
  for (int i = 0; i < otv.size(); i++) cout << otv[i] << " ";
}
int n, a[200009], ans;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int it = 1;
  for (int x = 1; x < 20; x++) {
    for (; it <= n && a[it] < (1 << x); it++) add(a[it]);
    if (basis.size() == x) ans = x;
  }
  graycode(ans);
}
