N = gets.to_i tmp = "#{gets.chomp}#{gets.chomp}".chars.map { |c| c == 'o' ? true : false } ADD = Array.new(7) { false } LIST = ADD + tmp + ADD # puts LIST.to_s def count_from(list, index) c = 0 i = index while i < list.size && list[i] c += 1 i += 1 end c end def count(list) a = Array.new(list.size) do |i| count_from(list, i) end # puts "#{list} -> #{a.max}" a.max end xidxs = LIST.each_index.select { |i| !LIST[i] } # puts xidxs.to_s ans = count(LIST) xidxs.each do |start| remain = N list = LIST.map.with_index { |r, i| if i >= start && remain > 0 && !r remain -= 1 true else remain = 0 if i >= start r end } ans = [count(list), ans].max end puts ans