$N=<>; @Y=sort{$a-$b}glob<>; @d=(1e15,$Y[1]-$Y[0]); for(2..$N-1){ $d[$_]=$d[-2**($d[$_-2]<$d[$_-1])]+$Y[$_]-$Y[$_-1] } print$d[-1],$/