Go: // Package main provides
//
// File:  1237.go
// Author: ymiyamoto
//
// Created on Wed Jul 11 10:35:26 2018
//
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func comb(ns []string, aux [][]string) [][]string {
	if len(ns) == 0 {
		return aux
	}
	v := ns[0]
	a := [][]string{}
	for _, au := range aux {
		tmp := make([]string, len(au))
		copy(tmp, au)
		tmp[len(tmp)-1] += v
		a = append(a, tmp)

		au = append(au, v)
		a = append(a, au)
	}

	return comb(ns[1:], a)
}

func main() {
	for {
		var d int
		var num string
		fmt.Scan(&d, &num)
		if d == 0 {
			break
		}

		var min int
		ns := strings.Split(num, "")
		for i := range ns {
			v, _ := strconv.Atoi(ns[i])
			min += v
		}

		var ans int
		var pat []string
		var hasSame bool
		for _, c := range comb(ns[1:], [][]string{{ns[0]}}) {
			var total int
			for _, v := range c {
				n, _ := strconv.Atoi(v)
				total += n
			}
			if ans == total {
				hasSame = true
			} else if ans < total && total <= d {
				ans = total
				pat = c
				hasSame = false
			}
		}

		if ans == 0 {
			fmt.Println("error")
		} else if hasSame {
			fmt.Println("rejected")
		} else {
			fmt.Println(ans, strings.Join(pat, " "))
		}
	}
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int pow(int x, int y){
  return (y==0?1:pow(x*x,y/2)*(y%2?x:1));
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int T, N;
  while(cin>>T>>N,T){
	int dig = log10(N);
	int ans = -1;
	map<int,int> mp;
	VI part;
	for(int bit=0;bit<(1<<dig);++bit){
	  VI tmp;
	  int num = N, sum = 0, prv = 0;
	  for(int i=0;i<dig;++i){
		if((bit>>i)&1){
		  int x = (num % pow(10,i+1)) / pow(10,prv);
		  sum += x;
		  prv = i+1;
		  num = num / pow(10,i+1) * pow(10,i+1);
		  tmp.PB(x);
		}
	  }
	  if(num > 0){
		sum += num / pow(10,prv);
		tmp.PB(num/pow(10,prv));
	  }

	  if(sum <= T && ans <= sum){
		  ans = sum, part = tmp;
		  mp[ans]++;
	  }
	}
	if(mp[ans] > 1) cout << "rejected" << endl;
	else if(ans == -1) cout << "error" << endl;
	else{
	  cout << ans;
	  for(int i=SZ(part)-1;i>=0;--i)
		cout << " " << part[i];
	  cout << endl;
	}
  }
  return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<sstream>
#include<vector>
#include<map>

using namespace std;
string t,num;
int mex;
int cnt;
int int_t;
string ans_s;

void dfs(int p,int total,string s)
{
  //cout << "now s : " <<s << " p = " << p <<" total = " << total << endl; 
  if(p >= num.size())
    {
      if(int_t >= total && total == mex)
	{
	  cnt++;
	}
      else if(int_t >= total && total > mex)
	{
	  cnt = 1;
	  mex = total;
	  ans_s = s;
	}
      return;
    }

  for(int i=p;i<num.size();i++)
    {
      dfs(i+1,total + (atoi)(num.substr(p,i-p+1).c_str()),s+" "+num.substr(p,i-p+1));
    }

    

}

int main()
{
 
  while(cin >> t >> num,((atoi)(t.c_str()) || (atoi)(num.c_str())))
    {
      int pre = 0;
      for(int i=0;i<num.size();i++)
	{
	  pre += num[i]-'0';
	}      
    

      bool F = false;
      int_t = (atoi)(t.c_str());
      if(t == num)
	{
	  cout << t << " " << num << endl;
	  F = true;
	}

      if(!F)
	{
	  mex = -1,cnt = 0;
	  dfs(0,0,"");  
	 
	  if(cnt > 1)
	    cout << "rejected" << endl;
	  else if(mex != -1)
	    cout << mex << ans_s << endl;
	  else 
	    cout << "error" << endl;
	}
      
     


    }
  return 0;
}

C++: #define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve(){
	while (true) {
		int a;
		string b;
		cin >> a >> b;
		if (a == 0) return;
		vector<vector<string>> inputs;
		int now_ans = 0;
		REP(i, (1 << (b.length()  - 1))) {
			int hoge = i + (1 << (b.length()-1));
			vector<string> calc;
			string tmp;
			REP(q, b.length()) {
				tmp.push_back(b[q]);
				if (hoge % 2) {
					calc.push_back(tmp);
					tmp.clear();
				}
				hoge /= 2;
			}
			int geko = 0;
			REP(i, calc.size()) {
				geko += stoll(calc[i]);
			}
			if (geko > a) continue;
			if (geko > now_ans) {
				inputs.clear();
				now_ans = geko;
			}
			if (geko == now_ans) {
				inputs.push_back(calc);
			}
		}
		if (now_ans == 0) {
			cout << "error" << endl;
		}
		else if (inputs.size() >= 2) {
			cout << "rejected" << endl;
		}
		else {
			cout << now_ans;
			REP(i, inputs[0].size()) {
				cout << " " << inputs[0][i];
			}
			cout << endl;
		}
	}
}

#undef int
int main() {
	init();
	solve();
}