Var n, i, min, max, min_i, max_i, tmp: integer; a:array[1..100] of integer;
begin
readln(n);
for i := 1 to n do
read(a[i]);
min := a[1];
max := a[1];
min_i := 1; {номер минимального}
max_i := 1;
for i := 2 to n do
begin
if min > a[i] then
begin
min := a[i];
min_i := i;
end;
if max < a[i] then
begin
max := a[i];
max_i := i;
end;
end;
tmp := a[max_i];
a[max_i] := a[min_i];
a[min_i] := tmp;
for i := 1 to n do
write(a[i], ' ');
end.