#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, inf = 0x3f3f3f3f;
int n, m, k, s[N], vis[N * 10], bas[20], a[20];
void insert(int x) {
  int t = x;
  for (int i = 20; i >= 0; i--)
    if ((x >> i) & 1)
      if (!bas[i]) {
        bas[i] = x;
        a[++k] = t;
        break;
      } else
        x ^= bas[i];
}
void dfs(int x, int num) {
  printf("%d ", num);
  if (x == (1 << m)) exit(0);
  vis[num] = 1;
  for (int i = 1; i <= k; i++)
    if (!vis[num ^ a[i]]) dfs(x + 1, num ^ a[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int i = 0; i <= 20; i++) {
    for (int j = 1; j <= n; j++)
      if (s[j] < (1 << i)) insert(s[j]);
    if (k == i) m = i;
    k = 0;
    memset(bas, 0, sizeof(bas));
  }
  printf("%d\n", m);
  k = 0;
  memset(bas, 0, sizeof(bas));
  for (int i = 1; i <= n; i++)
    if (s[i] < (1 << m)) insert(s[i]);
  dfs(1, 0);
  return 0;
}
