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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

string solve(int A, string B) {
    string ret = "error";
    int max_sum = 0;
    for (int i = 0; i < (1 << (B.length() - 1)); i++) {
        int bits = i;
        int sum = 0;
        int num = 0;
        string shredded;
        for (int j = 0; j < B.length(); j++) {
            num += B[j] - '0';
            shredded += B[j];
            if (bits & (1 << j) || j == B.length() - 1) {
                sum += num;
                num = 0;
                if (j != B.length() - 1) shredded += ' ';
            }
            num *= 10;
        }
        if (sum > max_sum && A >= sum) {
            ret = to_string(sum) + ' ' + shredded;
            max_sum = sum;
        } else if (sum == max_sum) {
            ret = "rejected";
        }
    }
    return ret;
}

int main(void) {
    int a;
    string b;
    vector<string> ans;
    while (1) {
        cin >> a >> b;
        if (a == 0) break;
        ans.push_back(solve(a, b));
    }
    for (auto i : ans) {
        cout << i << endl;
    }
}

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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int S;string T;
    while(cin>>S>>T,S!=0||T!="0"){
        map<int,vint>M;
        int n=T.size()-1;
        rep(b,1<<n){
            int sum=0,tmp=T[0]-'0';
            rep(i,n){
                if(b>>i&1){
                    sum+=tmp;
                    tmp=0;
                }
                tmp=tmp*10+T[i+1]-'0';
            }
            sum+=tmp;
            if(sum<=S)M[sum].pb(b);
        }
        if(M.size()==0){
            cout<<"error"<<endl;
            continue;
        }
        vint &v=M.rbegin()->se;
        if(v.size()>=2){
            cout<<"rejected"<<endl;
            continue;
        }
        int b=v[0];
        cout<<M.rbegin()->fi<<" ";
        cout<<T[0];
        rep(i,n){
            if(b>>i&1)cout<<" ";
            cout<<T[i+1];
        }cout<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,ans,l;
string a,s;
multiset<int>pp;
void ch(string t){
  int p=0,x=10,ss=l;
  for(int i=0;i<t.size();i++){
    if(t[i]=='+')p+=ss%x,ss/=x,x=10;
    else x*=10;
  }
    if(ans<=p&&p<=n){
      ans=p,a=t;
      pp.insert(p);
    }
}
void dfs(int d,string t){
  if(d==s.size())ch(t+'+');
  else {
    dfs(d+1,t+'+');
    dfs(d+1,t+'-');
  }
}
int f(string q){
  int o=0;
  for(int i=0;i<q.size();i++)
    o*=10,o+=q[i]-'0';
  return o;
}
string chq(string t){
  reverse(t.begin(),t.end());
  string u;
  u+=t[0];
  for(int i=1;i<t.size();i++){
    if(a[i-1]=='+')u+=' ';
    u+=t[i];
  }
  reverse(u.begin(),u.end());
  return u;
}
int main(){
  while(cin>>n>>s,n){
    pp.clear();
    l=f(s);
    ans=0;
    dfs(0,"");
    if(ans==0)cout<<"error"<<endl;
    else if(pp.count(ans)>=4)cout<<"rejected"<<endl;
    else{
      cout<<ans<<' ';
      string qq=chq(s);
      cout<<qq<<endl;
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int>res;
int ma,cnt;

void dfs(int s,const int t,const string n,vector<int>&v){
	if(s>t)return;
	if(n.empty()){
		if(ma<s)ma=s,cnt=0;
		if(ma==s)res=v,cnt++;
	//}else if(n[0]=='0'){
	//	v.push_back(0);
	//	dfs(s,t,n.substr(1),v);
	//	v.pop_back();
	}else{
		int add=0;
		for(int i=0;i<n.size();i++){
			add=add*10+n[i]-'0';
			v.push_back(add);
			dfs(s+add,t,n.substr(i+1),v);
			v.pop_back();
		}
	}
}

int main(){
	int t;
	string n;
	for(;cin>>t>>n,t;){
		vector<int>v;
		ma=0,cnt=0;
		dfs(0,t,n,v);
		if(cnt>1)puts("rejected");
		else if(!ma)puts("error");
		else{
			printf("%d",ma);
			for(int i=0;i<res.size();i++)printf(" %d",res[i]);
			puts("");
		}
	}
}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};



int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int m;
		string s;
		cin>>m>>s;
		if(m==0&&s=="0") break;
		int n=s.size(),mx=-1;
		vector<vs> res;
		for(int i=0;i<1<<(n-1);i++){
			string t="";
			int x=0;
			vs a;
			for(int j=0;j<n;j++){
				t+=s[j];
				if((i&1<<j)||(j==n-1)){
					x+=atoi(t.c_str());
					a.push_back(t);
					t="";
				}
			}
			if(x<=m&&mx<=x){
				if(x>mx) res.clear();
				res.push_back(a);
				mx=x;
			}
		}
		if(res.empty()) cout<<"error"<<endl;
		else if(res.size()>1) cout<<"rejected"<<endl;
		else{
			cout<<mx;
			for(auto i:res[0]) cout<<' '<<i;
			cout<<endl;
		}
	}
}