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] 
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
 import java.util.*;
public  class realfast implements Runnable 
  {
    private static final int INF = (int) 1e9;
    long in= 1000000007;
    long fac[]= new long[1000001];
    long inv[]=new long[1000001];
    public  void solve() throws IOException 
    {

        //int t = readInt();

        int n = readInt();
        int arr[]=new int[n];
        int min[]=new int[512];

        for(int i =0;i<n;i++)
            arr[i]= readInt();
        Arrays.fill(min,100000);
        int temp[]=new int [512];
        for(int i =0;i<n;i++)
        {
            
           
            for(int j =0;j<512;j++)
            {
                  if(min[j]<arr[i])
                  {
                       int d = j^arr[i];
                       min[d]=Math.min(min[d],arr[i]);
                  }
            }

            
            min[arr[i]]=Math.min(min[arr[i]],arr[i]);
        }
       
        ArrayList<Integer> c = new ArrayList<Integer>();
        c.add(0);
        for(int i =1;i<512;i++)
        {
               if(min[i]!=100000)
               {
               
                c.add(i);
               }
        }
        out.println(c.size());
        for(int i =0;i<c.size();i++)
            out.print(c.get(i)+" ");

        out.println();






       
        

    }
    public void set(int arr[] , int i , int j , int brr[])
    {
        if(Math.abs(arr[i])==Math.abs(arr[j]))
        {
            if(arr[i]*arr[j]<0)
            {
                brr[i]=1;
                brr[j]=1;
            }
            else
            {
                brr[i]=-1;
                brr[j]=1;
            }
        }
        else
        {
            if(arr[i]*arr[j]<0)
            {
                brr[i]=Math.abs(arr[j]);
                brr[j]=Math.abs(arr[i]);
            }
            else
            {
                brr[i]=-Math.abs(arr[j]);
                brr[j]=Math.abs(arr[i]);  
            }
        }

    }
    public void set3(int arr[], int i , int j , int k, int brr[])
    {
        if((arr[i]+arr[j])==0)
        {
            if((arr[i]+arr[k])!=0)
            {
                 int temp=j;
                 j=k;
                 k=temp;
            }
            else
            {
                 int temp=i;
                 i=k;
                 k=temp;

            }

        }

        if((arr[i]+arr[j])*arr[k]<0)
        {
            brr[k]=Math.abs(arr[i]+arr[j]);
            brr[i]= Math.abs(arr[k]);
            brr[j]=Math.abs(arr[k]);
        }
        else
        {
             brr[k]=-Math.abs(arr[i]+arr[j]);
            brr[i]= Math.abs(arr[k]);
            brr[j]=Math.abs(arr[k]);

        }



    }
    
    

    
    public int value (int seg[], int left , int right ,int index, int l, int r)
    {
            
            if(left>right)
            {
              return -100000000;
            }
            if(right<l||left>r)
                return -100000000;
            if(left>=l&&right<=r)
                return seg[index];
            int mid = left+(right-left)/2;
            int val = value(seg,left,mid,2*index+1,l,r);
            int val2 = value(seg,mid+1,right,2*index+2,l,r);
            return Math.max(val,val2);

    }
   
    public int gcd(int a , int b )
    {
      if(a<b)
      {
        int t =a;
        a=b;
        b=t;
      }
      if(a%b==0)
        return b ;
      return gcd(b,a%b);
    }
    public long pow(long n , long p,long m)
    {
         if(p==0)
            return 1;
        long val = pow(n,p/2,m);;
        val= (val*val)%m;
        if(p%2==0)
            return val;
        else
            return (val*n)%m;
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    public static void main(String[] args) {
        new Thread(null, new realfast(), "", 128 * (1L << 20)).start();
    }
 
    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    private BufferedReader reader;
    private StringTokenizer tokenizer;
    private PrintWriter out;
 
    @Override
    public void run() {
        try {
            if (ONLINE_JUDGE || !new File("input.txt").exists()) {
                reader = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            } else {
                reader = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            }
            solve();
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                // nothing
            }
            out.close();
        }
    }
 
    private String readString() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
 
    @SuppressWarnings("unused")
    private int readInt() throws IOException {
        return Integer.parseInt(readString());
    }
 
    @SuppressWarnings("unused")
    private long readLong() throws IOException {
        return Long.parseLong(readString());
    }
 
    @SuppressWarnings("unused")
    private double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }
}
class edge implements Comparable<edge>{
    int u ;
    int v;
    
    edge(int u, int v)
    {
       this.u=u;
       this.v=v;
    }
    public int compareTo(edge e)
    {
        return Math.abs(this.v)-Math.abs(e.v);
    }
}