import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 int n = in.nextInt(); String line; in.nextLine(); MyStack myStack = new MyStack(); for (int l = 0; l < n; l++) { line = in.nextLine(); String[] opt = line.split(" "); if (opt[0].equals("push")) { myStack.push(Integer.valueOf(opt[1])); } else if (opt[0].equals("pop")) { try { System.out.println(myStack.pop()); } catch (Exception e) { System.out.println("error"); } } else if (opt[0].equals("top")) { try { System.out.println(myStack.peek()); } catch (Exception e) { System.out.println("error"); } } } } } class MyStack { LinkedList<Integer> list; public MyStack() { this.list = new LinkedList<>(); } public void push(int num) { list.add(num); } public int peek() { return list.get(list.size() - 1); } public int pop() { int res = list.get(list.size() - 1); list.remove(list.size() - 1); return res; } }