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 <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int sum;
string str;
map<int,int> ans;
map<int,int> ans2;

int to_s(const string &in) {
    int res;
    sscanf(in.c_str(),"%d",&res);
    return res;
}

void dfs(int pos,int s,int bit) {
    // cout<<pos<<","<<s<<endl;
    if(pos >= str.size()) {
        if(s <= sum) ans[s]++,ans2[s]=bit;
        return;
    }

    for(int i=1;i<=str.size()-pos;i++) {
        string tmp=str.substr(pos,i);
        // cout<<"  "<<s<<" + "<<to_s(tmp)<<endl;
        dfs(pos+i,s+to_s(tmp),bit | (1<<(pos+i)));
    }

}

void solve() {
    ans.clear();
    dfs(0,0,0);
    if(ans.size() == 0) {
        cout<<"error"<<endl;
        return;
    }
    auto it=ans.end();
    --it;

    if(it->sc==0) {
        cout<<"error"<<endl;
    }
    else if(it->sc==1) {
        int s=it->fr;
        int bit=ans2[s];
        cout<<s<<" ";
        rep(i,str.size()) {
            if((bit>>i)&1) cout<<" ";
            cout<<str[i];
        }
        cout<<endl;

    }
    else {
        cout<<"rejected"<<endl;
    }

}

int main() {
    while(cin>>sum>>str) {
        if(sum==0&&str=="0") break;
        solve();
    }
    return 0;
}

C++: #include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int sum;
string str;
map<int,int> ans;
map<int,int> ans2;

int to_s(const string &in) {
    int res;
    sscanf(in.c_str(),"%d",&res);
    return res;
}

void dfs(int pos,int s,int bit) {
    // cout<<pos<<","<<s<<endl;
    if(pos >= str.size()) {
        if(s <= sum) ans[s]++,ans2[s]=bit;
        return;
    }

    for(int i=1;i<=str.size()-pos;i++) {
        string tmp=str.substr(pos,i);
        // cout<<"  "<<s<<" + "<<to_s(tmp)<<endl;
        dfs(pos+i,s+to_s(tmp),bit | (1<<(pos+i)));
    }

}

void solve() {
    ans.clear();
    dfs(0,0,0);
    if(ans.size() == 0) {
        cout<<"error"<<endl;
        return;
    }
    auto it=ans.end();
    --it;

    if(it->sc==0) {
        cout<<"error"<<endl;
    }
    else if(it->sc==1) {
        int s=it->fr;
        int bit=ans2[s];
        cout<<s<<" ";
        rep(i,str.size()) {
            if((bit>>i)&1) cout<<" ";
            cout<<str[i];
        }
        cout<<endl;

    }
    else {
        cout<<"rejected"<<endl;
    }

}

int main() {
    while(cin>>sum>>str) {
        if(sum==0&&str=="0") break;
        solve();
    }
    return 0;
}

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++;
			}
		}
		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 <iostream>
#include <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int t, n, sum;
vector<int> ans;
bool r = false;

void dfs(vector<int> v,int n, int d) {
    if (!n) {
        int s = 0;
        for (int i = 0; i < v.size(); i++) s += v[i];
        //for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << sum << " " << s << endl;
        if (s <= t && s > sum) {
            sum = s;
            ans = v;
            r = false;
        }
        else if (s <= t && s == sum) {
            r = true;
        }
        return;
    }
    
    while (1) {
        int a = n / d;
        int b = n % d;
        //printf("n=%d d=%d a=%d b=%d\n",n,d,a,b);
        vector<int> _v = v;
        _v.push_back(a);
        d /= 10;
        dfs(_v, b, d);
        if (d == 0) break;
    }
}

int main(void){
    while (cin>>t>>n && t && n) {
        sum = -1;;
        vector<int> a;
        int d = 1;
        while (n >= d*10) d *= 10; 
        dfs(a, n, d);
        
        if (r) cout << "rejected" << endl;
        else if (sum == -1) cout << "error" << endl;
        else {
            cout << sum;
            for (int i = 0; i < ans.size(); i++) cout << " " << ans[i];
            cout << endl;
        }
    }
}