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 <stdio.h>
#include <cctype>
#include <limits.h>
#include <cmath>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

int S;
string N;

int ans=-1;
vector<int> ans_list;
bool ng;

void init()
{
    ans = -1;
    ans_list.resize(0);
    ng = false;
}

void solve(int sum, int k, vector<int> list)
{
    if (sum > S) return;

    if (k == N.size()) { 
        if (sum > ans) {
            ans = sum;
            ans_list = list;
            ng = false;
        } else if (sum == ans) {
            ng = true;
        }
        return;
    }
    
    int n = 0;
    for (int i=0; k+i<N.size(); i++) {
        n *= 10;
        n += N[k+i] - '0';
        
        list.push_back(n);
        solve(sum+n, k+i+1, list);
        list.erase(list.end()-1);
    }
}

int main()
{
    while (cin>>S>>N, S) {
        init();
        
        solve(0, 0, vector<int>());
        
        if (ans == -1) cout << "error" << endl;
        else if (ng) cout << "rejected" << endl;
        else {
            cout << ans << " ";
            for (int i=0; i<ans_list.size(); i++) {
                if (i>0) cout << " ";
                cout << ans_list[i];
            }
            cout << endl;
        }
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
void solve(int x,string y){
	int n=y.size();
	bool same=false;
	int mx=-1;
	vector<int> mvc;
	rep(i,1<<(n-1)){
		int a[7]={};
		rep(j,n-1) a[j]=(i>>j)&1;
		int sum=0,now=y[0]-'0';
		vector<int> vc;
		rep(j,n-1){
			if(a[j]==0){
				now*=10;
				now+=y[j+1]-'0';
			}else{
				sum+=now;
				vc.pb(now);
				now=y[j+1]-'0';
			}
		}
		sum+=now;
		vc.pb(now);
		if(x<sum||sum<mx) continue;
		if(sum==mx){
			same=true;
			continue;
		}
		mx=sum;
		same=false;
		mvc=vc;
	}
	if(same){
		puts("rejected");
		return;
	}
	if(mx==-1){
		puts("error");
		return;
	}
	cout<<mx;
	for(int a:mvc) cout<<" "<<a;
	puts("");
}
int main(){
	while(true){
		int x;
		string y;
		cin>>x>>y;
		if(x==0) break;
		solve(x,y);
	}
}

C++: //26
#include<iostream>
#include<string>
#include<vector>
#include<cstdlib>
#include<numeric>
#include<sstream>

using namespace std;

int t;

string sad(string a,string b){
  stringstream ss;
  ss<<atoi(a.c_str())+atoi(b.c_str());
  return ss.str();
}

vector<string> dfs(string n,vector<string> v){
  if(n.empty()){
    if(t>=atoi(accumulate(v.begin(),v.end(),string("0"),sad).c_str())){
      return v;
    }else{
      return vector<string>();
    }
  }else{
    vector<string> r;
    int m=-1;
    for(int i=0;i<n.size();i++){
      vector<string> nv=v;
      nv.push_back(n.substr(0,i+1));
      vector<string> rv=dfs(n.substr(i+1),nv);
      if(!rv.empty()){
	int ca=atoi(accumulate(rv.begin(),rv.end(),string("0"),sad).c_str());
	if(ca==m){
	  r.push_back("1");
	  r.push_back("-1");
	}else if(ca>m){
	  m=ca;
	  r=rv;
	}
      }
    }
    return r;
  }
}

int main(){
  string n;
  while(cin>>t>>n,t||n!="0"){
    if(t==atoi(n.c_str())){
      cout<<t<<' '<<t<<endl;
    }else{
      vector<string> v=dfs(n,vector<string> ());
      if(v.empty()){
	cout<<"error"<<endl;
      }else if(*v.rbegin()=="-1"){
	cout<<"rejected"<<endl;
      }else{
	cout<<atoi(accumulate(v.begin(),v.end(),string("0"),sad).c_str())<<' ';
	for(int i=0;i<v.size();i++){
	  cout<<v[i]<<((i==v.size()-1)?'\n':' ');
	}
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 100000000
int po[8];
int t;
int result;
vector<int> ans;
vector<int> anss;

int Stoi(string s){
    if(s == "") return 0;
    else{

        int res = 0;
        int n = (int)s.size();
        n--;
        for(int i = 0; i < s.size(); i++){
            res += (int)(s[i] - '0') * po[n];
            n--;
        }

        return res;
    }
}

void rec(vector<int>& a, string num, int idx, string tmp, int sum){

    tmp += num[idx];
    if(idx == (int)num.size() - 1){
        ans.push_back(Stoi(tmp));
        sum += Stoi(tmp);
        if(sum <= t){
            if(result == sum){
                a.push_back(sum);
            }else if(result < sum || result == INF){
                result = sum;
                anss = ans;
            }
        }
        ans.pop_back();
        return;
    }

    //切らない
    rec(a, num, idx + 1, tmp, sum);

    //切る
    ans.push_back(Stoi(tmp));
    sum += Stoi(tmp);
    tmp = "";
    rec(a, num, idx + 1, tmp, sum);
    ans.pop_back();
    return;
}

int main(){
    
    po[0] = 1;
    for(int i = 1; i < 8; i++){
        po[i] = po[i - 1] * 10;
    }

    //cout << Stoi("157") << " " << Stoi("") << endl;

    while(1){
        string num; cin >> t >> num;
        if(!t) break;
        vector<int> a;
        result = INF;
        rec(a, num, 0, "", 0);
        
        for(int i = 0; i < a.size(); i++){
            if(result == a[i]){
                result = -1;
                break;
            }
        }
        if(result == INF) cout << "error" << endl;
        else if(result == -1) cout << "rejected" << endl;
        else{
            cout << result << " ";
            for(int i = 0; i < (int)anss.size(); i++){
                if(i == (int)anss.size() - 1) cout << anss[i] << endl;
                else cout << anss[i] << " ";
            }
        }
    }

    return 0;
}