#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> gen_gray(int n) {
  if (n == 0) {
    return {0};
  }
  auto res = gen_gray(n - 1);
  int len = 1 << n;
  res.resize(len);
  for (int i = 0; i < len / 2; ++i) {
    res[i] <<= 1;
    res[i + len / 2] = res[i] ^ 1;
  }
  reverse(res.begin() + len / 2, res.end());
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  constexpr int kMaxLog = 20;
  vector<pair<int, int>> base(kMaxLog, {-1, -1});
  auto possible = [&](int v) {
    int ov = v;
    for (int i = kMaxLog - 1; i >= 0; --i) {
      if (base[i].first != -1 && (v & (1 << i))) {
        v ^= base[i].first;
      }
    }
    if (v == 0) {
      return;
    }
    for (int i = kMaxLog - 1; i >= 0; --i) {
      if (v & (1 << i)) {
        base[i] = {v, ov};
        return;
      }
    }
    assert(false);
  };
  for (int v : s) {
    possible(v);
  }
  int k = 0;
  for (int i = kMaxLog - 1; i > 0; --i) {
    int biggest = 1 << i;
    bool ok = true;
    for (int j = 0; j < i; ++j) {
      if (base[j].first == -1 || base[j].second >= biggest) {
        ok = false;
        break;
      }
    }
    if (ok) {
      k = i;
      break;
    }
  }
  cout << k << '\n';
  auto gray = gen_gray(k);
  for (int v : gray) {
    int cur = 0;
    for (int i = 0; i < k; ++i) {
      if (v & (1 << i)) {
        cur ^= base[i].second;
      }
    }
    cout << cur << ' ';
  }
  cout << '\n';
  return 0;
}
