def try(arr) $stdout.puts arr.join(' ') $stdout.flush x, y = gets.split.map(&:to_i) [x, y] end fst = 0 [2, 4, 6, 8].each do |i| fst += try([0, 1, i, i + 1]).reduce(:+) end if fst == 4 nums = [] elsif fst == 7 nums = [] fb1 = try([0, 2, 3, 4]).reduce(:+) fb2 = try([1, 2, 3, 4]).reduce(:+) if fb2 > fb1 nums.push(1) elsif fb2 < fb1 nums.push(0) end elsif fst == 10 nums = [0, 1] end sets = [[2, 3], [4, 5], [6, 7], [8, 9]] 4.times do |i| arr = [2, 4, 6, 8] fb1 = try(arr).reduce(:+) arr[i] = sets[i][1] fb2 = try(arr).reduce(:+) if fb2 > fb1 nums.push(sets[i][1]) elsif fb2 < fb1 nums.push(sets[i][0]) end end nums.permutation(4).each do |arr| res = try(arr) if res == [4, 0] break exit 0 end end