require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end
require 'pp'
N,_=gets.chomp.split(' ').map{|n| n.to_i}
A = Array.new(N)
0.upto(N-1){|d|
	A[d],_=gets.chomp.split(' ').map{|n| n.to_i}
}
Asort = A.sort
imax = N/2
dif = 0
dif += (Asort[N-1] - Asort[0]).abs
	# puts "#{Asort[0]} #{Asort[N-1]}"
	# puts dif
# pp Asort
# smaller start
for i in 1..(imax-1)
	dif += (Asort[N-1-i+1] - Asort[i]).abs
	dif += (Asort[N-1-i] - Asort[i]).abs
	# puts "#{Asort[N-1-i]} #{Asort[i]}"
	# puts "#{Asort[i]} #{Asort[N-1-i+1]}"
	# puts dif
end
if(N%2!=0)
	a = (Asort[N/2] - Asort[N/2+1]).abs
	b = (Asort[N/2] - Asort[0]).abs
	# puts "#{Asort[N/2]} #{Asort[N/2+1]}"
	# puts "vs"
	# puts "#{Asort[N/2]} #{Asort[0]}"
	if(a < b)
		dif += b
	else
		dif += a
	end
	# puts dif
else
	dif -= (Asort[N/2]-Asort[N/2-1]).abs
	dif += (Asort[N/2]-Asort[0]).abs
end
# puts dif
smallerdif = dif

imax = N/2
dif = 0
dif += (Asort[N-1] - Asort[0]).abs
	# puts "#{Asort[N-1]} #{Asort[0]}"
	# puts dif
# pp Asort
for i in 1..(imax-1)
	dif += (Asort[N-1-i] - Asort[i-1]).abs
	dif += (Asort[N-1-i] - Asort[i]).abs
	# puts "#{Asort[i-1]} #{Asort[N-1-i]}}"
	# puts "#{Asort[N-1-i]} #{Asort[i]}"
	# puts dif
end
if(N%2!=0)
	a = (Asort[N/2] - Asort[N-1]).abs
	b = (Asort[N/2] - Asort[N/2-1]).abs
	# puts "#{Asort[N/2]} #{Asort[N-1]}"
	# puts "vs"
	# puts "#{Asort[N/2]} #{Asort[N/2-1]}"
	if(a < b)
		dif += b
	else
		dif += a
	end
	# puts dif
else
	dif -= (Asort[N/2]-Asort[N/2-1]).abs
	dif += (Asort[N/2]-Asort[N-1]).abs
end

largerdif = dif

thedif = smallerdif > largerdif ? smallerdif : largerdif

puts thedif



