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<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;

int n,maxn;
vector<int> V,maxV;

void Shred(int sum,int m,string s)
{
  if(sum>n){
    return;
  }
  if(s.empty()){
    if(maxn<sum){
      maxn=sum;
      maxV.clear();
      for(int i=0;i<V.size();i++){
	maxV.push_back(V[i]);
      }
    }
    return;
  }
  for(int i=1;i<s.length()+1;i++){
    m=atoi(s.substr(0,i).c_str());
    V.push_back(m); 
    Shred(sum+m,m,s.substr(i,s.length()));
    V.pop_back();
  }
}

int main()
{
  string s;
  int m,flag;
  while(1){
    cin>>n>>s;
    if(n==0 && s[0]=='0')break;
    maxn=0;flag=0;
    for(int i=1;i<s.length()+1;i++){
      V.clear();
      m=atoi(s.substr(0,i).c_str());
      V.push_back(m); 
      Shred(m,m,s.substr(i,s.length()));
    }
    for(int i=1;i<s.length()-1;i++){
      if(s[i]=='0' || (s[i]==s[i-1] && s[i]==s[i+1])){
	cout<<"rejected"<<endl;
	flag=1;
        break;
      }
    }
    if(flag==1)continue;
    if(maxn==0)cout<<"error"<<endl;
    else{
      cout<<maxn;
      for(int i=0;i<maxV.size();i++)cout<<" "<<maxV[i];
      cout<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

int main(){
	int n;
	string s;
	while (cin >> n >> s, n){
		int len = s.size();
		int ans = 0;
		vector<vector<int>> div;
		rep(i, 1 << (len - 1)){
			vector<int> v;
			int x = 0;
			int sum = 0;
			rep(j, len){
				if (j && (i&(1 << j - 1))){
					v.push_back(x);
					sum += x;
					x = 0;
				}
				x = x * 10 + s[j] - '0';
			}
			v.push_back(x);
			sum += x;

			if (sum <= n){
				if (ans < sum){
					div.clear();
					ans = sum;
				}
				if (ans == sum){
					div.push_back(v);
				}
			}
		}

		if (div.size() == 0){
			cout << "error" << endl;
		}
		else if (div.size() == 1){
			cout << ans;
			for (auto e : div[0]){
				cout << ' ' << e;
			}
			cout << endl;
		}
		else{
			cout << "rejected" << endl;
		}
	}

	return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
#define INFTY (1<<21)
int target;
string source;
vector<vector<string> > ans;
int diff;

void update(vector<int> c ){
    vector<string> s;
    for ( int i = 0; i < c.size()-1; i++ ){
	s.push_back(source.substr(c[i], c[i+1]-c[i]));
    }
    int sum = 0;
    for ( int i = 0; i < s.size(); i++ ) sum += atoi(s[i].c_str());

    if ( sum > target ) return;

    if ( target - sum == diff ){
	ans.push_back(s);
    } else if ( target - sum < diff ){
	diff = target - sum;
	ans.clear();
	ans.push_back(s);
    }
}

void rec(int pos, vector<int> c){
    if ( pos == source.size() ){
	c.push_back(pos);
	update(c);
	return;
    }
    rec(pos+1, c);
    c.push_back(pos);
    rec(pos+1, c);
    c.pop_back();
}

void compute(){
    vector<int> c;
    c.push_back(0);
    diff = INFTY;
    ans.clear();
    rec(1, c);

    if ( diff == INFTY ) cout << "error" << endl;
    else if ( ans.size() > 1 ) cout << "rejected" << endl;    
    else { 
	cout << target - diff;
	for ( int i = 0; i < ans[0].size(); i++ ) cout << " " << ans[0][i];
	cout << endl;
    }
}

main(){
    while( cin >> target >> source){
	if ( target == 0 && source == "0" ) break;
	compute();
    }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string t, num;

int main() {
	while (cin >> t >> num && !(t == "0"&&num != "0")) {
		ll n = -1;
		bool f = 1;
		vector<int> ans;
		rep(i, (1 << (num.size() - 1))) {
			ll sum = 0;
			vector<int> k;
			ll nn = num[0] - '0';
			rep(j, num.size() - 1) {
				if (i & (1 << j)) {
					nn *= 10;
				}
				else {
					sum += nn;
					k.push_back(nn);
					nn = 0;
				}
				//cout << "!!" << nn << endl;
				nn += num[j + 1] - '0';
			}
			sum += nn;
			//cout << "!" << sum << endl;
			if (nn != 0 || num.back() == '0')k.push_back(nn);
			if (sum <= stoi(t)) {
				if (sum > n) {
					n = sum;
					f = 1;
					ans = k;
				}
				else if (sum == n) {
					f = 0;
				}
			}
		}
		if (!f)cout << "rejected" << endl;
		else {
			if (n == -1)cout << "error" << endl;
			else {
				cout << n << " ";
				rep(i, ans.size()) {
					if (i != 0)cout << " ";
					cout << ans[i];
				}
				cout << endl;
			}
		}
	}
}