N = gets.to_i A = gets.split.map &:to_i width = (A.sum**0.5).floor*2-1 add = sub = 0 A.map.with_index{|n, i| height = [0, [width - i, i+1].min].max diff = height - n if diff > 0 add += diff else sub -= diff end } p (add - sub).abs + [add, sub].min