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 <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int s2i(string s){
    stringstream ss;
    ss << s;
    int ret;
    ss >> ret;
    return ret;
}
int main(){
    while(true){
        string target,input;
        cin >> target >> input;
        if(target == "0") break;
        int itarget = s2i(target);

        if(input.length() == 1){
            int iinput = s2i(input);
            if(iinput <= itarget){
                cout << iinput << " " << iinput << endl;
            }else{
                cout << "error" << endl;
            }
        }else{
            int N = input.size()-1;

            int maxi = -1;
            bool reject = false;
            vector<string> ans;
            for(int i=0;i<(1 << N);i++){
                vector<string> cutup;
                int before=0;
                for(int j=0;j<N;j++){
                    if(i & (1 << j)){
                        cutup.push_back(input.substr(before,j-before+1));
                        before = j+1;
                    }
                }
                cutup.push_back(input.substr(before));
                // for(int j=0;j<cutup.size();j++){
                //     cerr << cutup[j] << " ";
                // }
                // cerr << endl;
                int nyan = 0;
                for(int i=0;i<cutup.size();i++){
                    nyan += s2i(cutup[i]);
                }
                if(nyan > itarget) continue;
                if(maxi == nyan){
                    reject = true;
                }else if(nyan > maxi){
                    maxi = nyan;
                    ans = cutup;
                    reject = false;
                }
            }
            if(reject){
                cout << "rejected" << endl;
            }else if(maxi == -1){
                cout << "error" << endl;
            }else{
                cout << maxi << " ";
                for(int i=0;i<ans.size();i++){
                    cout << " " << ans[i];
                }
                cout << endl;
            }
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int t;
string s;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>t>>s;
		if(t==0)break;
		int res=-1;
		bool rejected=false;
		vector<string> ans;
		rep(i,1<<(s.length()-1)){
			string ss="";
			vector<string> a;
			int sum=0;
			rep(j,s.length()-1){
				ss+=s[j];
				if(i>>j&1){
					sum+=stoi(ss);
					a.pb(ss);
					ss="";
				}
			}
			ss+=s[s.length()-1];
			a.pb(ss);
			sum+=stoi(ss);
			if(sum<=t){
				if(res==sum)rejected=true;
				else if(res<sum){
					res=sum;rejected=false;
					ans=a;
				}
			}
		}
		if(rejected)cout<<"rejected"<<endl;
		else if(res==-1)cout<<"error"<<endl;
		else{
			cout<<res;
			rep(i,ans.size())cout<<" "<<ans[i];
			cout<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
int main() {
	int tar; string s;
	while (cin >> tar >> s, tar) {
		int len = s.length() - 1;
		int ma = -1;
		rep(i, 1 << len) {
			int now = 0;
			vector<string>t;
			rep(j, len) {
				if ((i >> j) & 1) {
					t.push_back(s.substr(now, j + 1 - now));
					now = j + 1;
				}
			}
			t.push_back(s.substr(now, len+1 - now));
			int sum = 0; int l = t.size();
			rep(j, l) {
				sum += stoi(t[j]);
			}
			if (sum <= tar)ma = max(ma, sum);
		}
		if (ma == -1) {
			cout << "error" << endl; continue;
		}
		int cnt = 0; vector<string> out;
		rep(i, 1 << len) {
			int now = 0;
			vector<string>t;
			rep(j, len) {
				if ((i >> j) & 1) {
					t.push_back(s.substr(now, j + 1 - now));
					now = j + 1;
				}
			}
			t.push_back(s.substr(now, len + 1 - now));
			int sum = 0; int l = t.size();
			rep(j, l) {
				sum += stoi(t[j]);
			}
			if (sum == ma) {
				cnt++; out = t;
			}
		}
		if (cnt > 1) {
			cout << "rejected" << endl;
		}
		else {
			cout << ma;
			int l = out.size();
			rep(i, l) {
				cout << " " << out[i];
			}
			cout << endl;
		}
	}
	return 0;
}