#include <bits/stdc++.h>
using i64 = long long;
int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> a(n);
  for (auto &e : a) scanf("%d", &e);
  std::sort(a.begin(), a.end());
  std::vector<int> basis, vec;
  int x = 0;
  auto it = a.begin();
  for (int i = 1; i < 20; i++) {
    for (; it != a.end() && *it < (1 << i); it++) {
      int u = *it;
      for (int v : basis) u = std::min(u, u ^ v);
      if (u) {
        basis.push_back(u);
        vec.push_back(*it);
        for (int j = basis.size() - 1; j > 0 && basis[j] > basis[j - 1]; j--)
          std::swap(basis[j], basis[j - 1]);
      }
    }
    if (basis.size() == i) x = i;
  }
  int c = 0;
  printf("%d\n0 ", x);
  for (int i = 1; i < (1 << x); i++) {
    printf("%d ", c ^= vec[__builtin_ctz(i)]);
  }
  printf("\n");
  return 0;
}
