loop do
    t, num = gets.split.map(&:to_i)
    break if t == 0 && num == 0
    d = num.to_s.length - 1
    num = num.to_s
    max = -1
    maxp = []
    (1 << d).times do |bit|
        cur = 1 << (d - 1)
        cur_s = 0
        sum = 0
        parts = Array.new
        d.times do |i|
            if bit & cur != 0
                sum += num[cur_s..i].to_i
                parts.push(num[cur_s..i].to_i)
                cur_s = i + 1
            end
            cur = cur >> 1
        end
        parts.push(num[(cur_s)...num.length].to_i)
        sum += num[(cur_s)...num.length].to_i
        if sum > max && sum <= t
            max = sum
            maxp = parts
        elsif sum == max
            max = Float::INFINITY
        end
    end
    puts max == -1 ? "error" : (max == Float::INFINITY ? "rejected" : "#{max} #{maxp * " "}")
end