#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;



int best;
int best_count;
vector<int> res;


void dfs(string n, int sum, int target, vector<int> v){
  if(sum > target) return;
  if(n == ""){
    if(sum > best){
      best = sum;
      best_count = 1;
      res = v;
    }else if(sum == best){
      best_count++;
    }
    return;
  }
  
  REP(i, n.size()){
    string n1 = n.substr(0, i + 1);
    string n2 = n.substr(i + 1);
    
    vector<int> v2 = v;
    v2.push_back(atoi(n1.c_str()));
    dfs(n2, sum + atoi(n1.c_str()), target, v2);
  }
}
int main(){
  string sheet;
  int target;
  while(cin >> target >> sheet && (sheet != "0" || target > 0)){
    best = -1;
    best_count = 0;
    dfs(sheet, 0, target, vector<int>());
    if(best == -1){
      cout << "error" << endl;
    }else if(best_count > 1){
      cout << "rejected" << endl;
    }else{
      cout << best << " " ;
      REP(i, res.size()) cout << res[i] << (i + 1 == (int)res.size() ? '\n' : ' ');
    }
  }
  return 0;
}