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 <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

int main() {
  int n;
  string s;
  while(cin >>n >>s && n){
    int ans = -1;
    bool reject = false;
    vector<string> v;
    
    int lim = (1 << ((int)(s.length()) - 1));
    for(int cut = 0; cut < lim; ++cut){
      int last = 0;
      vector<string> tmp;
      for(int mask = 1, i = 0; mask < lim && i < (int)(s.length()); mask = (mask << 1), ++i){
        if((cut & mask) != 0){
          tmp.push_back(s.substr(last, i + 1 - last));
          last = i + 1;
        }
      }
      if(last != (int)(s.length())) tmp.push_back(s.substr(last, (int)(s.length()) - last));
      int sum = 0;
      REP(i, tmp.size()) sum += (atoi(tmp[i].c_str()));

      if(sum > n) continue;

      //debug
      //cout <<"=============" <<endl;
      //cout <<cut <<endl;
      //cout <<sum <<endl;
      //REP(i, tmp.size()) cout <<tmp[i] <<", ";
      //cout <<endl;

      if(sum > ans){
        ans = sum;
        reject = false;
        v = tmp;
      } else if(sum == ans){
        reject = true;
      }
    }

    if(ans == -1) cout <<"error" <<endl;
    else if(reject) cout <<"rejected" <<endl;
    else{
      cout <<ans;
      REP(i, v.size()) cout <<" " <<v[i];
      cout <<endl;
    }
  }
  return 0;
}

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>
using namespace std;

int t;
string s;

vector<vector<int> > ans;
int ma = 0;

void func2(int n, int now, int sum) {
  //cout << n << " " << now << " " << sum << endl;
  if ( n == (int)s.size() ) {
    if ( now+sum <= t ) {
      ma = max(ma, now+sum);
      return;
    } else {
      return;
    }
  }

  if ( ans.size() >= 2 ) return;

  func2(n+1, now*10+(s[n]-'0'), sum);
  func2(n+1, s[n]-'0', sum+now);
}

void func(int n, int now, int sum, vector<int> v) {
  if ( n == (int)s.size() ) {
    if ( now+sum == ma ) {
      //cout << n << " " << now << " " << sum << endl;
      vector<int> tmp;
      tmp = v;
      tmp.push_back(now);
      ans.push_back(tmp);
      return;
    } else {
      return;
    }
  }

  if ( ans.size() >= 2 ) return;

  func(n+1, now*10+(s[n]-'0'), sum, v);
  v.push_back(now);
  func(n+1, s[n]-'0', sum+now, v);
}

int main() {

  while ( cin >> t >> s, t && s != "0" ) {
    ma = 0;
    ans.clear();
    func2(1, s[0]-'0', 0);
    //cout << ma << endl;
    vector<int> v;
    func(1, s[0]-'0', 0, v);
    
    if ( ans.size() == 0 ) cout << "error" << endl;
    else if ( ans.size() == 1 ) {
      cout << ma << " ";
      for ( int i = 0; i < (int)ans[0].size()-1; i++ ) {
	cout << ans[0][i] << " ";
      }
      cout << ans[0][(int)ans[0].size()-1] << endl;
    }
    else cout << "rejected" << endl;
  }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<functional>
using namespace std;

#define MAX_N 19

long long K, m;
int dig[MAX_N], cut[MAX_N], sum;
vector<pair<long long, string>>vec;
char T[11] = "0123456789";

void _memset() {
	sum = 0;
	for (int i = 0; i < MAX_N; i++) {
		dig[i] = 0;
		cut[i] = 0;
	}
	vec.clear();
}

long long power(long long n, long long v) {
	long long res = 1;
	for (int i = 0; i < v; i++) {
		res *= n;
	}
	return res;
}

int digits(long long n) {
	for (int i = 0; i < MAX_N; i++) {
		if (power(10, i) >= n) { return i + 1; }
	}
}

long long STOI(string U) {
	long long res = 0;
	for (int i = 0; i < U.size(); i++) {
		for (int j = 0; j < 10; j++) {
			if (U[i] == T[j]) {
				res += power(10, U.size() - 1 - i)*j;
			}
		}
	}
	return res;
}

string TOSTR(long long n) {
	string S = ""; bool ok = false;
	for (int i = MAX_N - 1; i >= 0; i--) {
		long long b = power(10, i);
		long long c = (n / b) % 10;
		if (c >= 1) {
			ok = true;
		}
		if (ok == true) {
			S += T[c];
		}
	}
	return S;
}

string make(vector<long long>vect) {
	string W = "";
	for (int i = 0; i < vect.size(); i++) {
		if (i >= 1) { W += ','; }
		W += TOSTR(vect[i]);
	}
	return W;
}

vector<long long>kaiseki(string W) {
	vector<long long>vec4;
	string X = "";
	W += ',';
	for (int i = 0; i < W.size(); i++) {
		if (W[i] == ',') {
			vec4.push_back(STOI(X));
			X = "";
		}
		else {
			X += W[i];
		}
	}
	return vec4;
}

int main() {
	while (true) {
		_memset();
		cin >> K >> m;
		if (K == 0 && m == 0) {
			break;
		}

		int digit = digits(m);
		string S = "";
		vector<long long>vec2;
		vec2.clear();

		for (int i = 0; i < MAX_N; i++) {
			dig[i] = (m / power(10, i)) % 10;
		}
		for (int i = 0; i < power(2, digit - 1); i++) {
			S = "";
			sum = 0;
			vec2.clear();
			for (int j = 0; j < MAX_N; j++) {
				cut[j] = 0;
			}
			for (int j = 0; j < digit - 1; j++)
			{
				int a = power(2, j);
				cut[j] = (i / a) % 2;
			}

			for (int j = digit - 1; j >= 1; j--) {
				S += T[dig[j]];
				if (cut[j - 1] == 1) {
					vec2.push_back(STOI(S));
					sum += vec2[vec2.size() - 1];
					S = "";
				}
			}
			S += T[dig[0]];
			vec2.push_back(STOI(S));
			sum += vec2[vec2.size() - 1];
			S = "";

			if (sum <= K && vec2[0] != 0) {
				vec.push_back(make_pair(sum, make(vec2)));
			}
		}
		sort(vec.begin(), vec.end(),greater<pair<long long, string>>());

		long long target;
		int sum2 = 0;

		if (vec.size() >= 1) {
			sum2 = 0;
			target = vec[0].first;
			for (int i = 0; i < vec.size(); i++) {
				if (vec[i].first == target) {
					sum2++;
				}
				else {
					break;
				}
			}
		}
		if (sum2 == 0) {
			cout << "error" << endl;
		}
		if (sum2 >= 2) {
			cout << "rejected" << endl;
		}
		if (sum2 == 1) {
			cout << vec[0].first << ' ';
			vector<long long>vec3 = kaiseki(vec[0].second);
			for (int i = 0; i < vec3.size(); i++) {
				if (i >= 1) { cout << ' '; }
				cout << vec3[i];
			}
			cout << endl;
		}

	}
	return 0;
}