#include <bits/stdc++.h>
const int N = 200005, M = 19;
int base[M], origin[M], rank, n, a[N], ans;
void insert(int x) {
  int b = x;
  for (int i = M - 1; ~i; --i)
    if (x >> i & 1) {
      if (!base[i]) origin[i] = b, base[i] = x, ++rank;
      x ^= base[i];
    }
}
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n;
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::sort(a, a + n);
  int p = 0;
  for (int i = 0; i <= 18; ++i) {
    while (p < n && !(a[p] >> i)) insert(a[p++]);
    if (rank == i) ans = i;
  }
  std::cout << ans << '\n';
  for (int i = 0; i < 1 << ans; ++i) {
    int code = i ^ i >> 1, s = 0;
    for (int j = 0; j < ans; ++j)
      if (code >> j & 1) s ^= origin[j];
    std::cout << s << ' ';
  }
  std::cout << '\n';
  return 0;
}
