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 <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

ll res = INF;
vector<int> vr;
bool ok;
void dfs(int cur, vector<int> v, ll t, string &s) {
    if (cur == s.size()) {
        ll sum = 0;
        int cur = 0;
        for (auto e : v) {
            ll sm = 0;
            for (int i = 0; i < e; i++) {
                sm = sm * 10 + (s[cur] - '0');
                cur++;
            }
            sum += sm;
        }
        if (sum > t) return;
        if (chmin(res, t - sum)) {
            ok = true;
            vr = v;
        }
        else if (res == t - sum) {
            ok = false;
        }
        return;
    }
    ll sum = 0; for (auto e : v) sum += e;
    /*{
        ll all = 0;
        int cur = 0;
        for (auto e : v) {
            ll sm = 0;
            for (int i = 0; i < e; i++) {
                sm = sm * 10 + (s[cur] - '0');
                cur++;
            }
            all += sm;
        }
        if (all > t) return;
    }*/
    int cnt = 0;
    for (int i = sum; i < s.size(); i++) {
        cnt++;
        v.emplace_back(cnt);
        dfs(sum + cnt, v, t, s);
        v.pop_back();
    }
}
void solve() {
    int t;
    string s; cin >> t >> s;
    res = INF; ok = true;
    if (t == 0 and s == "0") exit(0);
    vector<int> v;
    dfs(0, v, t, s);
    if (res == INF) puts("error");
    else if (!ok) puts("rejected");
    else {
        ll sum = 0; 
        int cur = 0;
        vector<ll> v;
        for (auto e : vr) {
            ll sm = 0;
            for (int i = 0; i < e; i++) {
                sm = sm * 10 + (s[cur] - '0');
                cur++;
            }
            v.emplace_back(sm);
            sum += sm;
        }
        printf("%lld", sum);
        for (int i = 0; i < v.size(); i++) printf(" %lld", v[i]);
        puts("");
    }
}

int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */

	int kkt = 89;
	while (kkt) {
		solve();
	}
    return 0;
}

C++: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	string s;
	while (cin >> N >> s, N) {
		int num=0;
		vector<string>ans;
		int cnt = 0;
		for (int i = 0; i < 1 << (s.size() - 1); i++) {
			vector<string>box;
			int sum = 0;
			box.push_back(string(1, s[0]));
			for (int j = 0; j < s.size() - 1; j++) {
				if ((i >> j) & 1) {
					box.push_back(string(1, s[j + 1]));
				}
				else {
					box.back().push_back(s[j + 1]);
				}
			}
			for (auto j : box) {
				sum += stoi(j);
			}
			if (sum <= N && num < sum) {
				num = sum;
				ans = box;
				cnt = 1;
			}
			else if (num == sum) {
				cnt++;
			}
		}
		if (cnt == 1) {
			cout << num;
			for (auto i : ans)cout << " " << i;
			cout << endl;
		}
		else if (cnt == 0) {
			cout << "error" << endl;
		}
		else {
			cout << "rejected" << endl;
		}
	}
}

C++: #include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<numeric>

#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	vector<int>	vi;

vi cut(string num,int stat){
	int len=num.length(),bef=0;
	vi res;
	rep(i,len)if(stat&(1<<i) || i==len-1){
		res.pb(atoi(num.substr(bef,i-bef+1).c_str()));
		bef=i+1;
	}
	return res;
}

int main(){
	for(;;){
		int tar;
		char num[7];	scanf("%d%s",&tar,num);
		if(tar==0)	break;
		int len=strlen(num);

		int ans=-1;
		vi ans2;
		bool dup=false;
		rep(i,1<<(len-1)){
			vi c=cut(num,i);
			int sum=accumulate(c.begin(),c.end(),0);
			if(sum<=tar){
				if(ans<sum)	ans=sum,ans2=c,dup=false;
				else if(ans==sum)	dup=true;
			}
		}

		if(ans==-1)		puts("error");
		else if(dup)	puts("rejected");
		else{
			printf("%d",ans);
			rep(i,ans2.size())	printf(" %d",ans2[i]);
			putchar('\n');
		}
	}

	return 0;
}

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

int main()
{
  int X;
  string Y;
  while(cin >> X >> Y, X || Y != "0") {

    int ret = -1, cnt = 0;
    vector< int > ans;

    for(int i = 0; i < 1 << (Y.size() - 1); i++) {
      int now = 0, sum = 0;
      vector< int > nums;
      for(int j = 0; j < Y.size(); j++) {
        now = now * 10 + Y[j] - '0';
        if(j == Y.size() - 1 || (i >> j) & 1) {
          sum += now;
          nums.push_back(now);
          now = 0;
        }
      }
      if(sum <= X && ret <= sum) {
        if(ret == sum) ++cnt;
        else ret = sum, cnt = 1, swap(ans, nums);
      }
    }
    if(cnt == 0) cout << "error" << endl;
    else if(cnt > 1) cout << "rejected" << endl;
    else {
      cout << ret << " ";
      for(int v : ans) cout << v << " ";
      cout << endl;
    }
  }
}