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 <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;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

vi f(string s, int a, int n){
    int x = 0;
    vi ret;
    rep(i,n){
        x *= 10;
        x += s[i] - '0';
        if(a&(1<<i)){
            ret.push_back(x);
            x = 0;
        }
    }
    x *= 10;
    x += s[n] - '0';
    ret.push_back(x);
    return ret;
}

int main(void) {
  int i,j;
  int t;
  string s;
  while(cin >> t >> s, t){
      int n = s.size()-1;
      vector<pii> ans;
      rep(i,1<<n){
          vi x = f(s,i,n);
          int sum = 0;
          rep(j,x.size())sum += x[j];
          if(sum <= t){
              ans.push_back(pii(sum,i));
          }
      }
      int sz = ans.size();
      if(sz==0){
          cout << "error" << endl;
          continue;
      }
      sort(all(ans));
      if(ans[sz-1].first == ans[sz-2].first){
          cout << "rejected" << endl;
          continue;
      }
      cout << ans[sz-1].first;
      vi x = f(s,ans[sz-1].second,n);
      rep(i,x.size())cout << " " << x[i];
      cout << endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;
void Cut(int);
void solve();
int t,len,flag,flag2,ans,ansc[6],anss;
string num;
bool cut[6];

int main(){
  while(1){
    cin>>t>>num;
    if(!t&&num=="0") break;
    for(int i=0;i<6;i++) cut[i]=false;
    len=num.size();
    flag=flag2=0;
    ans=-1;
    Cut(0);
    if(!flag) cout<<"error"<<endl;
    else{
      if(flag2) cout<<"rejected"<<endl;
      else{
	cout<<ans<<' ';
	for(int i=0;i<anss;i++) cout<<ansc[i],i==anss-1?:cout<<' ';

	cout<<endl;
      }
    }
  }
  return 0;
}

void Cut(int x){
  if(x==len-1){
    solve();
    return;
  }
  for(int i=0;i<2;i++) cut[x]=i,Cut(x+1);
}

void solve(){
  int sum=0,value=0,ind=0,v[6],f=0;
  for(int i=0;i<len;i++){
    value=value*10+(num[i]-'0');
    if(cut[i]) sum+=value,value=0;
  }
  sum+=value;
  if(sum<=t&&sum>=ans){
    value=0;
    flag=1;
    if(ans==sum) flag2=1;
    else flag2=0;
    ans=sum;
    for(int i=0;i<len;i++){
      value=value*10+(num[i]-'0');
      if(cut[i]) v[ind]=value,value=0,ind++;
    }
    v[ind]=value;
    ind++;
    anss=ind;
    for(int i=0;i<ind;i++) ansc[i]=v[i];
  }
}

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

int t;
string s;

vector<pair<int, vector<int>>> v;

void dfs(int i, int sum, vector<int> vv)
{
	if (sum > t) return;
	
	if (i == s.size()){
		v.push_back(make_pair(sum, vv));
		return;
	}
	
	/*
	
	if (s[i] == '0'){
		vv.push_back(0);
		dfs(i + 1, sum, vv);
		vv.pop_back();
		return;
	}
	
	*/
	
	int a = 0;
	for (int j = i; j < s.size(); j++){
		a *= 10;
		a += s[j] - '0';
		vv.push_back(a);
		dfs(j + 1, sum + a, vv);
		vv.pop_back();
	}
}

void solve()
{
	v.clear();
	dfs(0, 0, vector<int>());
	sort(begin(v), end(v));
	
	if (v.empty()){
		puts("error");
	}
	else if (v.size() >= 2 && v[v.size() - 1].first == v[v.size() - 2].first){
		puts("rejected");
	}
	else {
		printf("%d", v.back().first);
		for (int i = 0; i < v.back().second.size(); i++){
			printf(" %d", v.back().second[i]);
		}
		puts("");
	}
}

int main()
{
	while (cin >> t >> s, t){
		solve();
	}
}