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/problemset/problem/1582/F1
  // Memory Limit: 512 MB
  // Time Limit: 1500 ms
  // 
  // Powered by CP Editor (https://cpeditor.org)
  
  
  
  
  import java.io.*;
  import java.math.BigDecimal;
  import java.math.BigInteger;
  import java.math.MathContext;
  import java.math.RoundingMode;
  import java.util.*;
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.util.Collections;
  import java.io.InputStreamReader;
  import static java.lang.Math.*;
  import static java.lang.System.*;
  
  public class Main {
  
  
     
           
  
  
      public static void main(String[] args) throws IOException {
  
  //        try {
  //             Scanner in = new Scanner(System.in) ;
          FastScanner in = new FastScanner();
          PrintWriter out = new PrintWriter(System.out);
  
  
  
          int n = in.nextInt() ;
          int a[] = in.readArray(n) ;
          int dp[] = new int[520] ;
          Arrays.fill(dp , (int)1e6) ;
          dp[0] = 0 ;
          
          for(int i=0 ; i<n ; i++){
          	for(int j=0 ; j<=512 ; j++){
          		if(dp[j] < a[i]){
          			dp[j^a[i]] = min(dp[j^a[i]] , a[i]) ;
          		}
          	}
          	
          }
          
          int ans = 0 ;
          StringBuilder sb = new StringBuilder() ;
          
          for(int i=0 ; i<dp.length ; i++){
          	if(dp[i] == (int)1e6) continue ;
          	ans++ ;
          	sb.append(i + " ") ;
          }
          
          System.out.println(ans) ;
          System.out.println(sb) ;
          
          
          
          
          
          	
  
  
  
  
  
  
  
  
  
          out.flush();
          out.close();
  
  
  //        } catch (Exception e) {
  //            return;
  //        }
  
      }
  
      static long gcd(long a, long b) {
          return (b == 0) ? a : gcd(b, a % b);
      }
  
      static int gcd(int a, int b) {
          return (b == 0) ? a : gcd(b, a % b);
      }
  
      static void sort(int ar[]) {
          int n = ar.length;
          ArrayList<Integer> a = new ArrayList<>();
          for (int i = 0; i < n; i++)
              a.add(ar[i]);
          Collections.sort(a);
          for (int i = 0; i < n; i++)
              ar[i] = a.get(i);
      }
  
      static void sort1(long ar[]) {
          int n = ar.length;
          ArrayList<Long> a = new ArrayList<>();
          for (int i = 0; i < n; i++)
              a.add(ar[i]);
          Collections.sort(a);
          for (int i = 0; i < n; i++)
              ar[i] = a.get(i);
      }
  
      static long ncr(long n, long r, long mod) {
          if (r == 0)
              return 1;
          long val = ncr(n - 1, r - 1, mod);
          val = (n * val) % mod;
          val = (val * modInverse(r, mod)) % mod;
          return val;
      }
  
      static long fast_pow(long base, long n, long M) {
          if (n == 0)
              return 1;
          if (n == 1)
              return base % M;
          long halfn = fast_pow(base, n / 2, M);
          if (n % 2 == 0)
              return (halfn * halfn) % M;
          else
              return (((halfn * halfn) % M) * base) % M;
      }
  
      static long modInverse(long n, long M) {
          return fast_pow(n, M - 2, M);
      }
  
  
      static class FastScanner {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          StringTokenizer st = new StringTokenizer("");
  
          String next() {
              while (!st.hasMoreTokens())
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              return st.nextToken();
          }
  
          int nextInt() {
              return Integer.parseInt(next());
          }
  
          int[] readArray(int n) {
              int[] a = new int[n];
              for (int i = 0; i < n; i++) a[i] = nextInt();
              return a;
          }
  
  
          long nextLong() {
              return Long.parseLong(next());
          }
      }
  
  
  }
  
  
  
  
  
  
  
  