offset = 0 flag = false pre = 0 10.times do |i| 10.times do |j| flowNum = j * 10 ** i puts '%010d' % (flowNum + offset) STDOUT.flush hit, state = gets.chomp.split() if state == 'unlocked' flag = true break end if j == 0 pre = hit.to_i elsif hit.to_i < pre offset += (j - 1) * 10 ** i break elsif hit.to_i > pre offset += flowNum break end end break if flag end