Problem:
Enumeration of Combinations Print all combinations which can be made by $k$ different elements from $0, 1, ..., n-1$.

  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 combination is calculated by bitwise OR of the selected elements. Input The input is given in the following format. $n \; k$ Output Print the combinations ordered by their decimal integers. Print a combination in the following format. $d$: $e_0$ $e_1$ ... Print ' : ' after the integer value $d$, then print elements $e_i$ in the combination in ascending order. Separate two adjacency elements by a space character. Constraints  $1 \leq n \leq 18$  $k \leq n$  Sample Input 1 5 3 Sample Output 1 7: 0 1 2
11: 0 1 3
13: 0 2 3
14: 1 2 3
19: 0 1 4
21: 0 2 4
22: 1 2 4
25: 0 3 4
26: 1 3 4
28: 2 3 4

Solution (Python):
from itertools import combinations
n, k = map(int, input().split())
a = [i for i in range(n)]
rs = []
for c in combinations(a, k):
    tmp = sum(1 << i for i in c)
    rs.append([tmp, *c])
for ans in sorted(rs):
    print(str(ans[0]) + ":", *ans[1:])

Solution (Python):
from itertools import combinations

n,k = map(int,input().split())

num = [i for i in range(n)]
ans = []
for i in combinations(num,k):
    comb = list(i)
    comb.reverse()

    s = 0
    for j in comb:
        s += 2**j
    ans.append([s,list(i)])

ans.sort()
for i,j in ans:
    print(str(i)+":",*j)

Solution (Python):
from itertools import combinations

n, k = map(int, input().split())
for n, combi in sorted([(sum([1<<b for b in c]), ' '.join(map(str, c)))  for c in combinations(range(n), k)]):
    print(f'{n}: {combi}')

Solution (Python):
from itertools import combinations
n, k = map(int, input(). split())
l = [i for i in range(n)]
p = []
for i in combinations(l, k):
    num = 0
    for j in i:
        num |= 1 << j
    p.append((num, i))
    
p.sort()
for i, j in p:
    print("{}: ".format(i), end="")
    print(*j)

Solution (Python):
from itertools import combinations
n, k = [int(x) for x in input().split()]

L = [ x for x in range(n)]

p =[]
for l in (combinations(L, k)):
    num = 0
    for i in l:
        num |= 1<<i
    p.append((num,l))

p.sort()
for i, l in p:
    print("{}: ".format(i), end="")
    print( *l)

Solution (Python):
n, k = map(int, input().split())
ans = []
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if i>>j&1 ==1:
            cnt += 1
    if cnt == k:
        st = []
        for t in range(n):
            if i>>t&1 ==1:
                st.append(t)
        print("{}:".format(i),end =" ")
        print(*st)

Solution (Python):
from typing import List


