【样例说明】
将第2段路的高度调整为3,第3段路的高度调整为2,调整体力消耗为2。
路线序列变为3 3 2,穿越这条路线消耗体力为1。
所以总体力消耗为3。
【数据规模】
对于10%的数据,有N≤10;
对于30%的数据,有A[I]≤1000;
对于40%的数据,有N≤1000;
对于100%的数据,有N≤100000,A[I]≤10000000。
uses math;
var
a,b,c:longint;
v,r:array[1..100001]of longint;
ans:qword;
begin
readln(a);
for b:=1 to a do
begin
read(v[b]);
end;
for b:=2 to a-1 do
begin
if (v[b]>v[b-1])and(v[b]>v[b+1]) then
begin
c:=max(v[b-1],v[b+1]);
end
else
if (v[b]<v[b-1])and(v[b]<v[b+1]) then
begin
c:=min(v[b-1],v[b+1]);
end
else
c:=v[b];
r[b]:=abs(v[b]-c);
v[b]:=c;
end;
for b:=2 to a do
begin
ans:=ans+r[b]+abs(v[b]-v[b-1]);
end;
writeln(ans);
end.