#include <bits/stdc++.h>
using namespace std;
int a[1 << 19], ans[1 << 19], base[20], val[20];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  int s = 0, cnt = 0;
  for (int i = 1, j = 1; i < 20; i++) {
    for (; j <= n && a[j] < 1 << i; j++) {
      int x = a[j];
      for (int k = 19; ~k; k--)
        if (x & 1 << k) {
          if (!base[k]) cnt++, base[k] = x, val[k] = a[j];
          x ^= base[k];
        }
    }
    if (cnt == i) s = i;
  }
  cout << s << endl;
  cout << (ans[0] = 0);
  for (int i = 0; i < s; i++)
    for (int j = 0; j < 1 << i; j++)
      cout << ' ' << (ans[j ^ 1 << i] = ans[(1 << i) - 1 ^ j] ^ val[i]);
  return 0;
}
