#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  scanf("%d", &N);
  vector<int> S(N), ob;
  for (int n = 0; n < int(N); n++) scanf("%d", &S[n]);
  sort(begin(S), end(S));
  set<int> basis;
  auto it = begin(S);
  int ans = 0;
  for (int x = 1; x < int(20); x++) {
    for (; it != end(S) && *it < (1 << x); ++it) {
      int a = *it;
      for (auto iu = basis.rbegin(); iu != basis.rend(); ++iu) {
        a = min(a, (*iu) ^ a);
      }
      if (a) {
        basis.insert(a);
        ob.push_back(*it);
      }
    }
    if (((int)(basis).size()) == x) ans = max(ans, x);
  }
  printf("%d\n", ans);
  int pv = 0, pgc = 0;
  printf("0");
  for (int a = 1; a < int(1 << ans); a++) {
    int gc = a ^ (a >> 1);
    int cb = __builtin_ctz(gc ^ pgc);
    pv ^= ob[cb];
    pgc = gc;
    printf(" %d", pv);
  }
  printf("\n");
}
