program remove;
var
f:array[0..10000]of int64;
n,i,j:longint;
a:array[0..10000]of longint;
begin
assign(input,'remove.in');
reset (input);
assign (output,'remove.out');
rewrite (output);
readln (n);
for i:=1 to n do
read (a[i]);
for i:=1 to n do
for j:=1 to i do
begin
if i=j then
begin
if f[j-1]+a[i]>f[i] then
f[i]:=f[j-1]+a[i]
end
else
begin
if f[j-1]+abs(a[i]-a[j])*(i-j+1)>f[i] then
f[i]:=f[j-1]+abs(a[i]-a[j])*(i-j+1)
end
end;
writeln (f[n]);
close (input);
close (output)
end.