# frozen_string_literal: true class Array def center Rational(max + min, 2).then do |i| [i.floor - 1, i.floor, i.ceil, i.ceil + 1] end end end def solve Y.center.map { |i| Y.map { |y| (y - i).abs }.sum }.min end N = gets.to_i Y = gets.split.map(&:to_i) puts solve