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 if d == 0 puts count_max_day(c) exit end max_day = 0 weeks = 'o' * d + c #puts weeks max_day = [count_max_day(weeks), max_day].max #p max_day weeks = c + 'o' * d #puts weeks #p max_day max_day = [count_max_day(weeks), max_day].max #p c.length index = 0 while index < c.length && c[index] == 'x' #p index index += 1 end if index <= d weeks = 'o' * (d - index) + c max_day = [count_max_day(weeks), max_day].max end (index...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 if weeks.length == 15 # weeks += 'o' end # puts weeks max_day = [count_max_day(weeks), max_day].max end puts max_day