Codeforces Round 750 (Div. 2)
F1
Korney Korneevich and XOR (easy version)
Codeforces
1800
原题
← EF2 →
翻译中…

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, so he wished to experiment with it. For this purpose, he decided to find all integers $x \ge 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, \ldots , s_m$ is called increasing if $s_1 \lt s_2 \lt \ldots \lt s_m$.

翻译中…

Input

翻译中…

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

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 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, \ldots x_k$ ($0 \le x_1 \lt \ldots \lt x_k$) — found $x$ values.

翻译中…

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]$
翻译中…

样例

Input #1
4
4 2 2 4
Output #1
4
0 2 4 6
InputCopy OutputCopy
Input #2
8
1 0 1 7 12 5 3 2
Output #2
12
0 1 2 3 4 5 6 7 10 11 12 13
InputCopy OutputCopy
题目信息
题号
1582F1
时间限制
1.5 s
内存限制
512 MB
标签
位运算
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。