var
a,b,c,d,e,j,n,m,k,g:longint;
x:array[0..10]of longint;
y:array[1..18000,1..10]of longint;
begin
assign(input,'dataa.in');
assign(output,'dataa.out');
reset(input);
rewrite(output);
readln(n,m);
for a:=1 to m-1 do
begin
x[a]:=1;y[1,a]:=1;
end;
x[m]:=n-m+1;y[1,m]:=x[m];k:=1;j:=1;
repeat
c:=m;
while x[c]=x[c-1] do c:=c-1;
if c=1 then break;
x[c]:=x[c]-1;g:=c-1;
while x[g]=x[g+1] do g:=g-1;
x[g]:=x[g]+1;
if x[0]=0 then
begin
if m-g>=2 then
begin
for d:=g+1 to m-1 do
x[d]:=x[g];
e:=0;
for d:=1 to m-1 do
e:=e+x[d];
x[m]:=n-e;
end;
k:=k+1;j:=j+1;
for b:=1 to m do
y[j,b]:=x[b];
end;
until x[0]<>0;
writeln(k);
for a:=1 to 18000 do
begin
if y[a,1]=0 then break;
for b:=1 to m do
write(y[a,b],' ');
writeln;
end;
close(input);
close(output);
end.