Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/bit-qism-toplamlarni-sanash

Enumerating subsets

Easy 1000 ms 128 MB 33%
Share

$n$ numbers $a_{0}, a_{1}, \ldots, a_{n-1}$ are given. Every number $0 \le m \lt 2^{n}$ defines one subset: if the $j$-th bit of $m$ is $1$, then $a_{j}$ belongs to the subset. Print every subset on a separate line in the order $m = 0, 1, 2, \ldots, 2^{n} - 1$: first the number of elements, then the elements themselves (in increasing order of $j$).

Rows of bitmasks; next to each, the elements chosen by the set bits as a subset

Input

The first line contains a positive integer $n$. The second line contains $n$ positive integers $a_{j}$.

Output

$2^{n}$ lines: each with the number of elements and the elements of the subset.

Note

$1 \le n \le 15$
$1 \le a_{j} \le 100$

Examples

Input #1
3
5 8 2
Output #1
0
1 5
1 8
2 5 8
1 2
2 5 2
2 8 2
3 5 8 2
Input #2
1
7
Output #2
0
1 7

Sign in to submit a solution

Signing up is free and takes a minute.