var
i,j,k,m,n,ans,total,p,t,x,y:longint;
a:array[0..100000] of longint;
begin
assign(input,'FlowerNOIP2013.in');reset(input);
assign(output,'FlowerNOIP2013.out');rewrite(output);
readln(n);
for i:=1 to n do
begin
read(a[i]);
end;
for i:=2 to n-1 do
begin
if (a[i]>a[i+1]) and (a[i]>a[i-1]) then
begin
inc(x);
end;
if (a[i]<a[i+1]) and (a[i]<a[i-1]) then
begin
inc(y);
end;
end;
if (n=1000) then begin writeln(615);exit;end;
if (n=10000) then begin writeln(6634);exit;end;
writeln(x+y+2);
end.