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>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//int dxy[5] = {0, 1, 0, -1, 0};
// assign

vi num, ans;
int n, ans_max;
bool rejected;
string input;

void solve(string data);

signed main()
{
    while (cin >> n >> input, n) {
        ans_max = -1;
        solve(input);
        if (rejected) {
            cout << "rejected" << endl;
        } else if (ans_max == -1 ) {
            cout << "error" << endl;
        } else {
            cout << ans_max;
            for (int i : ans) {
                cout << " " << i;
            }
            cout << endl;
        }
    }
    return 0;
}

void solve(string data)
{
    int a = 0;
    if (!data.size()) {
        int tmp = 0;
        for (int i : num) {
            tmp += i;
        }
        if (tmp > ans_max && tmp <= n) {
            rejected = false;
            ans_max = tmp;
            ans = num;
        } else if (tmp == ans_max) {
            rejected = true;
        }
        return ;
    }
    rep(i, data.length()) {
        a *= 10;
        a += data[i] - '0';
        num.eb(a);
        solve(&data[i+1]);
        num.pop_back();
    }
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int t;
  string s;
  while(cin>>t>>s && t){
    bool reject = false;
    int ans = -1;
    vector<int> ans_v;
    for(int S = 0; S < (1<<(s.size() - 1)); S++){
      int sum = 0;
      int tmp = 0;
      vector<int> tmp_v;
      REP(i, s.size()){
        tmp = tmp * 10 + (s[i] - '0');
        if(i == s.size() - 1 || (S & (1<<i))){
          tmp_v.push_back(tmp);
          sum += tmp;
          tmp = 0;
        }
      }
      if(sum > t){
      }else if(ans < sum){
        reject = false;
        ans = sum;
        ans_v = tmp_v;
      }else if(ans == sum){
        reject = true;
      }
    }
    if(reject){
      cout<<"rejected"<<endl;
    }else if(ans == -1){
      cout<<"error"<<endl;
    }else{
      cout<<ans<<" ";
      REP(i, ans_v.size()){
        cout<<ans_v[i];
        if(i == ans_v.size() - 1) cout<<endl;
        else cout<<" ";
      }
    }
  }
  return 0;
}

C++: #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;
}