Error-proof stack#205

Error-proof stack

2 seconds
128 megabytes
Easy (≈1000)

Implement the stack data structure. Write a program that provides a description of the stack and models its operation by implementing all the methods given. The program reads sequential commands and performs the corresponding operation based on the command. After executing each command, the program should return a line. The possible commands for the program are:

Before executing back and pop commands, the program should check if there is at least one element in the stack. If the back or pop commands are given in the input and the stack is empty at that time, the program should return the line error.

Input

Described in the statement. See also the input example.

Output

Given in the statement. See also the output example.

Examples

Example 1

Loading
Loading