#K81227. Employee Check-out Simulation

    ID: 35707 Type: Default 1000ms 256MiB

Employee Check-out Simulation

Employee Check-out Simulation

In this problem, you are given a sequence of events representing employee check-ins and check-outs. Each positive integer (from 1 to 100) corresponds to an employee checking in with that ID, while a 0 indicates a check-out event. Upon encountering a check-out, the employee who most recently checked in (and has not yet checked out) is removed from the check-in list.

This process is analogous to operating a Last-In-First-Out (LIFO) stack, where a check-in corresponds to a push and a check-out corresponds to a pop operation. If a check-out event occurs when no employee is available to check out, no action is taken.

Your program should read input from standard input (stdin) and produce output to standard output (stdout) following the described simulation.

inputFormat

The first line of input contains an integer (n) representing the number of events. The second line contains (n) space-separated integers. Each positive integer represents an employee's check-in ID, while 0 indicates a check-out event.

outputFormat

Output the employee IDs in the order they checked out, separated by a space. If no employees have checked out, output an empty line.## sample

10
4 7 0 9 0 4 5 0 0 0
7 9 5 4 4