Problem:
Enumeration of Subsets III

You are given a set $T$, which is a subset of $S$. The set $S$ consists of $0, 1, ... n-1$.

Print all subsets of $T$.

Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements.

Input

The input is given in the following format.

$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$

$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.

Output

Print the subsets ordered by their decimal integers. Print a subset in the following format.

$d$: $e_0$ $e_1$ ...

Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.

Constraints

$1 \leq n \leq 28$

$0 \leq k \leq 18$

$k \leq n$

$0 \leq b_i < n$

Sample Input 1

4
2 0 2

Sample Output 1

0:
1: 0
4: 2
5: 0 2

Solution in Go (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func increment(bits []bool) bool {
	i := 0
	for i < len(bits) && bits[i] {
		bits[i] = false
		i++
	}
	if i < len(bits) {
		bits[i] = true
	} else {
		return false
	}
	return true
}

func contains(bits uint, queryBits uint) bool {
	// fmt.Printf("%v %v %b %b %b\n", bits, queryBits, bits, ^queryBits, bits & ^queryBits)
	return (bits & ^queryBits) == 0
}

func compress(b []bool) uint {
	n := len(b)

	queryBits := uint(0)
	for i := n - 1; i >= 0; i-- {
		if b[i] {
			queryBits++
		}
		if i != 0 {
			queryBits = queryBits << 1
		}
	}

	return queryBits
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()

	k := nextInt()
	b := make([]bool, n)
	for i := 0; i < k; i++ {
		b[nextInt()] = true
	}

	queryBits := compress(b)

	i := uint(0)
	iMax := uint(math.Pow(2.0, float64(n)))
	nPrinted := uint(0)
	nPrintedMax := uint(math.Pow(2.0, float64(k)))
	for i < iMax {
		if contains(i, queryBits) {
			cache := []string{}
			for j := 0; j < n; j++ {
				if (i & (1 << uint(j))) > 0 {
					cache = append(cache, strconv.Itoa(j))
				}
			}
			if i == 0 {
				fmt.Println("0:")
			} else {
				fmt.Printf("%v: %v\n", i, strings.Join(cache, " "))
			}
			nPrinted++
		}
		i++
		if nPrinted >= nPrintedMax {
			break
		}
	}
}