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(:+) puts fst end if fst == 4 sets = [[2, 3], [4, 5], [6, 7], [8, 9]] elsif fst == 7 sets = [[0, 1], [2, 3], [4, 5], [6, 7]] elsif fst == 10 sets = [[0, 0], [1, 1], [2, 3], [6, 7]] end nums = [] raise "#{nums}" 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]) else nums.push(sets[i][0]) end end nums.permutation(4).each do |arr| res = try(arr) break if res == [4,0] end