#include #include #include using Operation = std::pair; int n, idx = 0; std::stack stack; std::vector sequence; std::vector operation_log; int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cin >> n; operation_log.reserve(2 * n); sequence.resize(n); for (int i = 0; i < n; i++) { std::cin >> sequence[i]; } for (int current_num = 1; current_num <= n;) { while ((stack.empty() || stack.top() != sequence[idx]) && current_num <= n) { stack.push(current_num); operation_log.emplace_back(false, current_num); current_num++; } while (!stack.empty() && stack.top() == sequence[idx]) { stack.pop(); operation_log.emplace_back(true, sequence[idx]); idx++; } } if (!stack.empty()) { std::cout << "NO" << std::endl; } else { for (const auto [op, x] : operation_log) { std::cout << (op ? "POP " : "PUSH ") << x << std::endl; } } return 0; }