#!/usr/bin/env python3
import sys, random


def cmdlinearg(name, default=None):
    for arg in sys.argv:
        if arg.startswith(name + "="):
            return arg.split("=")[1]
    assert default is not None, name
    return default

random.seed(int(cmdlinearg('seed', sys.argv[-1])))


MAXN = int(sys.argv[1])
MAXM = int(sys.argv[2])
N = int(cmdlinearg('N', random.randint(1, MAXN)))
mode = cmdlinearg('mode', '')
M = int(cmdlinearg('M', random.randint(1, min(MAXM, N))))
rec = cmdlinearg('rec', 'sorted')

print(N, M)

order = list(range(N))
random.shuffle(order)



sizes = [ 1 for _ in range(M+1)]
sizes[M] = 0

for i in range(N-M):
    if mode == 'alloccur' or sizes[M]+M>=N: 
        sizes[random.randint(0, M-1)]+=1
    else:
        sizes[random.randint(0, M)]+=1





tot = 0
for i in range(M):
    who = [0 for _ in range(sizes[i]+1)]
    who[0] = sizes[i]
    nwho = list(range(sizes[i]))
    for j in range(sizes[i]):
        #nwho[j] = j+tot
        nwho[j] = order[j+tot]
    if rec == 'sorted':
        nwho.sort()

    for j in range(sizes[i]):
        who[j+1] = nwho[j]

    tot+=sizes[i]

    print(" ".join(str(x) for x in who))
