Program CT_mangcon;
uses crt;
Var
i,n,d,c,s,j:integer;
A:array [1..100] of integer;
f,g : text;
max:longint;
kt:boolean;
Begin
clrscr;
Assign(f, 'mangcon.inp');
Reset(f);
Assign(g, 'mangcon.out');
Rewrite(g);
Readln(f,n);
For i:=1 to n do
begin
write('a[',i,']= ');
Read(f,a[i]);
end;
max:=low(longint);
For i:=1 to n do
Begin
s:=a[i];
For j:=i to n do
Begin
if i<>j then s:=s+a[j];
if s>max then
Begin
max:=s;
d:=i;
c:=j;
End;
End;
End;
For i:=d to c do
begin
s:=a[i];
for j:=i to c do
Begin
if i<>j then s:=s+a[j];
if s>max then max:=s;
end;
end;
kt:=true;
For i:=d to c-1 do
for j:=i+1 to c do
if a[i]>a[j] then
kt:=false;
If kt then
begin
For i:=d to c do
write(g,a[i],' ');
write(g,'tong con lon nhat va tang dan la: ',max);
end
else
write(g,'Khong ton tai mang con lon nhat va tang dan');
Close(g);
close(f);
End.