a,x:array[1..300] of integer;
function f(k:integer):integer;
var x:array[1..300] of integer;
function upnum(l,r:integer):integer;
var i,j:integer;
begin
upnum:=0;
if l>r then exit;
for i:=l to r do if a[l]<a[k] then x[i]:=1 else x[i]:=0;
for i:=l+1 to r do
for j:=l to i-1 do if (x[j]+1>x[i])and(a[j]<a[i]) and (a[j]<a[k])then x[i]:=x[j]+1;
for i:=l to r do if x[i]>upnum then upnum:=x[i];
upnum:=r-l+1-upnum;
end;
function downnum(l,r:integer):integer;
var i,j:integer;
begin
downnum:=0;
if l>r then exit;
for i:=l to r do if a[l]<a[k] then x[i]:=1 else x[i]:=0;
for i:=l+1 to r do
begin
for j:=l to i-1 do if (x[j]+1>x[i])and(a[j]>a[i]) and (a[j]<a[k])then x[i]:=x[j]+1;
end;
for i:=l to r do if x[i]>downnum then downnum:=x[i];
downnum:=r-l+1-downnum;
end;
begin
exit(upnum(lm,k-1)+downnum(k+1,rm))
end;
begin
min:=maxint;
read(n);
for i:=1 to n do read(a[i]);
lm:=1;rm:=n;
while a[lm+1]>a[lm] do inc(lm);
while a[rm-1]>a[rm] do dec(rm);
for i:=lm to rm do
if a[i+1]>a[i] then continue
else begin
s:=f(i);
if s<min then min:=s;
end;
writeln(min);
end.
wa70,都是出去人少了一点。。。。