def shred str, pattern
    arr, add = [], ""
    pattern.length.times{|i|
        add += str[i]
        if pattern[i] == "1"
            arr << add
            add = ""
        end
    }
    add += str[-1] if str.length > 1
    arr << add
    arr
end

while true
    target, paper = gets.chomp.split
    break if [target, paper] == ["0", "0"]

    target = target.to_i
    max = Hash.new{|h, k| h[k] = []}
    (2 ** (paper.length - 1)).times{|i|
        pattern = sprintf("%0#{paper.length - 1}b", i)
        numbers = shred(paper, pattern)
        sum = numbers.map(&:to_i).inject(:+)
        max[sum] << numbers if sum <= target
    }
    first = max.to_a.sort_by!{|k, v| -k}[0]
    answer = nil
    if first.nil?
        answer = "error"
    elsif first[1].length > 1
        answer = "rejected"
    else
        answer = "#{first[0]} " + first[1].join(" ")
    end
    puts answer
end
