
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int main(void)
{
	int t;
	string nn;
	for (;;)
	{
		cin >> t >> nn;
		if (!t)break;
		int cal = -1;
		string output = "error";
		for (int f = 0; f < (1 << (nn.size() - 1)); ++f)
		{
			string n = nn;
			int sum = 0;
			vector<string>cash;
			int las = 0, put = 0;
			for (int i = 1; i < nn.size(); ++i)
			{
				++put;
				if (f & (1 << (i - 1)))
				{
					string m = n.substr(0, put);
					for (int k = 0; k < put; ++k)n.erase(n.begin());
					put = 0;
					las = i;
					sum += stoi(m);
					cash.push_back(m);
				}
			}
			if (!n.empty())
			{
				sum += stoi(n);
				cash.push_back(n);
			}
			if (sum <= t)
			{
				if (cal < sum)
				{
					cal = sum;
					output.clear();
					stringstream ss;
					ss << cal;
					ss >> output;
					for (string elm : cash)
					{
						output.append(" "+elm);
					}
				}
				else if (cal == sum)
				{
					output = "rejected";
				}
			}
		}
		cout << output << endl;
	}
	return 0;
}