gets
r = readlines.map(&:to_i)
min = r[0..-2].min
max = r[1..-1].max
pf = []

while (r.index(max) < r.index(min))
  pf<<r.slice!(r.index(min)+1..-1).map{|i| i - min}.max
  pf<<r.slice!(0..r.index(max)-1).map{|i| max - i}.max
  min = r[0..-2].min
  max = r[1..-1].max
end
pf<<(max-min)
p pf.max