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 <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int stoa(string s) {
	int ret = 0, t = 1;
	for(int i = s.size()-1; i >= 0; i--) {
		ret += (s[i] - '0') * t;
		t *= 10;
	}
	return ret;
}

int n;
string s;
int vmin = INF, vmax = 0, ans = 0, cnt = 0;
vector<int> res;

void dfs(int i, int sum, vector<int> v) {
	if(i == s.size()) {
		vmin = min(vmin, sum);
		vmax = max(vmax, sum);

		if(sum <= n) {
			if(ans < sum) {
				ans = sum;
				cnt = 1;
				res.clear();
				rep(i, v.size()) res.push_back(v[i]);
			} else if(ans == sum) {
				cnt++;
			} else cnt = 0;
		}
		return;
	}

	REP(j, 1, s.size() + 1) {
		// cout << "i:" << i <<  " j:" << j << " sum:" << sum << " " << s.substr(i, j) << " " << stoa(s.substr(i, j)) << endl;
		if(i + j <= s.size() ) {
			vector<int> t(v.begin(), v.end());
			t.push_back(stoa(s.substr(i, j)));
			dfs(i + j, sum + stoa(s.substr(i, j)), t);
		} else return;
	}
}

int main() {
	while(cin >> n >> s) {
		if(n == 0 && s == "0") break;

		vmin = INF, vmax = 0, ans = 0, cnt = 0;
		res.clear();

		vector<int> v;
		dfs(0, 0, v);

		if(vmin > n) {
			cout << "error" << endl;
		} else if(cnt >= 2) {
			cout << "rejected" << endl; 
		} else {
			cout << ans;
			rep(i, res.size()) {
				cout << " " << res[i];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int t;
    string s;
    while (cin >> t >> s, t)
    {
        int n = s.length();
        bool reject = false;
        int sum = -INF;
        vector<int> res;
        for (int i = 0; i < (1 << (n-1)); i++)
        {
            int stmp = 0, tmp = 0;
            bool update=false;
            vector<int> v;
            for (int j = 0; j < n; j++)
            {
                update=true;
                tmp *= 10;
                tmp += (s[j] - '0');
                if ((i >> j) & 1)
                {
                    stmp += tmp;
                    v.push_back(tmp);
                    tmp = 0;
                    update = false;
                }
            }
            if (update)
            {
                stmp += tmp;
                v.push_back(tmp);
            }
            if (stmp < sum || t < stmp){
                continue;
            }
            if (stmp == sum)
            {
                reject = true;
            }
            else
            {
                reject = false;
                res = v;
                sum = stmp;
            }
        }
        if (sum == -INF)
        {
            cout << "error" << endl;
        }
        else if (reject)
        {
            cout << "rejected" << endl;
        }
        else
        {
            cout << sum;
            for (int i = 0; i < (int)res.size(); i++)
                cout << " " << res[i];
            cout << endl;
        }
    }
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int t;
string s;
vector<vi> vvi;

void dfs(int pnt, vi v) {
	if(pnt == s.size()) {
		vvi.pb(v);
		return;
	}
	else {
		string s2 = "";
		FOR(i, pnt, s.size()) {
			vi v2 = v;
			if(i > s.size())
				break;
			s2 += s[i];
			v2.pb(stoi(s2));
			dfs(i + 1, v2);
		}
	}
}

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

	while(cin >> t, t) {
		vvi.clear();
		cin >> s;
		dfs(0, vi());
		int max = 0, pnt = -1;
		bool flg = false;
		REP(i, vvi.size()) {
			int sum = 0;
			REP(j, vvi[i].size())
				sum += vvi[i][j];
			if(sum <= t && sum > max) {
				max = sum; pnt = i;
				flg = false;
			}
			else if(sum == max)
				flg = true;
		}
		if(flg)
			cout << "rejected" << endl;
		else if(pnt == -1)
			cout << "error" << endl;
		else {
			cout << max << ' ';
			REP(i, vvi[pnt].size()) {
				if(i)
					cout << ' ';
				cout << vvi[pnt][i];
			}
			cout << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

vi ansv, v;
int n, ans, cnt;
string m;

void rec(int c, int sum){
	if(sum > n) return;
	if(c == m.size()){
		if(sum > ans){
			ans = sum, cnt = 0;
			ansv = v;
		}
		if(ans == sum) cnt++;
		return;
	}
	rep(i, m.size() - c){
		int d = atoi(m.substr(c, i + 1).c_str());
		v.pb(d);
		rec(c + i + 1, sum + d);
		v.pop_back();
	}
}
int main(){
	while(cin >> n >> m, n){
		v.clear();
		ans = cnt = 0;
		rec(0, 0);
		
		if(cnt == 0) cout << "error" << endl;
		else if(cnt > 1) cout << "rejected" << endl;
		else{
			cout << ans << " ";
			rep(i, ansv.size()) cout << ansv[i] << (i==ansv.size()-1?"\n":" ");
		}
	}
	return 0;
}