#include <bits/stdc++.h>
using namespace std;
const int N = 40, M = 2e5 + 7;
int a[M], v[N], n, m, pre, i, j, d[N], tot;
bool ins(int x) {
  for (int i = 22; i >= 0; --i)
    if (x >> i & 1)
      if (v[i])
        x ^= v[i];
      else {
        v[i] = x;
        return true;
      }
  return false;
}
void check(int x) {
  memset(v, 0, sizeof(v));
  tot = 0;
  for (i = 1; i <= n; ++i)
    if (a[i] < (1 << x))
      if (ins(a[i])) d[tot++] = a[i];
  if (tot == x) {
    printf("%d\n", x);
    pre = 0;
    printf("0");
    for (i = 1; i < (1 << x); ++i)
      for (j = 0; j < tot; ++j)
        if (i >> j & 1) {
          pre ^= d[j];
          printf(" %d", pre);
          break;
        }
    exit(0);
  }
}
int main() {
  for (scanf("%d", &n), i = 1; i <= n; ++i) scanf("%d", a + i);
  for (int i = 20; i >= 0; --i) check(i);
}
