#include #include #include #include std::stack input(std::string x) { std::stack in; for(int i = 0; i < x.length();) { if (x[i] == ' ') { i++; continue; } int k = x[i] - 48; i++; while (x[i] != ' ' && i != x.length()) { k = k * 10 + x[i] - 48; i++; } in.push(k); } return in; } int main() { std::string x, y; std::getline(std::cin, x); std::getline(std::cin, y); std::stack a = input(x), b = input(y); int k = 0; std::vector sort; int const total = a.size() + b.size(); while (k != total) { if (a.top() > b.top()) { std::cout << 'B'; sort.push_back(b.top()); if (b.size() != 1) { b.pop(); } else { std::cout << 'A'; sort.push_back(a.top()); k++; } } else { std::cout << 'A'; sort.push_back(a.top()); if (a.size() != 1) { a.pop(); } else { std::cout << 'B'; k++; sort.push_back(b.top()); } } k++; } std::cout << std::endl; for (auto x : sort) { std::cout << x << " "; } }