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] 
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(I,v,b) for(int I=v;I<b;I++)
#define ROF(I,v,b) for(int I=v;I>=b;I--)
#define vec vector
#define vi vec<int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(),x.end()
#define sgm(x) x.begin(),x.begin()
#define testcases int tc;cin>>tc;while(tc--)
#define mem(v,k) memset(v,k,sizeof(v))
#define FF first
#define SS second
#define rt return
#define br break
#define ct continue
#define endl "\n"
#define ii pair<int,int>
#define vecin(v,n,index) for(int I=index;I<n;I++)cin>>v[I];
#define vecout(v,n,index) for(int I=index;I<n;I++)cout<<v[I]<<" ";cout<<endl;

int isPossible(vi &k, int n, int prev, int x, int cur, auto &dp) {
    if (dp[n][cur][prev] != -1)rt dp[n][cur][prev];
    if (cur == x)rt dp[n][cur][prev] = 1;
    if (n == 0)rt dp[n][cur][prev] = 0;
    int res = isPossible(k, n - 1, prev, x, cur, dp);
    if (prev > k[n - 1])res |= isPossible(k, n - 1, k[n - 1], x, cur ^ (k[n - 1]), dp);
    rt dp[n][cur][prev] = res;
}
void solve() {
    int n;
    cin >> n;
    vi v(n);
    vecin(v, n, 0);
    map<int, int> vs;
    vi k;
    FOR(i, 0, n) {
        if (vs[v[i]]) {
            if (v[i] > k.back())k.pb(v[i]);
            ct;
        }
        k.pb(v[i]);
        vs[v[i]] = 1;
    }
    n = k.size();
    int maxe = *max_element(all(k));
    int s = ceil(log2(maxe));
    int mxor = (1LL << (s + 1)) - 1;
    vi ans(1);
    FOR(x, 1, mxor + 1) {
        int cur = 0;
        vec<vec<vi>> dp(n + 1, vec<vi> (mxor + 1, vi(502, -1)));
        if (isPossible(k, n, 501, x, cur, dp)) {
            ans.pb(x);
        }
    }
    vecout(ans, ans.size(), 0);
}

signed main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    ios_base::sync_with_stdio(false);   cin.tie(NULL);  cout.tie(NULL);

    // testcases
    solve();
}



