#include #include #include #include using namespace std; int TABLE[10][10]; int ToInt(const string& s) { int res; istringstream(s) >> res; if (s[0] == '0' && s.size() > 1){ //res = -1; } //cerr << s << " " << res << endl; return res; } int Calc(int flag, int size) { int res = 0; int last_index = 0; //cerr << " " << flag; for (int i = 0; i < size; ++i){ if (flag & (1 << i)){ int index = i + 1; if (TABLE[last_index][index] < 0){ res -= 1000000; } //cerr << " " << TABLE[last_index][index]; res += TABLE[last_index][index]; last_index = index; } } if (TABLE[last_index][size] < 0){ res -= 1000000; } //cerr << " " << TABLE[last_index][size]; res += TABLE[last_index][size]; //cerr << " " << res << endl; return res; } main() { int t; string num; while (cin >> t >> num && !(t == 0 && num == "0")){ memset(TABLE, 0, sizeof(TABLE)); for (int begin = 0; begin < (int)num.size(); ++begin){ for (int end = begin + 1; end <= (int)num.size(); ++end){ TABLE[begin][end] =ToInt(num.substr(begin, end - begin)); } } int size = num.size() - 1; int sum = -1; int answer = -1; bool is_reject = false; for (int flag = 0; flag < (1 << size); ++flag){ int temp = Calc(flag, size + 1); if (temp < 0){ continue; } //cerr << " " << flag << " " << temp << endl; if (sum < temp && temp <= t){ sum = temp; answer = flag; is_reject = false; } else if (sum == temp){ is_reject = true; } } if (sum == -1){ cout << "error" << endl; } else if (is_reject){ cout << "rejected" << endl; } else { cout << sum; int last_index = 0; for (int i = 0; i < (int)num.size(); ++i){ if (answer & (1 << i)){ int index = i + 1; cout << " " << TABLE[last_index][index]; last_index = index; } } cout << " " << TABLE[last_index][num.size()] << endl; } } }