var tomb:array[0..gmaxc,0..nmaxc] of word;
hany:array[1..nmaxc] of word;
A:array[1..20000] of word;
t:text;
N,G,GO,MAXE,i,al,j,co,u,hanyz:longint;
PROCEDURE { shell } Sort(
VAR
N: longint);
VAR
Done: Boolean;
Jump, I, J: longint;
BEGIN
Jump := N;
WHILE Jump > 1 DO
BEGIN
Jump := Jump DIV 2;
REPEAT
Done := True;
FOR J := 1 TO N - Jump DO
BEGIN
I := J + Jump;
IF A[J] > A[I] THEN
BEGIN
{Swap(A[J], A[I]);}
u:=a[j];
a[j]:=a[i];
a[i]:=u;
Done := False;
END { if }
END { FOR }
UNTIL Done
END { WHILE }
END; { Sort }
begin
assign(t,'ghiozdan.in');
reset(T);
read(t,N);
read(t,G);
co:=1;
go:=tomb[0,1];
for i:=1 to n do begin
read(t,a[i]);
go:=go+a[i];
end;
closE(T);
hanyz:=0;
sort(n);
tomb[0,1]:=a[1];
co:=1;
hany[co]:=1;
for i:=2 to n do begin
if tomb[0,co]=a[i] then inc(hany[co])
else
begin
inc(co);
hany[co]:=1;
tomb[0,co]:=a[i];
end;
end;
n:=co;
{ writeln(hany[1]);}
for i:=1 to gmaxc do for j:=1 to nmaxc do tomb[i,j]:=0;
i:=0;
if go>g then go:=g;
for al:=1 to go do begin
inc(i);
j:=0;
while (j<n) and ((tomb[i,0]>2) or (tomb[i,0]=0)) do
begin
inc(j);
co:=i-tomb[0,j];
if co>0 then begin if (tomb[co,j]<hany[j]) and (tomb[co,0]>0) then
if ((tomb[co,0]+1)<tomb[i,0]) or (tomb[i,0]=0) then
begin
for u:=0 to n do tomb[i,u]:=tomb[co,u];
tomb[i,j]:=tomb[i,j]+1;
inc(tomb[i,0]);
{ writeln(al,' ',i);}
end;
end
else
if co=0 then begin
for u:=0 to n do tomb[i,u]:=0;
tomb[i,j]:=1;
inc(tomb[i,0]);
{ writeln(i+hanyz*10000,' ');}
end;
end;
if al>5000 then
if al mod 5000=0 then begin
{ writeln(al);}
for j:=5001 to 10000 do
for co:=0 to n do
tomb[j-5000,co]:=tomb[j,co];
for j:=5000+1 to 10000 do
for co:=0 to n do tomb[j,co]:=0;
i:=i-5000;
hanyz:=hanyz+1;
end;
end;
u:=20000;
while tomb[u,0]=0 do
begin
u:=u-1;
end;
assign(t,'ghiozdan.out');
rewrite(T);
write(t,u+hanyz*5000,' ');
writeln(t,tomb[u,0]);
for i:=1 to n do
if tomb[u,i]>0 then
for j:=1 to tomb[u,i] do
writeln(t,tomb[0,i]);
close(t);
end.
const gmaxc=20000;
nmaxc=200;
var tomb:array[0..gmaxc,0..nmaxc] of word;
hany:array[1..nmaxc] of word;
A:array[1..20000] of word;
t:text;
N,G,GO,MAXE,i,al,j,co,u,hanyz:longint;
PROCEDURE { shell } Sort(
VAR
N: longint);
{ Shell-Metzner Sort }
{ Adapted from Programming in Pascal,
P. Grogono, Addison-Wesley, 1980 }
{ From Borland Pascal Programs for Scientists and Engineers }
{ by Alan R. Miller, Copyright C 1993, SYBEX Inc }
VAR
Done: Boolean;
Jump, I, J: longint;
BEGIN
Jump := N;
WHILE Jump > 1 DO
BEGIN
Jump := Jump DIV 2;
REPEAT
Done := True;
FOR J := 1 TO N - Jump DO
BEGIN
I := J + Jump;
IF A[J] > A[I] THEN
BEGIN
{Swap(A[J], A[I]);}
u:=a[j];
a[j]:=a[i];
a[i]:=u;
Done := False;
END { if }
END { FOR }
UNTIL Done
END { WHILE }
END; { Sort }
begin
assign(t,'ghiozdan.in');
reset(T);
read(t,N);
read(t,G);
co:=1;
go:=tomb[0,1];
for i:=1 to n do begin
read(t,a[i]);
go:=go+a[i];
end;
closE(T);
hanyz:=0;
sort(n);
tomb[0,1]:=a[1];
co:=1;
hany[co]:=1;
for i:=2 to n do begin
if tomb[0,co]=a[i] then inc(hany[co])
else
begin
inc(co);
hany[co]:=1;
tomb[0,co]:=a[i];
end;
end;
n:=co;
{ writeln(hany[1]);}
for i:=1 to gmaxc do for j:=1 to nmaxc do tomb[i,j]:=0;
i:=0;
if go>g then go:=g;
for al:=1 to go do begin
inc(i);
j:=0;
while (j<n) and ((tomb[i,0]>2) or (tomb[i,0]=0)) do
begin
inc(j);
co:=i-tomb[0,j];
if co>0 then begin if (tomb[co,j]<hany[j]) and (tomb[co,0]>0) then
if ((tomb[co,0]+1)<tomb[i,0]) or (tomb[i,0]=0) then
begin
for u:=0 to n do tomb[i,u]:=tomb[co,u];
tomb[i,j]:=tomb[i,j]+1;
inc(tomb[i,0]);
{ writeln(al,' ',i);}
end;
end
else
if co=0 then begin
for u:=0 to n do tomb[i,u]:=0;
tomb[i,j]:=1;
inc(tomb[i,0]);
{ writeln(i+hanyz*10000,' ');}
end;
end;
if al>5000 then
if al mod 5000=0 then begin
{ writeln(al);}
for j:=5001 to 10000 do
for co:=0 to n do
tomb[j-5000,co]:=tomb[j,co];
for j:=5000+1 to 10000 do
for co:=0 to n do tomb[j,co]:=0;
i:=i-5000;
hanyz:=hanyz+1;
end;
end;
u:=20000;
while tomb[u,0]=0 do
begin
u:=u-1;
end;
assign(t,'ghiozdan.out');
rewrite(T);
write(t,u+hanyz*5000,' ');
writeln(t,tomb[u,0]);
for i:=1 to n do
if tomb[u,i]>0 then
for j:=1 to tomb[u,i] do
writeln(t,tomb[0,i]);
close(t);
end.