{
TASK:ots
LANG:PASCAL
}
program otse4ka;
var i,n:longint;
    A:array[1..10000] of longint;
    max:longint;

  procedure sort(l,r:longint);
  var i,j,x,y:longint;

  begin
   i:=l;
   j:=r;
   x:=A[(l+r)div 2];
   repeat
    while a[i] < x do i := i + 1;
    while x < a[j] do j := j - 1;
    if i <= j then
    begin
      y := a[i]; a[i] := a[j]; a[j] := y;
      i := i + 1; j := j - 1;
    end;
  until i > j;
  if l < j then Sort(l, j);
  if i < r then Sort(i, r);


  end;


begin
 read (n);

 for i:=1 to n do
  read(A[i]);

sort(1,n);
max:=0;
inc(max,(A[2]-A[1]));
inc(max,(A[n]-A[n-1]));
for i:=3 to n-2 do
  if (A[i]-A[i-1])<(A[i+1]-A[i]) then
   inc(max,(A[i]-A[i-1]))
  else
   inc(max,(A[i+1]-A[i]));

writeln(max);
end.