d = gets.chomp.to_i c1 = gets.chomp c2 = gets.chomp c = c1 + c2 #puts c max_day = 0 def count_max_day(weeks) count_max_day = 0 count_day = 0 weeks.each_char do |day| if day == 'x' count_day = 0 else count_day += 1 count_max_day = [count_day, count_max_day].max end end count_max_day end max_day = 0 weeks = 'o' + c #puts weeks max_day = [count_max_day(weeks), max_day].max #p max_day weeks = 'o' + c + 'o' #puts weeks #p max_day max_day = [count_max_day(weeks), max_day].max (0...c.length).each do |i| next if c[i] == 'o' seq_days = 1 count_day = 0 (1..d).each do |j| break if i + j >= c.length || c[i + j] == 'o' seq_days += 1 end weeks = c[0, i] + ("o" * seq_days) + c[i + seq_days..-1] if i + seq_days == c.length weeks += 'o' * (d - seq_days) end # puts weeks max_day = [count_max_day(weeks), max_day].max end puts max_day