if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())

    target: List[int] = []
    v = (1 << k) - 1
    while (v < (1 << n)):
        target.append(v)
        x = v & -v
        y = v + x
        v = ((v & ~y) // x >> 1) | y
    target.sort()

    for d in target:
        print(f"{d}: ", end="")
        print(" ".join(str(j) for j in range(n) if d & (1 << j)))

Solution (Python):

"""
Bitset II - Enumeration of Combinations
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_D&lang=jp

"""
from itertools import combinations

n, k = map(int, input().split())
for n, combi in sorted([(sum([1<<b for b in c]), ' '.join(map(str, c)))  for c in combinations(range(n), k)]):
    print(f'{n}: {combi}')

Solution (Python):
n, b = map(int,input().split())
for i in range(1<<n):
    ans = []
    _i = i
    cnt = 0
    _cnt = 0
    while i and _cnt < b+1:
        if i&1:
            ans.append(cnt)
            _cnt += 1
        cnt += 1
        i=i>>1
    if _cnt == b:
         
        print(f'{_i}:',end = '')
        if _i == 0:
            print()
        else:print("",*ans)

Solution (Python):
import itertools


n, k = map(int, input().split())

list_n = [i for i in range(n)]

list_d = []


for tuple_e in itertools.combinations(list_n, k):
    d = 0

    for bit in tuple_e:
        d += 2 ** bit

    list_d.append((d, tuple_e))


for d, tuple_e in sorted(list_d):
    if tuple_e:
        print(f"{d}: ", end="")
        print(*tuple_e)
    else:
        print(f"{d}:")

Solution (Python):

n, b = map(int,input().split())
for i in range(1<<n):
    ans = []
    _i = i
    cnt = 0
    _cnt = 0
    while i and _cnt < b+1:
        if i&1:
            ans.append(cnt)
            _cnt += 1
        cnt += 1
        i=i>>1
    if _cnt == b:
        
        print(f'{_i}:',end = '')
        if _i == 0:
            print()
        else:print("",*ans)

Solution (Python):
import itertools

n,k=map(int,input().split())

N=[i for i in range(n)]
All=list(itertools.combinations(N,k))
Calc=[sum([2**All[i][j] for j in range(k)]) for i in range(len(All))]
Calc_sort=sorted(Calc)

if k==0:
    print("0:")
else:
    while len(All)!=0:
        c=Calc_sort[0]
        x=Calc.index(c)
        print(str(c)+": "+' '.join(map(str,All[x])))
        All.pop(x)
        Calc.pop(x)
        Calc_sort.pop(0)

Solution (Python):
from itertools import combinations


def calc_int(arr):
    ret = 0
    for i in arr:
        ret += 1 << i
    return ret


n, k = map(int, input().split())
subsets = []
for sub in combinations(range(n), k):
    subsets.append((calc_int(sub), sub))
subsets.sort()

for sub in subsets:
    print('{}: {}'.format(sub[0], ' '.join(map(str, sub[1])))) if len(sub[1]) != 0 else print(f'{sub[0]}:')

Solution (Python):
import itertools

n, k = map(int, input().split())

l = range(n)
combs = list(itertools.combinations(l, k))

sumlist = []
for comb in combs:
    sum = 0
    for c in comb:
        sum += pow(2, c)
    sumlist.append(sum)

z = zip(sumlist, combs)
z = sorted(z)

sumlist, combs = zip(*z)

for sum, comb in zip(sumlist, combs):
    c_str = (' '.join(str(c) for c in comb))
    print(str(sum) + ": " + c_str)

Solution (Python):




def combination(n, k):
    """Yields all combinations of k numbers from n numbers.

    >>> list(combination(3, 2))
    [[0, 1], [0, 2], [1, 2]]
    """
    def _combination(i, j, a):
        if i > n:
            return
        if j == 0:
            yield nums(n, a)
        elif i <= n:
            yield from _combination(i+1, j-1, a | 1 << i)
            yield from _combination(i+1, j, a)

    yield from _combination(0, k, 0)


def nums(size, bit):
    """Returns list of bit positions where bit flag is on.

    >>> nums(4, 7)
    [0, 1, 2]
    """
    return [n for n in range(size) if bit & (1 << n)]


def bit(nums):
    """Returns a bit representation of nums.

    >>> bit([0, 1, 2])
    7
    """
    return sum(1 << n for n in nums)


def run():
    n, k = [int(i) for i in input().split()]
    for ns in sorted(combination(n, k), key=bit):
        print("{}: {}".format(bit(ns), " ".join([str(i) for i in ns])))


if __name__ == '__main__':
    run()

Solution (Python):
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N, K = map(int, readline().split())

R = []
v = (1 << K) - 1
while v < (1 << N):
    R.append(v)
    x = v & -v; y = v + x
    v = ((v & ~y) // x >> 1) | y
R.sort()
for i in R:
    write("%d: %s\n" % (i, " ".join(str(j) for j in range(N) if i & (1 << j))))