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: // Problem: F1. Korney Korneevich and XOR (easy version)
  // Contest: Codeforces - Codeforces Round #750 (Div. 2)
  // URL: https://codeforces.com/contest/1582/problem/F1
  // Memory Limit: 512 MB
  // Time Limit: 1500 ms
  // 
  // Powered by CP Editor (https://cpeditor.org)
  
  import java.io.*;
  import java.util.*;
  
  import static java.lang.Math.max;
  import static java.lang.Math.min;
  import static java.lang.Math.abs;
  
  
  /**
   * zxz 
   * problem link:
   **/
  public class Main {
      //put some data here
  
      /**
       * do some clean action before next testcase
       */
      private void clear() {
  
      }
  
  
      private void solve() throws Exception {
          rf();
          int n = ri();
          // int m = ri();
          int [] data = readArr(n);
          
  		int [] idx = new int[512];
  		Arrays.fill(idx, Integer.MAX_VALUE);
          
          idx[0] = 0;
          for(int i = 0; i < n; i++){
          	idx[data[i]] = min(idx[data[i]], data[i]);
          	for(int j = 0; j < 512; j++){
          		if(idx[j]  < data[i]){
          			int t = j ^ data[i];
          			if(idx[t] > data[i]){
          				idx[t] = data[i];
          			}
          		}
          	}
          }
          int cnt = 0;
          for(int i : idx){
          	if(i != Integer.MAX_VALUE){
      			cnt++;
      		}
          }
          addAns(cnt);
          for(int j = 0; j < 512; j++){
      		if(idx[j]  != Integer.MAX_VALUE){
      			sb.append(j + " ");
      		}
      	}
  		sb.append("\n");
      }
  
      private void run() throws Exception {
  
  
          int T = 1;
  
          while (T-- > 0) {
              solve();
              if (T != 0) {
                  clear();
              }
          }
          printAns();
      }
  
      public static void main(String[] args) throws Exception {
          new Main().run();
      }
  
      StringBuilder sb = new StringBuilder();
      BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st;
  
  	private void addAns(int a){
  		sb.append(a + "\n");
  	}
  	
  	private void addAns(long a){
  		sb.append(a + "\n");
  	}
  	
  	private void addAns(String s){
  		sb.append(s + "\n");
  	}
  
      private void rf() throws IOException {
          st = new StringTokenizer(infile.readLine());
      }
  
  
      private int ri() {
          return Integer.parseInt(st.nextToken());
      }
  
      private long rl() {
          return Long.parseLong(st.nextToken());
      }
  
  	private char [] rs2c(){
  		return st.nextToken().toCharArray();
  	}
  	
  	private String rs(){
  		return st.nextToken();
  	}
  
      private void printAns() {
          System.out.println(sb);
      }
  
      private int[] readArr(int N) throws Exception {
          int[] arr = new int[N];
          rf();
          for (int i = 0; i < N; i++) {
              arr[i] = Integer.parseInt(st.nextToken());
          }
          return arr;
      }
  
      private void print(int[] arr) {
          //for debugging only
          for (int x : arr) {
              System.out.print(x + " ");
          }
          System.out.println();
      }
      
      private void print(long[] arr) {
          //for debugging only
          for (long x : arr) {
              System.out.print(x + " ");
          }
          System.out.println();
      }
  
      private long[] readArr2(int N) throws Exception {
          long[] arr = new long[N];
          st = new StringTokenizer(infile.readLine());
          for (int i = 0; i < N; i++) {
              arr[i] = Long.parseLong(st.nextToken());
          }
          return arr;
      }
  
      private boolean isPrime(long n) {
          if (n < 2) {
              return false;
          }
          if (n == 2 || n == 3) {
              return true;
          }
          if (n % 2 == 0 || n % 3 == 0) {
              return false;
          }
          long sqrtN = (long) Math.sqrt(n) + 1;
          for (long i = 6L; i <= sqrtN; i += 6) {
              if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                  return false;
              }
          }
          return true;
      }
  
      private long gcd(long a, long b) {
          if (a > b) {
              a = (a + b) - (b = a);
          }
          if (a == 0L) {
              return b;
          }
          return gcd(b % a, a);
      }
      
      private int gcd(int a, int b) {
          if (a > b) {
              a = (a + b) - (b = a);
          }
          if (a == 0) {
              return b;
          }
          return gcd(b % a, a);
      }
      
      private double pow(double x, long N) {
          double ans = 1.0;
          // 贡献的初始值为 x
          double x_contribute = x;
          // 在对 N 进行二进制拆分的同时计算答案
          while (N > 0) {
              if (N % 2 == 1) {
                  // 如果 N 二进制表示的最低位为 1，那么需要计入贡献
                  ans *= x_contribute;
              }
              // 将贡献不断地平方
              x_contribute *= x_contribute;
              // 舍弃 N 二进制表示的最低位，这样我们每次只要判断最低位即可
              N /= 2;
          }
          return ans;
      }
      
      long pow_mod(long x, long i, long mod){
  	    if(i == 0){
  	        return 1;
  	    }
  	    long temp = pow_mod(x, i >> 1, mod);
  	    temp = temp * temp % mod;
  	    if((i & 1 )!= 0){
  	        temp = temp * x % mod;
  	    }
  	    return temp;
  	}
      
  
  }
  