uses math;
Var i,j,t,first,n:longint;
used:array[0..1111]of boolean;
a:array[0..1111]of longint;
tmp,ans:int64;
procedure go(v,dest:longint;time:int64);
var d,vv:longint;
begin
vv:=v;
if v<dest then d:=1
else d:=-1;
while v<>dest do
begin
v:=v+d;
if used[v] then continue;
tmp:=tmp+abs(a[vv]-a[v])+time;
used[v]:=true;
end;
end;
begin
// assign(input,'cowrun.in');
// reset(input);
// assign(output,'cowrun.out');
// rewrite(output);
read(n);
for i:=1 to n do
read(a[i]);
inc(n);
a[n]:=0;
for i:=1 to n do
for j:=i+1 to n do
if a[i]>a[j] then
begin
a[0]:=a[i];
a[i]:=a[j];
a[j]:=a[0];
end;
for i:=1 to n do
if a[i]=0 then begin first:=i;break;end;
ans:=maxlongint*maxlongint;
for i:=1 to n do
begin
fillchar(used,sizeof(used),false);
tmp:=0;
used[first]:=true;
go(first,i,0);
go(i,n,abs(a[i]));
go(n,1,abs(a[i])+abs(a[i]-a[n]));
ans:=min(ans,tmp);
fillchar(used,sizeof(used),false);
tmp:=0;
used[first]:=true;
go(first,i,0);
go(i,1,abs(a[i]));
go(1,n,abs(a[i])+abs(a[i]-a[1]));
ans:=min(ans,tmp);
end;
Writeln(ans);
close(input);
close(output);
end.
dXNlcyBtYXRoOwpWYXIgaSxqLHQsZmlyc3Qsbjpsb25naW50OwogICAgdXNlZDphcnJheVswLi4xMTExXW9mIGJvb2xlYW47CiAgICBhOmFycmF5WzAuLjExMTFdb2YgbG9uZ2ludDsKICAgIHRtcCxhbnM6aW50NjQ7CiBwcm9jZWR1cmUgZ28odixkZXN0OmxvbmdpbnQ7dGltZTppbnQ2NCk7CiAgIHZhciBkLHZ2OmxvbmdpbnQ7CiAgICAgYmVnaW4KICAgICAgIHZ2Oj12OwogICAgICAgaWYgdjxkZXN0IHRoZW4gZDo9MQogICAgICAgZWxzZSBkOj0tMTsKICAgICAgIHdoaWxlIHY8PmRlc3QgZG8KICAgICAgICAgYmVnaW4KICAgICAgICAgICB2Oj12K2Q7CiAgICAgICAgICAgaWYgdXNlZFt2XSB0aGVuIGNvbnRpbnVlOwogICAgICAgICAgIHRtcDo9dG1wK2FicyhhW3Z2XS1hW3ZdKSt0aW1lOwogICAgICAgICAgIHVzZWRbdl06PXRydWU7CiAgICAgICAgIGVuZDsKICAgICBlbmQ7CiAgYmVnaW4KLy8gICAgYXNzaWduKGlucHV0LCdjb3dydW4uaW4nKTsKLy8gICAgcmVzZXQoaW5wdXQpOwovLyAgICBhc3NpZ24ob3V0cHV0LCdjb3dydW4ub3V0Jyk7Ci8vICAgIHJld3JpdGUob3V0cHV0KTsKICAgIHJlYWQobik7CiAgICBmb3IgaTo9MSB0byBuIGRvCiAgICAgIHJlYWQoYVtpXSk7CiAgICBpbmMobik7CiAgICBhW25dOj0wOwogICAgZm9yIGk6PTEgdG8gbiBkbwogICAgICBmb3Igajo9aSsxIHRvIG4gZG8KICAgICAgICBpZiBhW2ldPmFbal0gdGhlbgogICAgICAgICBiZWdpbgogICAgICAgICAgIGFbMF06PWFbaV07CiAgICAgICAgICAgYVtpXTo9YVtqXTsKICAgICAgICAgICBhW2pdOj1hWzBdOwogICAgICAgICBlbmQ7CiAgICBmb3IgaTo9MSB0byBuIGRvCiAgICAgIGlmIGFbaV09MCB0aGVuIGJlZ2luIGZpcnN0Oj1pO2JyZWFrO2VuZDsKICAgIGFuczo9bWF4bG9uZ2ludCptYXhsb25naW50OwogICAgZm9yIGk6PTEgdG8gbiBkbwogICAgICBiZWdpbgogICAgICAgIGZpbGxjaGFyKHVzZWQsc2l6ZW9mKHVzZWQpLGZhbHNlKTsKICAgICAgICB0bXA6PTA7CiAgICAgICAgdXNlZFtmaXJzdF06PXRydWU7CiAgICAgICAgZ28oZmlyc3QsaSwwKTsKICAgICAgICBnbyhpLG4sYWJzKGFbaV0pKTsKICAgICAgICBnbyhuLDEsYWJzKGFbaV0pK2FicyhhW2ldLWFbbl0pKTsKICAgICAgICBhbnM6PW1pbihhbnMsdG1wKTsKICAgICAgICBmaWxsY2hhcih1c2VkLHNpemVvZih1c2VkKSxmYWxzZSk7CiAgICAgICAgdG1wOj0wOwogICAgICAgIHVzZWRbZmlyc3RdOj10cnVlOwogICAgICAgIGdvKGZpcnN0LGksMCk7CiAgICAgICAgZ28oaSwxLGFicyhhW2ldKSk7CiAgICAgICAgZ28oMSxuLGFicyhhW2ldKSthYnMoYVtpXS1hWzFdKSk7CiAgICAgICAgYW5zOj1taW4oYW5zLHRtcCk7CiAgICAgIGVuZDsKICAgIFdyaXRlbG4oYW5zKTsKICAgIGNsb3NlKGlucHV0KTsKICAgIGNsb3NlKG91dHB1dCk7CiAgZW5kLg==