#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
struct LinearBase {
  int a[20], id[20];
  void ins(int x, int y) {
    for (int i = 19; ~i; i--)
      if (x >> i & 1) {
        if (a[i])
          x ^= a[i];
        else {
          a[i] = x;
          id[i] = y;
          break;
        }
      }
  }
  bool exist(int x) {
    for (int i = 19; ~i; i--)
      if (x >> i & 1) {
        if (a[i])
          x ^= a[i];
        else
          return false;
      }
    return true;
  }
} lb;
int ss[MAXN], aa[20], bb[20], n;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", ss + i);
  }
  for (int c = 19; ~c; c--) {
    memset(&lb, 0, sizeof(lb));
    for (int i = 1; i <= n; i++)
      if (ss[i] < 1 << c) lb.ins(ss[i], i);
    int res = 0;
    for (int i = 0; i < 20; i++)
      if (lb.a[i]) {
        aa[i] = lb.a[i];
        bb[i] = lb.id[i];
        res = i + 1;
      } else
        break;
    if (res != c) continue;
    printf("%d\n", res);
    for (int i = 0; i < 1 << res; i++) {
      int now = i;
      for (int j = 0; j + 1 < res; j++)
        if (i >> j >> 1 & 1) now ^= 1 << j;
      int ans = 0;
      for (int j = 0; j < res; j++)
        if (now >> j & 1) ans ^= ss[bb[j]];
      printf("%d ", ans);
    }
    break;
  }
  return 0;
}
