#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        string s;
        cin >> n >> s;
        if(n == 0)
            return 0;

        int len = s.size();
        int ret = INT_MIN;
        int cut;
        bool rejected;
        for(int i=0; i<(1<<(len-1)); ++i){
            bitset<5> bs(i);
            int a = s[0] - '0';
            int b = 0;
            for(int j=0; j<len-1; ++j){
                if(bs[j]){
                    b += a;
                    a = 0;
                }
                a *= 10;
                a += s[j+1] - '0';
            }
            b += a;

            if(b <= n){
                if(b > ret){
                    ret = b;
                    cut = i;
                    rejected = false;
                }else if(b == ret){
                    rejected = true;
                }
            }
        }

        if(ret == INT_MIN){
            cout << "error" << endl;
        }else if(rejected){
            cout << "rejected" << endl;
        }else{
            cout << ret << ' ';
            bitset<5> bs(cut);
            for(int i=0; i<len-1; ++i){
                cout << s[i];
                if(bs[i])
                    cout << ' ';
            }
            cout << s[len-1] << endl;
        }
    }
}