<Problem>
http://ntucoder.net/Problem/Details/1142
Uses Crt;
Var n,chot,i,t,tg,j,vt:longint;
a:array[1..100000] of longint;
Begin
readln(n);
for i:=1 to n do read(a[i]);
chot:=a[n];
i:=1; t:=1;
repeat
while (a[i]>chot) do inc(i);
if (i<=n) then
begin
tg:=a[i];
a[i]:=a[t];
a[t]:=tg;
if (i=n) then vt:=t;
inc(t);
inc(i);
//for j:=1 to n do write(a[j]); writeln;
end;
until i>n;
for i:=1 to n do
if i<>vt then
write(a[i],' ')
else write('[',a[i],'] ');
readln;
End.