#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, a[maxn], b[18], limit, ans[maxn], top, shu[maxn], cnt, vis[maxn], anss;
void build() {
  for (int i = 1; i <= n; i++) {
    int t = a[i];
    for (int j = 17; j >= 0; j--)
      if (t >> j & 1) {
        if (!b[j]) {
          b[j] = t;
          break;
        }
        t ^= b[j];
      }
  }
}
void Insert(int x) {
  int t = x;
  for (int j = 17; j >= 0; j--)
    if (t >> j & 1) {
      if (!b[j]) {
        b[j] = t;
        break;
      } else
        t ^= b[j];
    }
  if (t > 0) shu[++cnt] = x;
}
void dfs(int u) {
  ans[++top] = u;
  vis[u] = 1;
  for (int i = 1; i <= cnt; i++)
    if (!vis[u ^ shu[i]]) dfs(u ^ shu[i]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build();
  limit = 0;
  for (int i = 0; i <= 17; i++) {
    if (b[i]) {
      limit = (1 << (i + 1)) - 1;
      anss = i + 1;
    } else
      break;
  }
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++)
    if (a[i] <= limit) Insert(a[i]);
  vis[0] = 1;
  dfs(0);
  printf("%d\n", anss);
  for (int i = 1; i <= limit + 1; i++) printf("%d ", ans[i]);
  return 0;
}
