#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
const int MAXN = 2e5, LOG = 18;
int n;
unsigned int s[MAXN + 5];
unsigned int mask_to_val[MAXN + 5];
struct LinerBase {
  int size;
  unsigned int base[MAXN + 5], mask[MAXN + 5], val[MAXN + 5];
  void insert(const unsigned int& v) {
    unsigned int t = v;
    unsigned int ma = 0;
    for (int i = LOG; i >= 0; --i)
      if ((t >> i) & 1) {
        if (!base[i]) {
          base[i] = t;
          ++size;
          ma |= (1 << (size - 1));
          mask[i] = ma;
          val[size] = v;
          return;
        } else {
          t ^= base[i];
          ma ^= mask[i];
        }
      }
  }
  unsigned int query_mask(const unsigned int& v) {
    unsigned int t = v;
    unsigned int ma = 0;
    for (int i = LOG; i >= 0; --i)
      if ((t >> i) & 1) {
        assert(base[i]);
        t ^= base[i];
        ma ^= mask[i];
      }
    return ma;
  }
} B;
vector<unsigned int> get_gray(unsigned int x) {
  if (x == 0) {
    vector<unsigned int> res(1, 0);
    return res;
  }
  vector<unsigned int> res = get_gray(x - 1);
  unsigned int len = (1u << (x - 1));
  for (unsigned int i = 0; i < len; ++i) {
    res.push_back(res[len - 1 - i] | (1u << (x - 1)));
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
  }
  sort(s + 1, s + n + 1);
  int j = 0;
  int x = -1;
  for (int i = 0; i <= LOG; ++i) {
    while (j + 1 <= n && s[j + 1] < (1u << i)) {
      ++j;
      B.insert(s[j]);
    }
    if (B.size == i) x = i;
  }
  assert(x != -1);
  for (unsigned int i = 0; i < (1u << x); ++i) {
    mask_to_val[B.query_mask(i)] = i;
  }
  vector<unsigned int> v = get_gray(x);
  cout << x << endl;
  for (unsigned int i = 0; i < (1u << x); ++i) {
    cout << mask_to_val[v[i]] << " ";
  }
  cout << endl;
  return 0;
}
