N = gets.to_i turn = 0 loop { if turn == 0 case N when 1 STDOUT.puts "1 1" when 2 STDOUT.puts "2 1" else if N.even? STDOUT.puts "2 #{N / 2}" else STDOUT.puts "1 #{N / 2 + 1}" end end else k, x = gets.split.map(&:to_i) i = N - x + 1 - (k - 1) STDOUT.puts "%d %d" % [k, i] end STDOUT.flush t = gets.to_i break if t == 0 || t == 1 turn += 1 }