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 <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator > (const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///
int n; string s;

int main()
{
	while (cin >> n >> s, n)
	{
		bool f = false;
		int l = s.size() - 1;
		int ans = -1; vi ansv;
		REP(i, 1 << l)
		{
			int t = 0;
			int tmp = 0;
			vi v;
			REP(j, l)
			{
				if (((i >> j) & 1) == 1)
				{
					t += tmp*10 + (s[j] - '0');
					v.push_back(tmp*10 + (s[j] - '0'));
					tmp = 0;
				}
				else
				{
					tmp *= 10;
					tmp += s[j] - '0';
				}
			}
			t += tmp*10 + (s[l] - '0');
			v.push_back(tmp*10 + (s[l] - '0'));
			if (n >= t&&t > ans)
			{
				ans = t;
				ansv = v;
				f = false;
			}
			else if (t == ans) f = true;
		}
		if (f) puts("rejected");
		else if (ans == -1) puts("error");
		else
		{
			cout << ans;
			REP(i, ansv.size()) cout << " " << ansv[i];
			cout << endl;
		}
	next:;
	}
	return 0;
}

C++: // AOJ 1237
#include <bits/stdc++.h>
using namespace std;
int m;
string s;
map<int,vector< vector<string> > > res;
vector<string> his;
int dfs(string x,int t){
	if( x.size() == 0 ){
		//cout << t << endl;
		if( m >= t ) res[t].push_back(his);
		return 0;
	}
	//if( dp.count(make_pair(t,x)) ) return dp[make_pair(t,x)];
	int ans = 0;
	for(int i = 0 ; i < x.size() ; i++){
		string s = x.substr(0,i+1);
		stringstream ss(s);
		int w;
		ss >> w;
		his.push_back(s);
		ans += dfs(x.substr(i+1),t+w);
		his.pop_back();
	}
	//return dp[make_pair(t,x)] = ans;
}


int main(){
	while( cin >> m >> s && m){
		res.clear();
		dfs(s,0);
		if( res.size() == 0 ) cout << "error" << endl;
		else if( (*res.rbegin()).second.size() > 1 ) cout << "rejected" << endl;
		else{
			cout << (*res.rbegin()).first;
			for(int i = 0 ; i < (*res.rbegin()).second[0].size() ; i++)
				cout << " " << (*res.rbegin()).second[0][i];
			cout << endl;
		}
	}
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#include<sstream>
#include<vector>
#include<map>
 
using namespace std;
string t,num;
int mex;
int cnt;
int int_t;
string ans_s;
 
void dfs(int p,int total,string s)
{
  //cout << "now s : " <<s << " p = " << p <<" total = " << total << endl; 
  if(p >= num.size())
    {
      if(int_t >= total && total == mex)
    {
      cnt++;
    }
      else if(int_t >= total && total > mex)
    {
      cnt = 1;
      mex = total;
      ans_s = s;
    }
      return;
    }
 
  for(int i=p;i<num.size();i++)
    {
      dfs(i+1,total + (atoi)(num.substr(p,i-p+1).c_str()),s+" "+num.substr(p,i-p+1));
    }
 
     
 
}
 
int main()
{
  
  while(cin >> t >> num,((atoi)(t.c_str()) || (atoi)(num.c_str())))
    {
      int pre = 0;
      for(int i=0;i<num.size();i++)
    {
      pre += num[i]-'0';
    }      
     
 
      bool F = false;
      int_t = (atoi)(t.c_str());
      if(t == num)
    {
      cout << t << " " << num << endl;
      F = true;
    }
 
      if(!F)
    {
      mex = -1,cnt = 0;
      dfs(0,0,"");  
      
      if(cnt > 1)
        cout << "rejected" << endl;
      else if(mex != -1)
        cout << mex << ans_s << endl;
      else
        cout << "error" << endl;
    }
       
      
 
 
    }
  return 0;
}

C++: #include "bits/stdc++.h"
#define ll long long
#define INF (1<<30)
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1237
ll t;
string num;
ll ans;
vector<ll> ans_arr;

void dfs(ll n, ll sum,vector<ll> p) {
	if (n == num.length()) {
		p.push_back(sum);
		ll Sum = 0;
		for (int i = 0; i < p.size();i++) {
			//cout << p[i] << " ";
			Sum += p[i];
		}
		//cout << endl;
		if (Sum > t) return;

		//cout << Sum << endl;

		if (Sum > ans) {
			ans = Sum;
			ans_arr = p;
		}
		else if (Sum == ans) {
			ans_arr.clear();
			ans_arr.push_back(INF);
		}
		return;
	}

	int x = num[n] - '0';

	auto temp = p;
	if(n != 0)temp.push_back(sum);
	dfs(n + 1, x, temp);
	if(n != 0)dfs(n + 1, sum * 10 + x, p);
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> t >> num) {
		if (t == 0 && num == "0")break;
		ans = -1;
		ans_arr.clear();
		vector<ll> p;
		dfs(0,0, p);

		if (ans == -1) {
			cout << "error" << endl;
			continue;
		}

		if (ans_arr[0] == INF) {
			cout << "rejected" << endl;
			continue;
		}

		cout << ans;
		for (int i = 0; i < ans_arr.size();i++) {
			cout << " " << ans_arr[i];
		}
		cout << endl;
	}
}

C++: #include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;

map<int, pair<vector<int>,int>>getans(string st) {
	map<int, pair<vector<int>,int>>ans;
	ans[stoi(st)] = make_pair(vector<int>(1,stoi(st)),1);
	if (st.size()) {
		for (int i = 1; i < st.size(); ++i) {
			map<int, pair<vector<int>, int>>mp(getans(st.substr(i, st.size() - i)));
			for (auto& j : mp) {
				string from = st.substr(0, i);
				vector<int>now(1, stoi(from) );
				if (!ans.count(stoi(from) + j.first)) {		
					now.insert(now.end(), j.second.first.begin(), j.second.first.end());
					ans[stoi(from) + j.first] = make_pair(now, j.second.second);
				}
				else {
					ans[stoi(from) + j.first].second+=j.second.second;
				}
			}
		}
	}
	
	return ans;
}

int main() {
	while (1) {
		int sum; string num; cin >> sum >> num;
		if (sum == 0)break;
		map<int, pair<vector<int>, int>>mp(getans(num));
		auto it(mp.upper_bound(sum));

		if (it == mp.begin()) {
			cout << "error" << endl;
		}
		else if (prev(it)->second.second != 1) {
			cout << "rejected" << endl;
		}
		else {
			cout << prev(it)->first;
			for (int i = 0; i < prev(it)->second.first.size(); ++i) {
				cout <<" "<< prev(it)->second.first[i];
			}
			cout << endl;
		}

	}
	return 0;
}