Kuro has just learned about permutations and he is really excited to create a new permutation type. He has chosen n distinct positive integers and put all of them in a set S. Now he defines a magical permutation to be:

  * A permutation of integers from 0 to 2^x - 1, where x is a non-negative integer. 
  * The [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of any two consecutive elements in the permutation is an element in S.



Since Kuro is really excited about magical permutations, he wants to create the longest magical permutation possible. In other words, he wants to find the largest non-negative integer x such that there is a magical permutation of integers from 0 to 2^x - 1. Since he is a newbie in the subject, he wants you to help him find this value of x and also the magical permutation for that x.

Input

The first line contains the integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in the set S.

The next line contains n distinct integers S_1, S_2, …, S_n (1 ≤ S_i ≤ 2 ⋅ 10^5) — the elements in the set S.

Output

In the first line print the largest non-negative integer x, such that there is a magical permutation of integers from 0 to 2^x - 1.

Then print 2^x integers describing a magical permutation of integers from 0 to 2^x - 1. If there are multiple such magical permutations, print any of them.

Examples

Input


3
1 2 3


Output


2
0 1 3 2 

Input


2
2 3


Output


2
0 2 1 3 

Input


4
1 2 3 4


Output


3
0 1 3 2 6 7 5 4 

Input


2
2 4


Output


0
0 

Input


1
20


Output


0
0 

Input


1
1


Output


1
0 1 

Note

In the first example, 0, 1, 3, 2 is a magical permutation since:

  * 0 ⊕ 1 = 1 ∈ S 
  * 1 ⊕ 3 = 2 ∈ S 
  * 3 ⊕ 2 = 1 ∈ S



Where ⊕ denotes [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) operation.
#include <bits/stdc++.h>
using namespace std;
namespace FastIO {
struct Reader {
 private:
  FILE* file;
  std::vector<char> buffer;
  int pos;
  void read();
  bool was;

 public:
  Reader(FILE* file_ = stdin, const int size_ = 1 << 16)
      : file(file_), buffer(size_, '\0'), pos(size_), was(true) {}
  operator bool() const { return was; }
  char getChar();
  std::string getStr();
  std::string getLine();
  template <typename T>
  T getInt();
  template <typename T>
  T getReal();
};
Reader& operator>>(Reader& reader, char& c) {
  return c = reader.getChar(), reader;
}
Reader& operator>>(Reader& reader, std::string& s) {
  return s = reader.getStr(), reader;
}
template <class T>
typename std::enable_if<std::is_floating_point<T>::value, Reader&>::type
operator>>(Reader& reader, T& t) {
  return t = reader.getReal<T>(), reader;
}
template <class T>
typename std::enable_if<std::is_integral<T>::value, Reader&>::type operator>>(
    Reader& reader, T& t) {
  return t = reader.getInt<T>(), reader;
}
template <class T>
Reader& operator>>(Reader& reader, std::vector<T>& vec) {
  for (auto& it : vec) {
    reader >> it;
  }
  return reader;
}
struct Writer {
 private:
  FILE* file;
  std::vector<char> buffer;
  int pos;
  int defaultPrecision, defaultWidth;
  char defaultFill;

 public:
  Writer(FILE* file_ = stdout, const int size_ = 1 << 16)
      : file(file_),
        buffer(size_, '\0'),
        pos(0),
        defaultPrecision(6),
        defaultWidth(0),
        defaultFill(' ') {}
  ~Writer() { flush(); }
  void flush() { putChar(EOF); }
  void setprecision(int precision) { defaultPrecision = precision; }
  void setw(int width) { defaultWidth = width; }
  void setfill(char fill) { defaultFill = fill; }
  int getPrecision() const { return defaultPrecision; }
  int getWidth() const { return defaultWidth; }
  char getFill() const { return defaultFill; }
  void putChar(char c);
  void putStr(const std::string&);
  template <typename T>
  void putInt(T value, int width = 0, char fill = ' ');
  template <typename T>
  void putReal(T value, int precision = 6, int width = 0, char fill = ' ');
};
Writer& operator<<(Writer& writer, const char c) {
  return writer.putChar(c), writer;
}
Writer& operator<<(Writer& writer, const std::string& s) {
  return writer.putStr(s), writer;
}
template <class T>
typename std::enable_if<std::is_floating_point<T>::value, Writer&>::type
operator<<(Writer& writer, const T& t) {
  writer.putReal(t, writer.getPrecision(), writer.getWidth(), writer.getFill());
  return writer;
}
template <class T>
typename std::enable_if<std::is_integral<T>::value, Writer&>::type operator<<(
    Writer& writer, const T& t) {
  writer.putInt(t, writer.getWidth(), writer.getFill());
  return writer;
}
}  // namespace FastIO
void gray(int n, vector<int>& m, int depth) {
  int t = (1 << (depth - 1));
  if (depth == 0) {
    m[0] = 0;
  } else {
    for (int i = 0; i < t; i++) {
      m[t + i] = m[t - i - 1] + (1 << (depth - 1));
    }
  }
  if (depth < n) {
    gray(n, m, depth + 1);
  }
}
int main() {
  FastIO::Reader cin;
  FastIO::Writer cout;
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  unordered_set<int> basis;
  basis.reserve(1 << 20);
  for (int x = 18; x >= 0; x--) {
    basis = {0};
    int cur = 0;
    vector<int> arr;
    for (int val : v) {
      if (cur ^ val < (1 << x)) {
        bool can = true;
        for (int active : basis) {
          can &= basis.find(active ^ val) == basis.end();
          if (!can) break;
        }
        if (can) {
          arr.push_back(val);
          vector<int> add_on;
          for (int active : basis) {
            add_on.push_back(active ^ val);
          }
          for (int add : add_on) {
            basis.insert(add);
          }
        }
      }
    }
    if (x == arr.size()) {
      cout << x << "\n";
      vector<int> masks(1 << x, 0);
      gray(x, masks, 0);
      for (int mask : masks) {
        int cur = 0;
        for (int bit = 0; bit < x; bit++) {
          if ((mask >> bit) & 1) {
            cur ^= arr[bit];
          }
        }
        cout << cur << " ";
      }
      return 0;
    }
    basis.clear();
  }
  return 0;
}
namespace FastIO {
void Reader::read() {
  if (!buffer.empty()) {
    buffer.resize(fread(&buffer[0], 1, (int)buffer.size(), file));
    pos = 0;
  }
}
char Reader::getChar() {
  if (pos == (int)buffer.size()) {
    read();
  }
  if (pos == (int)buffer.size()) {
    was = false;
    return EOF;
  } else {
    was = true;
    return buffer[pos++];
  }
}
std::string Reader::getStr() {
  char c = ' ';
  while (std::isspace(c)) {
    c = getChar();
  }
  std::string answ;
  while (c != EOF && !std::isspace(c)) {
    answ.push_back(c);
    c = getChar();
  }
  was = !answ.empty();
  return answ;
}
std::string Reader::getLine() {
  char c = '\n';
  while (c == '\n') {
    c = getChar();
  }
  std::string answ;
  while (c != '\n' && c != EOF) {
    answ.push_back(c);
    c = getChar();
  }
  was = !answ.empty();
  return answ;
}
template <typename T>
T Reader::getInt() {
  char c = '?';
  while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) {
    c = getChar();
  }
  bool positive = true;
  if (c == '-') {
    positive = false;
    c = getChar();
  }
  T answ(0);
  bool flag = false;
  while ('0' <= c && c <= '9') {
    flag = true;
    (answ *= 10) += (c - '0');
    c = getChar();
  }
  was = flag;
  return positive ? answ : -answ;
}
template <typename T>
T Reader::getReal() {
  bool flag = false;
  char c = '?';
  while (!(c == '-' || ('0' <= c && c <= '9') || c == EOF)) {
    c = getChar();
  }
  bool positive = (c != '-');
  if (c == '-') {
    c = getChar();
  }
  long long first = 0;
  while ('0' <= c && c <= '9') {
    flag = true;
    (first *= 10) += (c - '0');
    c = getChar();
  }
  was = flag;
  if (c != '.') {
    return T(positive ? first : -first);
  }
  c = getChar();
  long long second = 0, pow = 1;
  while ('0' <= c && c <= '9') {
    (second *= 10) += (c - '0');
    c = getChar();
    pow *= 10;
  }
  T answ = first + (T)second / (T)pow;
  return positive ? answ : -answ;
}
void Writer::putChar(char c) {
  if (pos == (int)buffer.size() || c == EOF) {
    fwrite(&buffer[0], 1, pos, file);
    pos = 0;
  }
  if (c != EOF) {
    buffer[pos++] = c;
  }
}
void Writer::putStr(const std::string& s) {
  for (auto it : s) {
    putChar(it);
  }
}
template <typename T>
void Writer::putInt(T value, int width, char fill) {
  bool positive = !(value < 0);
  if (value < 0) {
    value = -value;
  }
  char buf[24];
  int p = 0;
  do {
    buf[p++] = char(value % 10 + '0');
    value /= 10;
  } while (value > 0);
  if (!positive) {
    buf[p++] = '-';
  }
  while (p < width) buf[p++] = fill;
  while (p > 0) putChar(buf[--p]);
}
template <typename T>
void Writer::putReal(T value, int precision, int width, char fill) {
  putInt((long long)value, width - precision - 1, fill);
  value = std::abs(value - (long long)value);
  if (precision == 0) {
    return;
  }
  putChar('.');
  while (precision >= 6) {
    value *= 1000000;
    putInt((int)value, 6, '0');
    value -= (int)value;
    precision -= 6;
  }
  while (precision >= 3) {
    value *= 1000;
    putInt((int)value, 3, '0');
    value -= (int)value;
    precision -= 3;
  }
  while (precision >= 1) {
    value *= 10;
    putInt((int)value, 1, '0');
    value -= (int)value;
    precision -= 1;
  }
}
}  // namespace FastIO
