function myout(text){console.log(text);}//standard output
function Main(input) {
	//input = parseInt(input);
	//input = input.split(" ");
	//input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	input = input.split("\n").map((a)=>Number(a));
  var N = input[0];
  input.shift();
  input.sort(function(a,b){
  	return a - b;
  });
  var list = [];
  list.push(input.shift());
  var count = 0;
  while(input.length != 0){
    try{
        if(count % 2 == 0){
    		list.push(input.pop());
          if(input.length == 0){break;}
    		list.unshift(input.pop());
    	}else{
          	list.push(input.shift());
          if(input.length == 0){break;}
    		list.unshift(input.shift());
        }
      count++;
    }catch(e){
    }
  }
  var output = 0;
  for(var i = 0; i < list.length - 1; i++){
    var mae = list[i];
    var ato = list[i+1];
    output += Math.abs(mae - ato);
  }
  myout(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
