#include <bits/stdc++.h>
using namespace std;
const int N = 22;
int n, arr[(1 << N) + 5], arr2[(1 << N) + 5], nn, arr3[(1 << N) + 5];
int vis[(1 << 22)], vi = 0;
bool has[N];
vector<int> v2;
void check(int cur) {
  nn = 0;
  vi++;
  int tmp = 0;
  v2.clear();
  v2.push_back(0);
  for (int i = 0; i < n; i++) {
    if (arr[i] < (1 << cur)) {
      if (vis[arr[i]] == vi) continue;
      arr2[nn++] = arr[i];
      vis[arr[i]] = vi;
      tmp = (int)v2.size();
      for (int j = 0; j < tmp; j++) {
        vis[(arr[i] ^ v2[j])] = vi;
        v2.push_back((arr[i] ^ v2[j]));
      }
    }
  }
  if ((int)v2.size() < (1 << cur)) return;
  vi++;
  arr3[0] = 0;
  vis[0] = vi;
  for (int i = 1; i < (1 << cur); i++) {
    for (int j = 0; j < nn; j++) {
      if (vis[(arr3[i - 1] ^ arr2[j])] == vi) continue;
      vis[(arr3[i - 1] ^ arr2[j])] = vi;
      arr3[i] = (arr3[i - 1] ^ arr2[j]);
      break;
    }
  }
  cout << cur << endl;
  for (int i = 0; i < (1 << cur); i++) {
    if (i) putchar(' ');
    printf("%d", arr3[i]);
  }
  puts("");
  exit(0);
}
int main() {
  scanf("%d", &n);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    for (int j = N; j >= 0; j--) {
      if (((arr[i] >> j) & 1) == 1) {
        mx = max(mx, j + 1);
      }
    }
  }
  for (int ans = mx; ans > 0; ans--) {
    check(ans);
  }
  cout << "0 \n0\n";
  return 0;
}
