#include <bits/stdc++.h>
using namespace std;
const int maxn = 212345;
int n, s[maxn];
bool good[18][1 << 18];
int main() {
  scanf("%d", &n);
  for (int(i) = (1); (i) <= (n); (i)++) scanf("%d", s + i);
  sort(s + 1, s + n + 1);
  for (int(bit) = (18); (bit) >= (1); (bit)--) {
    good[bit - 1][0] = true;
    vector<int> base;
    for (int(i) = (1); (i) <= (n); (i)++) {
      if (s[i] >= 1 << bit) break;
      if (good[bit - 1][s[i]]) continue;
      for (int(j) = (0); (j) <= ((1 << bit) - 1); (j)++)
        if (good[bit - 1][j]) good[bit - 1][j ^ s[i]] = true;
      base.emplace_back(s[i]);
    }
    if (base.size() == bit) {
      printf("%d\n", bit);
      int now = 0;
      printf("0");
      for (int(i) = (1); (i) <= ((1 << bit) - 1); (i)++) {
        int cnt = 0, j = i;
        while (!(j & 1)) j >>= 1, cnt++;
        now ^= base[cnt];
        printf(" %d", now);
      }
      return 0;
    }
  }
  printf("0\n0");
}
