#!/usr/bin/env python3
# have the permutation be such that one of the halves does not fit 
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)



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

starts = []
order = list(range(N))
order = order[:N//2] + [order[-blocked-2]] + order[N//2:-blocked-2] + order[-blocked-1:]

if mode == "upper":
    order = list(range(N))
    order = [order[N//2]]+order[:N//2]+order[N//2+1:]
elif mode == "lower":
    order = list(range(N))
    order = order[:N//2]+order[N//2+1:]+[order[N//2]]

for i in range(M):
    if i < M - blocked:
        e = order[i]
    else:
        e = order[i-M]
    a[i + 1].append(e)
    starts.append(e)
a.sort()


if mode == "alloccur":
    a[0][0] = order.pop()

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 shuffle:
    tail = a[1:]
    random.shuffle(tail)
    a[1:] = tail

start = 1


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))
