#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
long long __pow(long long x, long long y, long long M) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % M;
    y >>= 1;
    x = (x * x) % M;
  }
  return res % M;
}
long long __pow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y >>= 1;
    x = (x * x);
  }
  return res;
}
long long mi(long long x, long long M) { return __pow(x, M - 2, M); }
long long mul(vector<long long> a, long long M) {
  long long res = 1;
  for (auto x : a) res = (res * x) % M;
  return res;
}
long long cl(long long a, long long b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
void umax(long long &a, long long b) { a = max(a, b); }
void umin(long long &a, long long b) { a = min(a, b); }
const long long N = 2e5 + 2, inf = 1e18, M = 998244353, LN = 20;
long long Test, n, m, k, q, a[N];
bool ok = 1;
class BIT {
  long long n, VAL;
  vector<long long> bit;

 public:
  BIT() {}
  BIT(long long _n, long long val) {
    n = _n;
    VAL = val;
    bit.assign(2 * n + 2, VAL);
  }
  long long todo(long long a, long long b) { return a + b; }
  void update(long long i, long long x) {
    i++;
    for (; i <= n; i += (i & -i)) bit[i] = todo(bit[i], x);
  }
  long long get(long long i) {
    i++;
    long long res = VAL;
    for (; i; i -= (i & -i)) res = todo(res, bit[i]);
    return res;
  }
};
void test_case() {
  cin >> n;
  vector<BIT> trees(512);
  for (long long i = 0; i <= 511; i++) trees[i] = BIT(512, 0);
  vector<bool> vis(512);
  vis[0] = 1;
  long long cnt = 1;
  for (long long i = 1, x; i <= n; i++) {
    cin >> x;
    if (!vis[x]) cnt++;
    vis[x] = 1;
    trees[x].update(x, 1);
    for (long long j = 1; j <= 511; j++)
      if (x > 0 && (x ^ j) > 0 && trees[x ^ j].get(x - 1) > 0)
        cnt += !vis[j], vis[j] = 1, trees[j].update(x, 1);
  }
  cout << cnt << '\n';
  for (long long i = 0; i < 512; i++)
    if (vis[i]) cout << i << " ";
  cout << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Test = 1;
  for (long long t = 1; t <= Test; t++) {
    test_case();
  }
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

This is an easier version of the problem with smaller constraints.

Korney Korneevich dag up an array a of length n. Korney Korneevich has recently read about the operation [bitwise XOR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR), so he wished to experiment with it. For this purpose, he decided to find all integers x ≥ 0 such that there exists an increasing subsequence of the array a, in which the bitwise XOR of numbers is equal to x.

It didn't take a long time for Korney Korneevich to find all such x, and he wants to check his result. That's why he asked you to solve this problem!

A sequence s is a subsequence of a sequence b if s can be obtained from b by deletion of several (possibly, zero or all) elements.

A sequence s_1, s_2, … , s_m is called increasing if s_1 < s_2 < … < s_m.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5).

The second line contains n integers a_1, a_2, …, a_n (0 ≤ a_i ≤ 500) — the elements of the array a.

Output

In the first line print a single integer k — the number of found x values.

In the second line print k integers in increasing order x_1, x_2, … x_k (0 ≤ x_1 < … < x_k) — found x values.

Examples

Input


4
4 2 2 4


Output


4
0 2 4 6 


Input


8
1 0 1 7 12 5 3 2


Output


12
0 1 2 3 4 5 6 7 10 11 12 13 

Note

In the first test case:

  * To get value x = 0 it is possible to choose and empty subsequence 
  * To get value x = 2 it is possible to choose a subsequence [2] 
  * To get value x = 4 it is possible to choose a subsequence [4] 
  * To get value x = 6 it is possible to choose a subsequence [2, 4] 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug &operator<<(const c &) {
    return *this;
  }
};
long long __pow(long long x, long long y, long long M) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % M;
    y >>= 1;
    x = (x * x) % M;
  }
  return res % M;
}
long long __pow(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x);
    y >>= 1;
    x = (x * x);
  }
  return res;
}
long long mi(long long x, long long M) { return __pow(x, M - 2, M); }
long long mul(vector<long long> a, long long M) {
  long long res = 1;
  for (auto x : a) res = (res * x) % M;
  return res;
}
long long cl(long long a, long long b) {
  if (a % b == 0) return a / b;
  return a / b + 1;
}
void umax(long long &a, long long b) { a = max(a, b); }
void umin(long long &a, long long b) { a = min(a, b); }
const long long N = 2e5 + 2, inf = 1e18, M = 998244353, LN = 20;
long long Test, n, m, k, q, a[N];
bool ok = 1;
class BIT {
  long long n, VAL;
  vector<long long> bit;

 public:
  BIT() {}
  BIT(long long _n, long long val) {
    n = _n;
    VAL = val;
    bit.assign(2 * n + 2, VAL);
  }
  long long todo(long long a, long long b) { return a + b; }
  void update(long long i, long long x) {
    i++;
    for (; i <= n; i += (i & -i)) bit[i] = todo(bit[i], x);
  }
  long long get(long long i) {
    i++;
    long long res = VAL;
    for (; i; i -= (i & -i)) res = todo(res, bit[i]);
    return res;
  }
};
void test_case() {
  cin >> n;
  vector<BIT> trees(512);
  for (long long i = 0; i <= 511; i++) trees[i] = BIT(512, 0);
  vector<bool> vis(512);
  vis[0] = 1;
  long long cnt = 1;
  for (long long i = 1, x; i <= n; i++) {
    cin >> x;
    if (!vis[x]) cnt++;
    vis[x] = 1;
    trees[x].update(x, 1);
    for (long long j = 1; j <= 511; j++)
      if (x > 0 && (x ^ j) > 0 && trees[x ^ j].get(x - 1) > 0)
        cnt += !vis[j], vis[j] = 1, trees[j].update(x, 1);
  }
  cout << cnt << '\n';
  for (long long i = 0; i < 512; i++)
    if (vis[i]) cout << i << " ";
  cout << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Test = 1;
  for (long long t = 1; t <= Test; t++) {
    test_case();
  }
  return 0;
}

```