program ideone;
Const smax = 99;
Type simple = array[0..smax] of smallint;
Var data, sort, res:simple; i, n:smallint;
procedure writeArr(arr:simple; n:smallint);
Var i:smallint;
begin
for i:=0 to n do write(arr[i], ' ');
writeln();
end;
procedure delInArr(Var arr:simple; pos:smallint);
Var i:smallint; tArr:simple;
begin
for i:=0 to pos-1 do tArr[i]:=arr[i];
for i:=pos to smax do tArr[i]:=arr[i+1];
arr:=tArr;
end;
procedure insInArr(Var arr:simple; pos, e:smallint);
Var i:smallint; tArr:simple;
begin
for i:=0 to pos-1 do tArr[i]:=arr[i];
tArr[pos]:=e;
for i:=pos+1 to smax do tArr[i]:=arr[i+1];
arr:=tArr;
end;
function bubbleSort(arr:simple; n:smallint):simple;
Var i, j, t:smallint;
begin
for i:=0 to n-1 do
for j:=0 to n-1 do
if arr[j]<arr[j+1] then begin
t:=arr[j];
arr[j]:=arr[j+1];
arr[j+1]:=t;
end;
bubbleSort:=arr;
end;
function isSame(arr:simple; num, lim:smallint):boolean;
Var i:smallint; same:boolean;
begin
same:=False;
i:=0;
while (same<>True) and (i<=lim) do begin
writeln('DEBAG: num = ', num, ', lim = ', lim);
if arr[i]=num then same:=True;
i:=i+1;
end;
isSame:=same;
end;
function findIndexMax(main, forbidden:simple; lim:smallint):smallint;
Var i, index:smallint;
begin
index:=0;
for i:=0 to n do
if (main[index]<main[i]) and (isSame(forbidden, i, lim)=False) then
index:=i;
writeln('DEBAG: index = ', index);
findIndexMax:=index;
end;
function converter(mainA:simple):simple;
Var i:smallint; res:simple;
begin
for i:=0 to n do begin
res[i]:=findIndexMax(mainA, res, i-1);
end;
converter:=res;
end;
begin
read(n);
n:=n-1;
for i:=0 to n do read(data[i]);
res:=converter(data);
writeArr(res, n);
end.
cHJvZ3JhbSBpZGVvbmU7CgpDb25zdCBzbWF4ID0gOTk7ClR5cGUgc2ltcGxlID0gYXJyYXlbMC4uc21heF0gb2Ygc21hbGxpbnQ7ClZhciBkYXRhLCBzb3J0LCByZXM6c2ltcGxlO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= 3, lim = 0
DEBAG: num = 4, lim = 0
DEBAG: index = 4
DEBAG: num = 1, lim = 1
DEBAG: num = 1, lim = 1
DEBAG: num = 3, lim = 1
DEBAG: num = 4, lim = 1
DEBAG: num = 4, lim = 1
DEBAG: index = 1
DEBAG: num = 1, lim = 2
DEBAG: num = 1, lim = 2
DEBAG: num = 1, lim = 2
DEBAG: num = 2, lim = 2
DEBAG: num = 2, lim = 2
DEBAG: num = 2, lim = 2
DEBAG: num = 3, lim = 2
DEBAG: num = 4, lim = 2
DEBAG: num = 4, lim = 2
DEBAG: index = 2
DEBAG: num = 1, lim = 3
DEBAG: num = 1, lim = 3
DEBAG: num = 1, lim = 3
DEBAG: num = 2, lim = 3
DEBAG: num = 2, lim = 3
DEBAG: num = 2, lim = 3
DEBAG: num = 2, lim = 3
DEBAG: num = 3, lim = 3
DEBAG: num = 4, lim = 3
DEBAG: num = 4, lim = 3
DEBAG: index = 0
DEBAG: num = 1, lim = 4
DEBAG: num = 1, lim = 4
DEBAG: num = 1, lim = 4
DEBAG: num = 2, lim = 4
DEBAG: num = 2, lim = 4
DEBAG: num = 2, lim = 4
DEBAG: num = 2, lim = 4
DEBAG: num = 3, lim = 4
DEBAG: num = 4, lim = 4
DEBAG: num = 4, lim = 4
DEBAG: index = 0
3 4 1 2 0 0