#include <bits/stdc++.h>
using namespace std;
const int M = 410001;
int n, m, k, a[M], d[30], fr[30], b[M];
void ins(int x, int t) {
  for (int i = 20; i >= 0; i--) {
    if (!((x >> i) & 1)) continue;
    if (!d[i]) {
      fr[i] = t, d[i] = x;
      k++;
      return;
    }
    x ^= d[i];
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  for (int i = 1; i <= n; i++) ins(a[i], a[i]);
  k = 0;
  while (d[k]) k++;
  while (1 && k) {
    int B = 1;
    for (int i = 0; i < k; i++)
      if (fr[i] >= 1 << k) {
        B = 0;
        k = i;
        break;
      }
    if (B) break;
  }
  printf("%d\n", k);
  int x = 0;
  for (int i = 1; i <= 1 << k; i++) {
    printf("%d ", x);
    b[x] = 1;
    for (int j = 0; j < k; j++)
      if (!b[x ^ fr[j]]) {
        x = x ^ fr[j];
        break;
      }
  }
}
