#include<bits/stdc++.h>
using namespace std;

int main(){
	string str;
	int target;
	while(cin >> target >> str, str != "0" || target != 0){
		int len = str.size() - 1;
		int ans = -1;
		int ansi = 0;
		bool reject = false;
		for(int i = 0; i < (1 << len); i++){
			int prev = 0;
			int sum = 0;
			for(int j = 0; j < len; j++){
				if(i & (1 << j)){
					sum += stoi(str.substr(prev, (j - prev)+ 1), nullptr, 10);
					prev = j + 1;
				}
			}
			sum += stoi(str.substr(prev, str.size() - prev),nullptr, 10);
			//cout << sum << endl;
			if(sum <= target){
				if(ans == sum){
					reject = true;	
				}else if(ans < sum){
					ans = sum;
					reject = false;
					ansi = i;
				}
			}
		}
		if(ans == -1){
			cout << "error" << endl;
		}else if(reject){
			cout << "rejected" << endl;
		}else{
			cout << ans;
			int prev = 0;
			for(int j = 0; j < len; j++){
				if(ansi & (1 << j)){
					cout << " " << stoi(str.substr(prev, (j - prev)+ 1),nullptr, 10);
					prev = j + 1;
				}
			}
			cout << " " << stoi(str.substr(prev, str.size() - prev),nullptr, 10);
			cout << endl;

		}

	}
}