lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end def solve1(a) s = [0i64, 0i64] i = 0 until a.empty? s[i % 2] += a.pop i += 1 end s[0].abs - s[1].abs end def solve2(a) s = [0i64, 0i64] i = 0 until a.empty? if i.even? s[0] += a.pop else s[1] += a.shift end i += 1 end s[0].abs - s[1].abs end n = read_line.to_i a = read_line.split.map(&.to_i).sort puts [solve1(Deque.new(a)), solve1(Deque.new(a.reverse)), solve2(Deque.new(a)), solve2(Deque.new(a.reverse))].max