#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:2000000")
using namespace std;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 4e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ = 320;
const long double EPS = 1e-7;
struct GaussXOR {
  vector<int> nums;
  GaussXOR() { nums.resize(17); }
  bool add(int x) {
    for (int i = 17; i >= 0; --i) {
      if (x >> i & 1 ^ 1) continue;
      if (nums[i])
        x ^= nums[i];
      else {
        nums[i] = x;
        return true;
      }
    }
    return false;
  }
};
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  GaussXOR gs;
  vector<int> cur;
  int cnt = 0;
  vector<int> ans;
  for (auto x : a) {
    int lg = 0;
    while ((1 << lg) <= x) ++lg;
    if (gs.add(x)) {
      cur.push_back(x);
      cnt++;
    }
    if (lg == cnt) {
      ans = cur;
    }
  }
  cout << ans.size() << endl;
  int mask = 0;
  for (int i = 0; i < (1 << ans.size()); i++) {
    int out = 0;
    mask ^= (i & -i);
    for (int j = 0; j < ans.size(); j++)
      if (mask >> j & 1) out ^= ans[j];
    cout << out << ' ';
  }
  return 0;
}
