N = gets.to_i field = [nil]*N def mid(len, i) return [len, i] if len <= 2 return [2-(len%2), i+(len-1)/2] end fill = lambda do |a| field[a[0]...(a[0]+a[1])] = [true]*a[1] end 111.times do ans = [] len = 0 field.each_with_index do |e,i| unless e.nil? next if len == 0 ans = mid(len, i) break end len += 1 end ans = mid(len, 0) if ans.empty? && len > 0 fill.call(ans) puts "#{ans[0]} #{ans[1]+1}" STDOUT.flush t = gets.to_i break if [0,1,2].include?(t) ans = gets.chomp.split.map(&:to_i) ans[1] -= 1 fill.call(ans) end