program ideone;
Const smax = 99;
Type simple = array[0..smax] of smallint;
Var data, sort:simple; i, n:smallint;
procedure writeArr(arr:simple);
Var i:smallint;
begin
for i:=0 to n-1 do write(arr[i], ' ');
writeln();
end;
function cocktailShakerSort(data:simple):simple;
Var i, j, t:smallint; isSwap:boolean;
begin
i:=0;
isSwap:=True;
while isSwap=True do begin
isSwap:=False;
for j:=0 to n-2 do
if data[j]>data[j+1] then begin
t:=data[j];
data[j]:=data[j+1];
data[j+1]:=t;
isSwap:=True;
end;
for j:=n-2 downto 0 do
if data[j]>data[j+1] then begin
t:=data[j];
data[j]:=data[j+1];
data[j+1]:=t;
isSwap:=True;
end;
i:=i+1;
writeArr(data);
end;
cocktailShakerSort:=data;
end;
begin
read(n);
for i:=0 to n-1 do read(data[i]);
cocktailShakerSort(data)
end.
cHJvZ3JhbSBpZGVvbmU7CgpDb25zdCBzbWF4ID0gOTk7ClR5cGUgc2ltcGxlID0gYXJyYXlbMC4uc21heF0gb2Ygc21hbGxpbnQ7ClZhciBkYXRhLCBzb3J0OnNpbXBsZTsgaSwgbjpzbWFsbGludDsKCnByb2NlZHVyZSB3cml0ZUFycihhcnI6c2ltcGxlKTsKVmFyIGk6c21hbGxpbnQ7CmJlZ2luCglmb3IgaTo9MCB0byBuLTEgZG8gd3JpdGUoYXJyW2ldLCAnICcpOwoJd3JpdGVsbigpOwplbmQ7CgpmdW5jdGlvbiBjb2NrdGFpbFNoYWtlclNvcnQoZGF0YTpzaW1wbGUpOnNpbXBsZTsKVmFyIGksIGosIHQ6c21hbGxpbnQ7IGlzU3dhcDpib29sZWFuOwpiZWdpbgoJaTo9MDsKCWlzU3dhcDo9VHJ1ZTsKCXdoaWxlIGlzU3dhcD1UcnVlIGRvIGJlZ2luCgkJaXNTd2FwOj1GYWxzZTsKCQlmb3Igajo9MCB0byBuLTIgZG8KCQkJaWYgZGF0YVtqXT5kYXRhW2orMV0gdGhlbiBiZWdpbgoJCQkJdDo9ZGF0YVtqXTsKCQkJCWRhd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