#include <bits/stdc++.h>
using namespace std;
const long double EPS = (long double)1e-7;
const long double PI = acos(0) * 2;
bool isZero(const long double& x) { return abs(x) <= EPS; }
int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b)) {
  }
  return abs(a);
}
pair<long long, long long> operator+(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first + b.first, a.second + b.second);
}
pair<long long, long long> operator-(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first - b.first, a.second - b.second);
}
pair<long long, long long> operator*(const pair<long long, long long>& a,
                                     const long long& b) {
  return pair<long long, long long>(a.first * b, a.second * b);
}
long long operator*(const pair<long long, long long>& a,
                    const pair<long long, long long>& b) {
  return a.first * b.second - b.first * a.second;
}
long long ccw(const pair<long long, long long>& a,
              const pair<long long, long long>& b,
              const pair<long long, long long>& c) {
  return a * b + b * c + c * a;
}
void fg(vector<int> G[], int a, int b) {
  G[a].push_back(b);
  G[b].push_back(a);
}
void fg(vector<pair<int, int> > G[], int a, int b, int c) {
  G[a].push_back({b, c});
  G[b].push_back({a, c});
}
const int MAXN = 200055;
vector<int> BV;
int B[55];
int A[MAXN];
int N;
void f(vector<int>& V, int lv) {
  if (!lv) {
    V.emplace_back(0);
    V.emplace_back(BV[0]);
    return;
  }
  vector<int> T;
  f(T, lv - 1);
  V = T;
  int ex = T.back() ^ BV[lv];
  for (int v : T) V.emplace_back(v ^ ex);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int X = 20; X; X--) {
    fill(B, B + 55, 0);
    BV.clear();
    for (int i = 0; i < N; i++) {
      int x, y;
      x = y = A[i];
      if ((1 << X) <= x) continue;
      for (int j = X - 1; 0 <= j; j--) {
        if (!(x & (1 << j))) continue;
        if (B[j])
          x ^= B[j];
        else {
          B[j] = x;
          BV.emplace_back(y);
          break;
        }
      }
    }
    if (((int)(BV).size()) != X) continue;
    vector<int> AnsV;
    f(AnsV, X - 1);
    printf("%d\n", X);
    for (int v : AnsV) printf("%d ", v);
    puts("");
    return 0;
  }
  puts("0\n0");
  return 0;
}
