program project3;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
n,i,j,k,z:longint;
a,b:array[1..1000] of Byte;
procedure Merge(l,p,s:longint);
begin
//kopiowanie a[1..s] do b[1..s]
for i:=1 to p do
b[i] := a[i];
//właściwe scalanie
i := 1; j := s+1; k := 1;
while (i <= s) and (j <= p) do
//Niezmiennik: a[1..k] - scalone podciągi b[1..i-1], a[s+1..j-1]
begin
if b[i] < a[j] then
begin a[k] := b[i]; i := i+1;k:=k+1; end
else
begin a[k] := a[j]; j := j+1;k:=k+1; end
end;
if i>s then
begin
while (j<=p) do
Begin
a[k]:=a[j];
j:=j+1;
k:=k+1;
End;
end
else
begin
while(i<=s) do
begin
A[k]:=b[i];
i:=i+1;
k:=k+1;
end
end;
end;
procedure MS(l,p:longint);
var
s:Longint;
begin
if l < p then
begin
s := (l+p) div 2;
MS(l,s);
MS(s+1,p);
Merge(l,p,s);
end
else
if l=p then Merge(l,p,s);
end;
begin
readln(n);
randomize;
for i:=1 to n do
begin
a[i]:=random(10);
Write(a[i],' ');
end;
MS(1,n);
Writeln('Po sort.');
Writeln;
for i:=1 to n do
begin
wRite(a[i],' ');
end;
readln;
{ TODO -oUser -cConsole Main : Insert code here }
end.