#include <bits/stdc++.h>
using namespace std;
vector<int> ori(1), A, B;
int idx[19], V[19];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int N, ans = 0, p = 0;
  for (int i = 1; i < 18; i++) {
    vector<int> temp(1, i);
    idx[i] = -1;
    for (auto a : ori) temp.push_back(a);
    for (auto a : temp) ori.push_back(a);
  }
  idx[0] = idx[18] = -1;
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  B = A;
  for (int j = 17; j >= 0; j--) {
    for (int i = 0; i < N; i++) {
      if (B[i] & (1 << j)) {
        if (idx[j] == -1)
          idx[j] = i, swap(V[j], B[i]);
        else
          B[i] ^= V[j];
      }
    }
  }
  for (; idx[ans] != -1; ans++)
    ;
  cout << ans << "\n0";
  for (int i = 1; i < (1 << ans); i++) cout << ' ' << (p ^= A[idx[ori[i - 1]]]);
  cout << '\n';
  return 0;
}
