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 = [] sets = [[2, 3], [4, 5], [6, 7], [8, 9]] elsif fst == 7 nums = [] sets = [[2, 3], [4, 5], [6, 7], [8, 9]] elsif fst == 10 nums = [0, 1] sets = [[2, 3], [4, 5], [6, 7], [8, 9]] end 4.times do |i| arr = [sets[0][0], sets[1][0], sets[2][0], sets[3][0]] 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 if nums.size < 4 arr = [0, 2, 3, 4] fb1 = try(arr).reduce(:+) arr = [1, 2, 3, 4] fb2 = try(arr).reduce(:+) if fb2 > fb1 nums.push(1) elsif fb2 < fb1 nums.push(0) end end nums.permutation(4).each do |arr| res = try(arr) break if res == [4, 0] end