program lab_3;
uses crt;
const n=10;
Var M, A: array[1..n+1] of integer;
i, p, p1, p2, bgn, max: integer;
key: boolean;
BEGIN
clrscr;
Writeln('vvedite massiv:');
for i:=1 to n do
Readln(M[i]);
key:=true;
bgn:=0;
while true do
begin
key:=true;
max:=1;
p:=0;
p1:=0;
p2:=0;
for i:=1 to n+1 do
if M[i]=0 then
begin
if i-p>max then
begin
p1:=p;
p2:=i;
max:=i-p;
end;
p:=i;
end
else key:=false;
if key then BREAK;
for i:=1 to max-1 do
begin
A[bgn+i]:=M[p1+i];
M[p1+i]:=0;
Write(A[bgn+i],' ');
end;
bgn:=bgn+max;
end;
Writeln;
for i:=1 to n do Write(A[i],' ');
Readln;
END.