var a, b, c, i, n, max, min:integer;
s :array [1..10000] of integer;
begin
read (n);
for i:=1 to n do
read (s[i]);
max:=s[1];
min:=s[1];
a:=1;
b:=1;
for i:=1 to n do
begin
if s[i]>=max then
begin
max:=s[i];
a:=i;
end;
if s[i]
begin
min:=s[i];
b:=i;
end;
end;
s[a]:=min;
s[b]:=max;
writeln;
for i:=1 to n do
write (s[i],' ');
end.