Program n1;
const n = 6;
var a : array[1..n] of integer;
i, max, min, temp : integer;
begin
for i := 1 to n do readln(a[i]);
min := 1;
max := 1;
for i := 1 to n do
begin
if a[i] > a[max] then max := i;
if a[i] < a[min] then min := i;
end;
temp := a[max];
a[max] := a[min];
a[min] := temp;
for i := 1 to n do write(a[i],' ');
end.