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 <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void init();
void last();

void init() {

}

int sum(string n) {
    int res = 0;
    for (char c : n) res += (c - '0');
    return res;
}
int sum(const vector<int> &v) {
    int res = 0;
    for (int e : v) res += e;
    return res;
}

int anssum = 0;
vector<int> ans;
bool rejected = false;
void dfs(const int &n, const string &m, int idx, vector<int> nowvec) {
    if (idx == m.length()) {
        const int vsum = sum(nowvec);
        if (vsum <= n && abs(vsum - n) < abs(n - anssum)) {
            anssum = vsum;
            ans = nowvec;
            return;
        }
    }
    for (int i = idx + 1; i <= m.length(); i++) {
        int buf = 0;
        for (int j = idx; j < i; j++) {
            buf = buf * 10 + m[j] - '0';
        }
        nowvec.emplace_back(buf);
        dfs(n, m, i, nowvec);
        nowvec.pop_back();
    }
    return;
}
void dfs2(const int &n, const string &m, int idx, vector<int> nowvec) {
    if (idx == m.length()) {
        const int vsum = sum(nowvec);
        rejected |= ((vsum == anssum) && (ans != nowvec));
    }
    for (int i = idx + 1; i <= m.length(); i++) {
        int buf = 0;
        for (int j = idx; j < i; j++) {
            buf = buf * 10 + m[j] - '0';
        }
        nowvec.emplace_back(buf);
        dfs2(n, m, i, nowvec);
        nowvec.pop_back();
    }
    return;
}

void solve(int n, string m) {
    if (n < sum(m)) {
        puts("error");
        return;
    }
    if (stoi(m) == n) {
        printf("%d %d\n", n, n);
        return;
    }
    dfs(n, m, 0, vector<int>());
    dfs2(n, m, 0, vector<int>());
    if (rejected) {
        puts("rejected");
        return;
    }
    printf("%d ", accumulate(begin(ans), end(ans), 0));
    for (int i = 0; i < ans.size(); i++) {
        printf("%d%c", ans[i], (i + 1 == ans.size() ? '\n' : ' '));
    }

}

void refresh() {
    rejected = false;
    anssum = 0;
    ans.clear();
}

void last() {
    exit(0);
}

int main(void) {
	int a, b, c, x, y, z, n, m, p, k;
	string s;
	while (cin >> n >> s, n) {
		solve(n, s);
        refresh();
	}
    last();
}

C++: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int t;
string s;
vector<vi> vvi;

void dfs(int pnt, vi v) {
	if(pnt == s.size()) {
		vvi.pb(v);
		return;
	}
	else {
		string s2 = "";
		FOR(i, pnt, s.size()) {
			vi v2 = v;
			if(i > s.size())
				break;
			s2 += s[i];
			v2.pb(stoi(s2));
			dfs(i + 1, v2);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	while(cin >> t, t) {
		vvi.clear();
		cin >> s;
		dfs(0, vi());
		int max = 0, pnt = -1;
		bool flg = false;
		REP(i, vvi.size()) {
			int sum = 0;
			REP(j, vvi[i].size())
				sum += vvi[i][j];
			if(sum <= t && sum > max) {
				max = sum; pnt = i;
				flg = false;
			}
			else if(sum == max)
				flg = true;
		}
		if(flg)
			cout << "rejected" << endl;
		else if(pnt == -1)
			cout << "error" << endl;
		else {
			cout << max << ' ';
			REP(i, vvi[pnt].size())
				cout << vvi[pnt][i] << ' ';
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

template<typename T>
string toString(const T& x) {
  ostringstream os; os << x; return os.str();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int t, n;
  while (cin >> t >> n, t) {
    string s = toString(n);
    int sz = s.size();
    map<int, vector<int>> mp;
    for (int i = 0; i < 1 << (sz - 1); i++) {
      int l = 0, r = 0, sub = 0;
      while (l < sz - 1) {
        while (r < sz - 1 && (i >> r & 1) == 0) r++;
        sub += atoi(s.substr(l, r - l + 1).c_str());
        l = ++r;
      }
      if (l < sz) sub += atoi(s.substr(l, r - l + 1).c_str());
      mp[sub].emplace_back(i);
    }
    
    int ans = -1;
    for (auto& i : mp) {
      if (i.first > t) continue;
      ans = max(ans, i.first);
    }

    if (ans < 0) {
      cout << "error" << endl;
    } else if (mp[ans].size() > 1) {
      cout << "rejected" << endl;
    } else {
      cout << ans;
      int l = 0, r = 0;
      while (l < sz - 1) {
        while (r < sz - 1 && (mp[ans][0] >> r & 1) == 0) r++;
        cout << " " << s.substr(l, r - l + 1);
        l = ++r;
      }
      if (l < sz) cout << " " << s.substr(l, r - l + 1);
      cout << endl;
    }
  }

  return 0;
}