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)

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 100
#define DIVISOR 1000000007

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    char *tmp = strtok(line, " ");
    int k = strtol(tmp, NULL, 10);
    for(i = 0; i < k; i++) {
        char *tmp = strtok(NULL, " ");
        arr[i] = strtol(tmp, NULL, 10);
    }
#else
#error
#endif
    return k;
}

#define NUM_MAX 28
#define K_MAX 18

int main(void) {
    int arr[NUM_MAX+1];
    int num = get_int();
    int k = fget_array(arr, K_MAX+1);
    int i;
    int match = 0;
    for(i = 0; i < k; i++) {
        match |= (1<<arr[i]);
    }
    int pat;
    // see https://kimiyuki.net/blog/2017/07/16/enumerate-sets-with-bit-manipulation/
    for(pat = 0;; pat = (pat-match)&match) {
        printf("%d:", pat);
        for(i = 0; i < num; i++) {
            if(!(pat & (1<<i))) continue;
            printf(" %d", i);
        }
        putchar('\n');
        if(pat == match) break;
    }
    return 0;
}