#include #include #include #include using std::cin; using std::cout; using std::max; using std::min; using std::stack; using std::string; using std::vector; int main() { /*std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);*/ stack orig; stack mini; int cmd; cin >> cmd; string req; int cnt = 0; for (int go = 0; go < cmd; ++go) { cin >> req; if (req == "enqueue") { cnt++; int num; cin >> num; int tomin = num; if (!mini.empty()) { tomin = min(mini.top(), num); } orig.push(num); mini.push(tomin); cout << "ok\n"; } else if (req == "front") { if (cnt == 0) { cout << "error\n"; continue; } cout << orig.top() << "\n"; } else if (req == "clear") { while (cnt > 0) { cnt--; orig.pop(); mini.pop(); } cout << "ok\n"; } else if (req == "size") { cout << cnt << "\n"; } else if (req == "min") { if (cnt == 0) { cout << "error\n"; continue; } cout << mini.top() << "\n"; } else if (req == "dequeue") { if (cnt == 0) { cout << "error\n"; continue; } cnt--; cout << orig.top() << "\n"; orig.pop(); mini.pop(); } } }