#P1582F1. Korney Korneevich and XOR (easy version)

Korney Korneevich and XOR (easy version)

Description

This is an easier version of the problem with smaller constraints.

Korney Korneevich dag up an array aa of length nn. Korney Korneevich has recently read about the operation bitwise XOR, so he wished to experiment with it. For this purpose, he decided to find all integers x0x \ge 0 such that there exists an increasing subsequence of the array aa, in which the bitwise XOR of numbers is equal to xx.

It didn't take a long time for Korney Korneevich to find all such xx, and he wants to check his result. That's why he asked you to solve this problem!

A sequence ss is a subsequence of a sequence bb if ss can be obtained from bb by deletion of several (possibly, zero or all) elements.

A sequence s1,s2,,sms_1, s_2, \ldots , s_m is called increasing if s1<s2<<sms_1 < s_2 < \ldots < s_m.

The first line contains a single integer nn (1n1051 \le n \le 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai5000 \le a_i \le 500) — the elements of the array aa.

In the first line print a single integer kk — the number of found xx values.

In the second line print kk integers in increasing order x1,x2,xkx_1, x_2, \ldots x_k (0x1<<xk0 \le x_1 < \ldots < x_k) — found xx values.

Input

The first line contains a single integer nn (1n1051 \le n \le 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai5000 \le a_i \le 500) — the elements of the array aa.

Output

In the first line print a single integer kk — the number of found xx values.

In the second line print kk integers in increasing order x1,x2,xkx_1, x_2, \ldots x_k (0x1<<xk0 \le x_1 < \ldots < x_k) — found xx values.

Samples

样例输入 1

4
4 2 2 4

样例输出 1

4
0 2 4 6

样例输入 2

8
1 0 1 7 12 5 3 2

样例输出 2

12
0 1 2 3 4 5 6 7 10 11 12 13

Note

In the first test case:

  • To get value x=0x = 0 it is possible to choose and empty subsequence
  • To get value x=2x = 2 it is possible to choose a subsequence [2][2]
  • To get value x=4x = 4 it is possible to choose a subsequence [4][4]
  • To get value x=6x = 6 it is possible to choose a subsequence [2,4][2, 4]