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


def next_index(a, x, m):
    mini = -1
    maxi = m
    while mini + 1 != maxi:
        mid = (mini + maxi) // 2
        if a[mid][-1] > x:
            maxi = mid
        else:
            mini = mid
    return mini


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", MAXN))
mode = cmdlinearg("mode", "")
M = int(cmdlinearg("M", random.randint(1, min(MAXM, N))))
blocked = int(cmdlinearg("blocked", M // 2))
shuffle = int(cmdlinearg("shuffle",1))
print(N, M)

if mode == "alloccur":
    M -= 1


a = [[] for _ in range(M + 1)]
a[0].append(-1)

starts = []
order = list(range(N))
t = min(max(blocked,N//2),5*blocked)
b = random.sample(order[-t:-1],blocked)


for i in range(M):
    if i == 0:
        e = 0
    if i < M - blocked:
        e = random.sample(order[i*(N-t)//(M+1-blocked)+1:(i+1)*(N-t)//(M+1-blocked)],1)[0]
    else:
        e = b[i-M - 1+blocked]
    a[i + 1].append(e)
    starts.append(e)
a.sort()


order = list(range(N))
random.shuffle(order)
if mode == "alloccur":
    while True:
        a[0][0] = order.pop()
        if a[0][0] not in starts:
            break

for i in range(0, len(order)):
    if order[i] in starts:
        continue
    ind = next_index(a, order[i], M + 1)
    if ind == -1:
        ind = 0
    a[ind].append(order[i])

if mode == "alloccur":
    a[0].sort()
    if shuffle:
        random.shuffle(a)
elif shuffle:
    tail = a[1:]
    random.shuffle(tail)
    a[1:] = tail

start = 1

if mode == "alloccur":
    start = 0

for i in range(start, M + 1):
    who = [a[i][j] for j in range(-1, len(a[i]))]
    who[0] = len(a[i])
    print(" ".join(str(x) for x in who))
