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 <cstdio>
#include <vector>
#include <cmath>

using namespace std;

int t, n, sum;
vector<int> ans;
bool r = false;

void dfs(vector<int> v,int n, int d) {
    if (d == 0) {
        int s = 0;
        for (int i = 0; i < v.size(); i++) s += v[i];
        //for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << sum << " " << s << endl;
        if (s <= t && s > sum) {
            sum = s;
            ans = v;
            r = false;
        }
        else if (s <= t && s == sum) {
            r = true;
        }
        return;
    }
    
    while (1) {
        int a = n / d;
        int b = n % d;
        //printf("n=%d d=%d a=%d b=%d\n",n,d,a,b);
        vector<int> _v = v;
        _v.push_back(a);
        d /= 10;
        dfs(_v, b, d);
        if (d == 0) break;
    }
}

int main(void){
    while (cin>>t>>n && t && n) {
        sum = -1;;
        vector<int> a;
        int d = 1;
        while (n >= d*10) d *= 10; 
        dfs(a, n, d);
        
        if (r) cout << "rejected" << endl;
        else if (sum == -1) cout << "error" << endl;
        else {
            cout << sum;
            for (int i = 0; i < ans.size(); i++) cout << " " << ans[i];
            cout << endl;
        }
    }
}

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

typedef vector<int> vec;
typedef vector<vec> mat;

const int INF = 1 << 28;
int sum;
string num;

int main() {
    while (cin >> sum >> num, sum || num != "0") {
        map<int,vec> m;
        int target = -1;
        for (int i = 0; i < 1 << (num.size() - 1); i++) {
            int tmp = 0;
            int pre = 0;
            for (int j = 0; j < num.size() - 1; j++) {
                if (i & (1 << j)) {
                    string s = string(num.begin() + pre, num.begin() + j + 1);
                    if (s[0] == '0' && s.size() > 1) continue;
                    stringstream ss; ss << s;
                    int n; ss >> n;
                    tmp += n;
                    pre = j + 1;
                }
            }

            string s = string(num.begin() + pre, num.end());
            stringstream ss; ss << s;
            int n; ss >> n;
            tmp += n;

            if (tmp <= sum) {
                m[tmp].push_back(i);
                target = max(target, tmp);
            }
        }

        if (m.size() == 0) {
            cout << "error" << endl;
        } else if (m[target].size() == 1) {
            cout << target << " ";
            int tmp = m[target][0];
            for (int i = 0; i < num.size(); i++) {
                cout << num[i];
                if (tmp & (1 << i)) cout << " ";
            }
            cout << endl;
        } else {
            cout << "reject" << endl;
        }
    }
}

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

int main() {

  while( true ) {

    long long int n;
    string t;
    cin >> n >> t;
    if ( n == 0 ) break;

    vector< pair< long long int, vector< long long int > > > v;

    for ( long long int i = 0; i < ( 1 << ( t.size() - 1 ) ); i++ ) {

      long long int s = 0;
      vector< long long int > p;


      long long int x = t[0] - '0';
      long long int bit = 1;
      for ( long long int j = 1; j < t.size(); j++ ) {
	if ( ( i & bit ) != 0 ) {
	  s += x;
	  p.push_back( x );
	  x = 0;
	}
	x = x * 10 + t[j] - '0';
	bit *= 2;
      }
      s += x;
      p.push_back( x );


      if ( s <= n ) {
	v.push_back( make_pair( s, p ) );
      }

    }

    sort( v.begin(), v.end() );
    if ( v.size() == 0 ) {
      cout << "error" << endl;
    }else if ( v.size() > 1 && ( v[ v.size() - 1 ].first == v[ v.size() - 2 ].first ) ) {
      cout << "rejected" << endl;
    }else {
      cout << v[ v.size() - 1 ].first;
      for ( long long int i = 0; i < v[ v.size() - 1 ].second.size(); i++ ) {
	cout << " " << v[ v.size() - 1 ].second[i];
      }
      cout << endl;
    }

  }

  return 0;

}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <cmath>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
typedef pair<int, int> PII;

int S;
string N;

int ans=-1;
vector<int> ans_list;
bool ng;

void init()
{
    ans = -1;
    ans_list.resize(0);
    ng = false;
}

void solve(int sum, int k, vector<int> list)
{
    if (sum > S) return;
    if (N[k] == '0') return;

    if (k == N.size()) { 
        if (sum > ans) {
            ans = sum;
            ans_list = list;
            ng = false;
        } else if (sum == ans) {
            ng = true;
        }
        return;
    }
    
    int n = 0;
    for (int i=0; k+i<N.size(); i++) {
        n *= 10;
        n += N[k+i] - '0';
        
        list.push_back(n);
        solve(sum+n, k+i+1, list);
        list.erase(list.end()-1);
    }
}

int main()
{
    while (cin>>S>>N, S) {
        init();
        
        solve(0, 0, vector<int>());
        
        if (ans == -1) cout << "error" << endl;
        else if (ng) cout << "rejected" << endl;
        else {
            cout << ans << " ";
            for (int i=0; i<ans_list.size(); i++) {
                if (i>0) cout << " ";
                cout << ans_list[i];
            }
            cout << endl;
        }
    }
}