class Calc0077 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @n = args.shift.first.to_i @as = args.shift.map(&:to_i) end def run (1..Math.sqrt(@as.inject(:+)).floor).map { |k| calc(k) }.min end def calc(k) ps = (1..k).to_a + (1..(k-1)).to_a.reverse ((-@as.size + 1)..0).map { |m| le = @as.map.with_index { |a, i| a - ((0...(k * 2 - 1)).include?(m + i) ? ps[m + i] : 0) } le.select(&:positive?).inject(:+) || 0 }.min end end puts Calc0077.new(STDIN.readlines).run if __FILE__ == $0