description: 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] 
solution: import java.util.*;
  import java.io.*;
  //import javafx.util.*;
  
  public class Solution
  {
         static class Reader {
          final private int BUFFER_SIZE = 1 << 16;
          private DataInputStream din;
          private byte[] buffer;
          private int bufferPointer, bytesRead;
   
          public Reader()
          {
              din = new DataInputStream(System.in);
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
   
          public Reader(String file_name) throws IOException
          {
              din = new DataInputStream(
                  new FileInputStream(file_name));
              buffer = new byte[BUFFER_SIZE];
              bufferPointer = bytesRead = 0;
          }
   
          public String readLine() throws IOException
          {
              byte[] buf = new byte[64]; // line length
              int cnt = 0, c;
              while ((c = read()) != -1) {
                  if (c == '\n') {
                      if (cnt != 0) {
                          break;
                      }
                      else {
                          continue;
                      }
                  }
                  buf[cnt++] = (byte)c;
              }
              return new String(buf, 0, cnt);
          }
   
          public int nextInt() throws IOException
          {
              int ret = 0;
              byte c = read();
              while (c <= ' ') {
                  c = read();
              }
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
   
              if (neg)
                  return -ret;
              return ret;
          }
   
          public long nextLong() throws IOException
          {
              long ret = 0;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
              if (neg)
                  return -ret;
              return ret;
          }
   
          public double nextDouble() throws IOException
          {
              double ret = 0, div = 1;
              byte c = read();
              while (c <= ' ')
                  c = read();
              boolean neg = (c == '-');
              if (neg)
                  c = read();
   
              do {
                  ret = ret * 10 + c - '0';
              } while ((c = read()) >= '0' && c <= '9');
   
              if (c == '.') {
                  while ((c = read()) >= '0' && c <= '9') {
                      ret += (c - '0') / (div *= 10);
                  }
              }
   
              if (neg)
                  return -ret;
              return ret;
          }
   
          private void fillBuffer() throws IOException
          {
              bytesRead = din.read(buffer, bufferPointer = 0,
                                   BUFFER_SIZE);
              if (bytesRead == -1)
                  buffer[0] = -1;
          }
   
          private byte read() throws IOException
          {
              if (bufferPointer == bytesRead)
                  fillBuffer();
              return buffer[bufferPointer++];
          }
   
          public void close() throws IOException
          {
              if (din == null)
                  return;
              din.close();
          }
      }
      static int parent(int x , int p[])
      {
             if(p[x] == x)
             return x;
             
             return (p[x] = parent(p[x],p));
      }
      
      static void union(int a , int b , int p[] , int size[])
      {
             a = parent(a,p);
             b = parent(b,p);
             
             if(size[a] < size[b])
             {
                    int temp = a;
                    a = b;
                    b = temp;
             }
             p[b] = a;
             size[a] += size[b];
      }
     // int ass;
      
      static long mod = 1000000007;
      static long pow(long a , long b)
      {
             if(b == 0)
             return 1;
             
             long ans = pow(a,b/2);
             if(b%2 == 0)
             return ans*ans%mod;
             
             return ans*ans%mod*a%mod;
      }
      
      
      
      
    public static void main(String []args) throws IOException
    {
           Reader sc = new Reader();
           int n = sc.nextInt();
           int arr[] = new int[n];
           for(int i = 0 ; i < n ; i++)
           {
                  arr[i] = sc.nextInt();
           }
           int min[] = new int[513];
           for(int i = 0 ; i <= 512 ; i++)
           {
                  min[i] = Integer.MAX_VALUE;
           }
           for(int i = 0 ; i < n ; i++)
           {
                  for(int j = 0 ; j <= 512 ; j++)
                  {
                         if(min[j] < arr[i])
                         {
                                min[j^arr[i]] = Math.min(min[j^arr[i]] , arr[i]);
                         }
                  }
                  min[arr[i]] = Math.min(min[arr[i]] , arr[i]);
           }
           
           int ans = 0;
           StringBuffer str = new StringBuffer("");
           min[0] = 0;
           for(int i = 0 ; i <= 512 ; i++)
           {
                  if(min[i] != Integer.MAX_VALUE)
                  {
                  ans++;
                  str.append(i + " ");
                  }
           }
           System.out.println(ans);
           System.out.println(str);
    }
  }