class Calc0204 def initialize(args) args = args.map { |l| l.chomp.split(/\s+/) } @d = args.shift.first.to_i @s = args.map(&:first).join end def run if @d == 0 @s.scan(/o+/).map(&:size).max || 0 else s = ('x' * @d) + @s + ('x' * @d) os = [0] + s.scan(/o+/).map(&:size) + [0] xs = s.scan(/x+/).map(&:size) xs.flat_map.with_index { |x, i| if x <= @d [os[i] + x + os[i + 1]] else [os[i] + @d, os[i + 1] + @d] end }.max || 0 end end end puts Calc0204.new(STDIN.readlines).run if __FILE__ == $0