#include <bits/stdc++.h>
using namespace std;
int n, s[200002], p[20], q[20], a[1 << 20], b[1 << 20];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &s[i]);
  sort(s + 1, s + n + 1);
  for (int i = 1; i <= n; ++i)
    for (int j = 0, k = s[i]; j < 20; ++j)
      if (k & (1 << j))
        if (p[j])
          k ^= p[j];
        else {
          p[j] = k, q[j] = i;
          break;
        }
  int x = 0, y = 0;
  while (p[y]) ++y;
  for (int i = y; i >= 0; --i) {
    bool flag = 1;
    for (int j = 0; j < i; ++j)
      if (s[q[j]] >= (1 << i)) {
        flag = 0;
        break;
      }
    if (flag) {
      x = i;
      break;
    }
  }
  for (int i = 0; i < x; ++i)
    for (int j = 0; j < (1 << i); ++j)
      a[(1 << i) + j] = a[(1 << i) - j - 1] | (1 << i);
  for (int i = 0; i < x; ++i) b[1 << i] = s[q[i]];
  int t = 0;
  for (int i = 0; i < (1 << x); ++i) {
    a[i] ^= t;
    if (i + 1 < (1 << x)) t = a[i + 1] ^ a[i] ^ b[a[i + 1] ^ a[i] ^ t];
  }
  printf("%d\n", x);
  for (int i = 0; i < (1 << x); ++i)
    printf("%d%c", a[i], " \n"[i + 1 == (1 << x)]);
}
