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<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
#define sz(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
	priority_queue<int,vector<int>,greater<int>() >ta;
	int n,m;
	string sn,sm;
	int ans=0;
	bool used[1000000];
	bool flag[100];
	vector<string>ab;
	void dfs(int h,int f){
		if(h==sz(sm)){
		//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<endl;
		int sum=0;
		string tmp="";
		flag[sz(sm)-1]=0;
		for(int i=0;i<sz(sm);i++){
			tmp.push_back(sm[i]);
			if(flag[i])sum+=stoi(tmp),tmp="";
		}
		if(sz(tmp)>=1)sum+=stoi(tmp);
		if(f==1&&sum==ans){
			//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<endl;
			tmp="";
			for(int i=0;i<sz(sm);i++){
			tmp.push_back(sm[i]);
			if(flag[i]){ab.push_back(tmp),tmp="";}
		}
		if(!tmp.empty())ab.push_back(tmp);
		return ;
		}
		
		
		if(sum<=n)ans=max(ans,sum);
		used[sum]++;
		//for(int i=0;i<sz(sm);i++)cout<<flag[i]<<" ";cout<<sum<<endl;
		return ;
		}
		
		flag[h]=1;
		dfs(h+1,f);
		flag[h]=0;
		if(h+1<sz(sm))dfs(h+1,f);
	}
	
	int main(){
	while(cin>>n>>m,n||m){
	sn=itos(n),sm=itos(m);
	fill(used,used+1000000,0);
	fill(flag,flag+100,0);
	ans=0;
	ab.clear();
	dfs(0,0);
	if(used[ans]>=2)cout<<"rejected"<<endl;
	else if (ans==0)cout<<"error"<<endl;
	else {
		cout<<ans<<" ";
		dfs(0,1);
		for(int i=0;i<sz(ab);i++){cout<<ab[i];(i==sz(ab)-1)?cout<<endl:cout<<" ";}
	}
	}
	return 0;
}

C++: //#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
	while(1) {
		int n;
		string m;
		cin >> n >> m;
		if(!n && m == "0") break;

		bool rej = false, err = true;
		int ma = -1, ans[10] = {0}, sz = 0;
		/*if(to_string(n) == m) {
			ma = n;
			err = false;
			sz = 2;
			ans[0] = ans[1] = n;
		}*/
		FOR(i, 0, 1<<(m.size()-1)) {
			string v[10] = {""};
			v[0] = m[0];
			int idx = 0;
			REP(j, m.size()-1) {
				if(i>>j&1) idx++;
				v[idx] += m[j+1];
			}
			int sum = 0;
			REP(j, idx+1) {
				//cout << v[j] << " ";
				sum += stoi(v[j]);
			}
			//cout << "sum:" << sum << endl;
			if(sum <= n) {
				err = false;
				if(sum > ma) {
					ma = sum;
					rej = false;
					//cout << "a" << endl;
					ans[0] = sum;
					REP(j, idx+1) ans[j+1] = stoi(v[j]);
					sz = idx+2;
				} else if(sum == ma) {
					rej = true;
				}
			}
		}
		if(err) {
			cout << "error" << endl;
		} else if(rej) {
			cout << "rejected" << endl;
		} else {
			//cout << "sz:" << sz << endl;
			REP(i, sz) {
				cout << ans[i];
				if(i != sz-1) cout << " ";
			}
			cout << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <sstream>

#define TIMES(i, n) for (auto TIMES_n = (n), i = 0 * TIMES_n; i < TIMES_n; i++)
#define RANGE(c) (c).begin(), (c).end()

template <typename T>
std::string to_s(const T &t) {
  std::ostringstream ss;
  ss << t;
  return ss.str();
}

typedef std::vector<int> Ints;

struct Problem {
  int target, num;
  
  bool read() {
    return scanf("%d %d", &target, &num) == 2 && target != 0;
  }
  
  void solve() {
    std::string chars = to_s(num);
    int max = -1;
    int lesser = -1;
    Ints max_digits;
    
    TIMES(n, 1 << (chars.size() - 1)) {
      Ints digits = splits_at(chars, n);
      int sum = std::accumulate(RANGE(digits), 0);
      if (max <= sum && sum <= target) {
        lesser = max;
        max = sum;
        max_digits = std::move(digits);
      }
    }
    
    if (max < 0) {
      puts("error");
    } else if (max == lesser) {
      puts("rejected");
    } else {
      std::cout << max;
      for (auto n : max_digits) { std::cout << " " << n; }
      std::cout << "\n";
    }
  }
  
  Ints splits_at(const std::string &str, int n) {
    int i = 0;
    Ints chunks;
    TIMES(j, str.size() - 1) {
      int m = n % 2;
      n /= 2;
      if (m == 0) { continue; }
      chunks.push_back(atoi(str.substr(i, j - i + 1).c_str()));
      i = j + 1;
    }
    chunks.push_back(atoi(str.substr(i).c_str()));

    return chunks;
  }
};

int main() {
  Problem p;
  while (p.read()) { p.solve(); }
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int t;
    string num;
    while (cin >> t >> num, t != 0 || num != "0") {
        int ans = -1;
        int cnt = 0;
        vector<int> nl;
        REP (i, 0, num.size()) {
            vector<int> dis(num.size() - 1, false);
            for (int j = dis.size() - 1; j > int(dis.size() - i - 1); j--) dis[j] = true;
            do {
                int a = num[0] - '0';
                int sum = 0;
                bool mis = false;
                vector<int> prt;
                REP (k, 0, dis.size()) {
                    if (dis[k]) {
                        prt.push_back(a);
                        sum += a;
                        a = 0;
                    }
                    a = a * 10 + num[k + 1] - '0';
                }
                prt.push_back(a);
                sum += a;
                if (!mis && sum <= t) {
                    if (ans == sum) {
                        cnt++;
                    } else if (ans < sum){
                        cnt = 1;
                        ans = sum;
                        nl = prt;
                    }
                }
            } while (next_permutation(dis.begin(), dis.end()));
        }
        if (cnt >= 2) {
            cout << "rejected" << endl;
        } else if (ans == -1) {
            cout << "error" << endl;
        } else {
            cout << ans;
            for (int a : nl) {
                cout << ' ' << a;
            }
            cout << endl;
        }
    }
    return 0;
}