#C13887. Elevator System Simulation

    ID: 43474 Type: Default 1000ms 256MiB

Elevator System Simulation

Elevator System Simulation

This problem simulates an elevator system in a building. The elevator starts at a given floor and processes a list of floor requests based on an initial direction. It first serves all valid requests in the given direction and then processes the remaining valid requests in the reverse order. A request is considered valid if it falls within the range \( [0, 10] \). If an invalid direction is provided (i.e., not 'up' or 'down'), the program must output an error message.

Your task is to implement this functionality by reading input from standard input (stdin) and printing the result to standard output (stdout).

inputFormat

The input consists of multiple lines:

  1. The first line contains an integer representing the starting floor of the elevator.
  2. The second line contains a string which is either 'up' or 'down', representing the initial moving direction of the elevator.
  3. The third line contains an integer ( n ), the number of floor requests.
  4. The fourth line contains ( n ) space-separated integers, each denoting a floor request.

outputFormat

Output the sequence of floors visited by the elevator as a space-separated list in one line. If the direction is invalid, output: Invalid direction: must be up or down.## sample

2
up
3
5 1 3
2 3 5 1