def lscan; gets.split.map(&:to_i); end gets li = lscan.sort n = li.size n2 = n/2 n1 = n - n2 if n == 1 p li[0] exit end odd, even = li.each_slice(2).reduce([0, 0]){|s,e| s[0] += e[0]; e[1] and s[1] += e[1]; s } score1 = li[0...n1].reduce(:+).abs - li[n1..-1].reduce(:+).abs score2 = -li[0...n2].reduce(:+).abs + li[n2..-1].reduce(:+).abs score3 = odd.abs - even.abs best = [score1, score2, score3].max best = [even.abs - odd.abs, best].max if n.even? p best