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 C# (judge verdict: Accepted)

using System.Text;
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int sum { get; set; }
    public int times { get; set; }
    public long b { get; set; }
}

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var k = int.Parse(line[0]);
        if (k == 0) { Console.WriteLine("0:"); goto end; }
        var b = new int[k];
        for (int i = 0; i < k; i++) b[i] = int.Parse(line[i + 1]);
        var ps = getAns(b, n);
        print(ps, b);
        end:;
    }
    public static List<P> getAns(int[] b, int n)
    {
        var ps = new List<P>();
        var p = new int[n];
        for (int i = 0; i < n; i++) p[i] = 1 << i;
        var q = new Queue<P>();
        var w = new P();
        q.Enqueue(w);
        var w1 = new P();
        w1.b = 1L << b[0];
        q.Enqueue(w1);
        while (q.Count() > 0)
        {
            var w2 = q.Dequeue();
            if (w2.times == b.Length - 1)
            {
                foreach (var x in b)
                    if (((w2.b >> x) & 1) == 1) w2.sum += p[x];
                ps.Add(w2);
            }
            else
            {
                var w3 = new P();
                w3.b = w2.b;
                w2.times++;
                w3.times = w2.times;
                w2.b |= 1L << b[w2.times];
                q.Enqueue(w2);
                q.Enqueue(w3);
            }
        }
        return ps;
    }
    public static void print(List<P> ps, int[] b)
    {
        var sb = new StringBuilder();
        foreach (var x in ps.OrderBy(y => y.sum))
            if (x.b == 0) sb.Append(string.Format("0:\n"));
            else
            {
                sb.Append(string.Format("{0}: ", x.sum));
                sb.Append(string.Join(" ", b.Where(y => ((x.b >> y) & 1) == 1)));
                sb.Append("\n");
            }
        Console.Write(sb);
    }
}