#include <bits/stdc++.h>
using namespace std;
int s[200005];
int vis[500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  vector<int> v;
  int Max = 20;
  while (true) {
    for (int i = 0; i < n; i++) {
      if (s[i] >= (1 << (Max + 1))) continue;
      int temp = s[i];
      for (auto &it : v) {
        s[i] = min(s[i], it ^ s[i]);
        if (s[i] > it) swap(s[i], it);
      }
      if (s[i] != 0) v.push_back(s[i]);
      s[i] = temp;
    }
    if (v.size() != Max + 1) {
      v.clear();
      Max--;
    } else {
      break;
    }
    if (Max == -1) {
      printf("0\n0\n");
      return 0;
    }
  }
  printf("%d\n", Max + 1);
  vector<int> ans;
  vis[0] = 1;
  ans.push_back(0);
  for (int i = 0; i <= Max; i++) {
    for (int j = 0; j < n; j++) {
      if (s[j] < (1 << (Max + 1))) {
        if (vis[ans.back() ^ s[j]] == 0) {
          for (int k = ans.size() - 1; k >= 0; k--) {
            ans.push_back(ans[k] ^ s[j]);
            vis[ans[k] ^ s[j]] = 1;
          }
          break;
        }
      }
    }
  }
  for (auto it : ans) printf("%d ", it);
  return 0;
}
