Whi TL. P1148
program Building_Tower;
const
InputFile = '1148.in';
Max = 1185;
type
Newtype = array [0..Max] of Comp;
var
Fm : array [-1..0, 1..35] of ^Newtype;
Q : array [1..60] of Integer;
nn, hh, mm : Integer;
i, j, Num : Integer;
k, Tt : Comp;
function Count(n, h, m: Integer): Comp;
var
Res : Comp;
i, j, k : Integer;
a, b, c : Shortint;
x, y, xx, yy : Integer;
begin
if Odd(m) then a:=-1
else a:=0;
b:=-1-a; c:=a;
for i:=-1 to 0 do
for j:=1 to 35 do Fillchar(Fm[i, j]^, Sizeof(Fm[i, j]^), 0);
Fm[a, (m+1) shr 1]^[(m+1) shr 1]:=1;
for i:=2 to h do begin
for j:=1 to 35 do
for k:=1 to (n+1) shr 1 do
if Fm[a, j]^[k]>0 then begin
x:=j shl 1+a+1;
y:=k shl 1+c+x;
if y<=n then begin
xx:=(x+1) shr 1; yy:=(y+1) shr 1;
Fm[b, xx]^[yy]:=Fm[b, xx]^[yy]+Fm[a, j]^[k];
end;
Dec(x, 2); Dec(y, 2);
if (x>0) and (y<=n) then begin
xx:=(x+1) shr 1; yy:=(y+1) shr 1;
Fm[b, xx]^[yy]:=Fm[b, xx]^[yy]+Fm[a, j]^[k];
end;
Fm[a, j]^[k]:=0;
end;
if a=0 then c:=-1-c;
a:=b; b:=-1-b;
end;
Res:=0;
for i:=1 to 35 do
for j:=1 to (n+1) shr 1 do
if Fm[a, i]^[j]>0 then Res:=Res+Fm[a, i]^[j];
Count:=Res;
end;
{Main}
begin
Assign(Input, InputFile);
Reset(Input);
Readln(nn, hh, mm);
for i:=-1 to 0 do
for j:=1 to 35 do New(Fm[i, j]);
if nn>2370 then nn:=2370;
Writeln(Count(nn, hh, mm):1:0);
repeat
Readln(k);
if k=-1 then Break;
Fillchar(Q, Sizeof(Q), 0);
Q[1]:=mm; Num:=mm;
Tt:=0;
for i:=2 to hh do begin
if Q[i-1]=1 then Q[i]:=2
else begin
Tt:=Count(nn-Num, hh+1-i, Q[i-1]-1);
if Tt<k then begin
k:=k-Tt; Q[i]:=Q[i-1]+1;
end
else Q[i]:=Q[i-1]-1;
end;
Inc(Num, Q[i]);
end;
for i:=1 to hh do Write(Q[i], ' ');
Writeln;
until False;
Close(Input);
end.