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<stack>
#include<list>
#include<cstdio>

using namespace std;

class Ans{
  int minimam;
  int target;
  list<int> st;
  stack<string> ans;
  const char *str;
  void prl(){
    for(list<int>::iterator it=st.begin();it!=st.end();it++){
      printf("%d ",*it);
    }
    printf("\n");
  }

  void check(int n){
    if(n<0){
      return;
    }else if(n<=minimam){
      char buff[10];
      string s;
      sprintf(buff,"%d ",target-n);
      s=buff;
      for(list<int>::iterator it=st.begin();it!=st.end();++it){
        sprintf(buff,"%d ",*it);
        s+=buff;
      }
      if(n<minimam){
        ans=stack<string>();
      }
      ans.push(s);
      minimam=n;
    }
  }
  void answer(const char *str,int now,int dist){
    if(*str == '\0' && now!=-1) {
      st.push_back(now);
      check(dist-now);
      st.pop_back();
      return;
    }
    if(now!=-1){
      st.push_back(now);
      //cout << now << endl;
      //prl();
      answer(str,-1,dist-now);
      st.pop_back();
    }
    {
      if(now==-1) now=0;
      now=now*10+(*str - '0');
      if(now > dist) return;
      answer(str+1,now,dist);
    }
  }
public:
  Ans(int target,const char *str){
    this->target = target;
    this->str = str;
    this->minimam = 0x7FFFFFFF;
    answer(this->str,-1,this->target);
  }
  void print(){
    if(ans.size()==1){
      string s = ans.top();
      while(s[s.size()-1] == ' ') s = s.substr(0, s.size()-1);
      cout << s << endl;
    }else if(ans.size()>1){
      cout << "rejected" << endl;
    }else{
      cout << "error" << endl;
    }
  }
};

int main(){
  int n;
  string m;
  while(cin >> n >> m , !(n==0&&m=="0")){
    Ans a(n,m.c_str());
    //cout << endl;
    a.print();
    //cout << endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(b))

typedef long long ll;
typedef pair<int, int> pii;

int target;
string nums;
int n;

int sum;
vector<int> part;
bool reject;

void rec(int i, vector<int> d, int sums, int tmp) {
	//if (i != 0 && tmp == 0) return;
	
	if (i == n) {
		sums += tmp;
		d.push_back(tmp);
		/*
		cout << sums << " ";
		for_(k,0,(int)d.size()) {
			if (k < (int)d.size() - 1) cout << d[k] << " ";
			else cout << d[k] << endl;
		}
		*/
		if (target >= sums) {
			if (sums > sum) {
				reject = false;
				sum = sums;
				part = d;
			} else if (sums == sum) {
				bool flag = true;
				int psize = (int)part.size();
				int dsize = (int)d.size();
				if (psize == dsize) {
					vector<int> sp = part, sd = part;
					sort(allof(sp)); sort(allof(sd));
					for_(k,0,psize) if (sp[k] != sd[k]) flag = false;
				}
				if (flag) reject = true;
			}
		}
		return;
	}
	
	int rtmp = tmp;
	
	int add = (int)(nums[i] - '0');
	tmp = 10 * tmp + add;
	rec(i + 1, d, sums, tmp);
	
	if (i != 0) {
		tmp = rtmp;
		sums += tmp;
		d.push_back(tmp);
		tmp = add;
		rec(i + 1, d, sums, tmp);
	}
}

void solve() {
	//cout << target << " " << nums << endl;
	n = (int)nums.size();
	sum = -1;
	part.clear();
	reject = false;
	
	rec(0,vector<int>(), 0, 0);
	
	if (sum == -1) cout << "error" << endl;
	else if (reject) cout << "rejected" << endl;
	else {
		cout << sum << " ";
		int psize = (int)part.size();
		for_(i,0,psize) {
			if (i < psize - 1) cout << part[i] << " ";
			else cout << part[i] << endl;
		}
	}
}

int main() {
	while (cin >> target >> nums, target) {
		solve();
	}
	return 0;
}