#include <bits/stdc++.h>
using namespace std;
int s[200010];
int a[200010];
int b[200010];
int ans[200010];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
  for (int r = 20; r >= 0; r--) {
    int x = (1 << r) - 1, m = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] <= x) {
        a[++m] = s[i];
        b[m] = s[i];
      }
    }
    int cnt = 0;
    for (int i = 0; i < r; i++) {
      int v = 1 << i;
      for (int j = i + 1; j <= m; j++) {
        if (b[j] & v) {
          swap(a[j], a[i + 1]);
          swap(b[j], b[i + 1]);
          cnt++;
          for (int jj = i + 2; jj <= m; jj++) {
            if (b[jj] & v) b[jj] ^= b[i + 1];
          }
          break;
        }
      }
    }
    if (cnt != r) continue;
    printf("%d\n", r);
    printf("%d ", 0);
    int st = 0;
    for (int i = 1; i <= r; i++) {
      ans[st + 1] = a[i];
      for (int j = 1; j <= st; j++) {
        ans[st + 1 + j] = ans[j];
      }
      st = 2 * st + 1;
    }
    for (int i = 1; i <= st; i++) {
      ans[i] ^= ans[i - 1];
      printf("%d ", ans[i]);
    }
    break;
  }
  return 0;
}
