#K75527. Elevator Simulation

    ID: 34439 Type: Default 1000ms 256MiB

Elevator Simulation

Elevator Simulation

You are given a building with N floors, numbered from 1 to N, and a sequence of Q elevator requests. Each request is in one of the following two forms:

  • R x y: Representing a ride request where the elevator is dispatched from floor x to floor y. When processing this request, the elevator will first go to floor x and then to floor y.
  • C z: Representing a call request, where the elevator is called to floor z.

Your task is to simulate the elevator system. The elevator starts at floor 1. For each request, record the floors visited in the order they occur. Finally, output the entire sequence of floors visited by the elevator.

Note: There is no intermediate movement simulation – simply output the floor values as they are requested.

Examples:

Input:
5 5
R 1 3
R 3 5
C 2
R 2 4
R 4 1

Output: 1 3 3 5 2 2 4 4 1

Input: 4 3 C 2 C 4 C 1

Output: 2 4 1

</p>

inputFormat

The first line contains two integers N and Q, representing the number of floors and the number of requests respectively.

The next Q lines each contain a request in one of two formats:

  • R x y – a ride request from floor x to floor y.
  • C z – a call request to floor z.

It is guaranteed that all floors mentioned are valid (i.e. between 1 and N).

outputFormat

Output a single line containing the sequence of floors visited, separated by a single space.

## sample
5 5
R 1 3
R 3 5
C 2
R 2 4
R 4 1
1 3 3 5 2 2 4 4 1