loop do
    t, sheet = gets.chomp.split
    target = t.to_i
    break if target == 0

    hash = {}
    (0 .. 2 ** (sheet.size - 1) - 1).each do |x| 
        arr = [-1] + (0..sheet.size-1).select {|i| x[i] == 1} + [sheet.size-1]

        part = arr.each_cons(2).map {|i, j| sheet[i+1..j]}
        # next if part.any?{|s| s =~ /^0./}
        sum = part.map(&:to_i).inject(:+)
        (hash[sum] ||= []) << part
    end 

    hash.delete_if {|s, _| s > target}

    if hash.empty?
        puts 'error'
    else
        max = hash.keys.max

        if hash[max].size > 1 
            puts 'rejected'
        else
            puts ([max] + hash[max][0]) * ' ' 
        end 
    end 
end