#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, w = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') w = 0, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return w ? x : -x;
}
int n, m, s[345678], a[20], b[20], all, ans[345678], tot;
void insert(int x) {
  for (int i = n - 1, y = x; ~i; --i)
    if (x >> i & 1)
      if (!a[i]) {
        a[i] = x;
        b[i] = y;
        break;
      } else
        x ^= a[i];
}
void dfs(int x, int y, int ban) {
  if (__builtin_popcount(ban ^ all) == 1) {
    ans[++tot] = y;
    ans[++tot] = x ^ y;
    return;
  }
  for (int i = 0; i < n; ++i)
    if ((~ban >> i & 1) && (x >> i & 1))
      for (int j = 0; j < n; ++j)
        if ((~ban >> j & 1) && i != j) {
          dfs(1 << j, y, ban | 1 << i);
          dfs(x ^ (1 << i) ^ (1 << j), y ^ (1 << i) ^ (1 << j), ban | 1 << i);
          return;
        }
}
bool check(int _n) {
  n = _n;
  all = (1 << n) - 1;
  for (int i = 0; i < n; ++i) a[i] = b[i] = 0;
  for (int i = 1; i <= m; ++i)
    if ((s[i] | all) == all) insert(s[i]);
  for (int i = 0; i < n; ++i)
    if (!a[i]) return false;
  printf("%d\n", n);
  if (n)
    dfs(1, 0, 0);
  else
    ans[tot = 1] = 0;
  for (int i = 1; i <= tot; ++i) {
    int res = 0;
    for (int j = 0; j < n; ++j)
      if (ans[i] >> j & 1) res ^= b[j];
    printf("%d ", res);
  }
  puts("");
  return true;
}
int main() {
  m = gi();
  for (int i = 1; i <= m; ++i) s[i] = gi();
  for (int i = 18; ~i; --i)
    if (check(i)) return 0;
}
