#P2952. Farmer John's Line Simulation
Farmer John's Line Simulation
Farmer John's Line Simulation
Farmer John's cows are lining up in a specific order. Initially, no cow is in line. Each cow enters the line sequentially (with labels 1, 2, 3, …) and joins either the left or right end. Occasionally, a number of cows leave the line from either the left or right end. Note that once a cow leaves the line, she will never re-enter.
You will be given S operations. Each operation is one of the following two types:
enter L
orenter R
: A cow enters the line from the left or right end, respectively.leave L k
orleave R k
: k cows leave the line from the left or right end, respectively.
The cows always enter in numerical order starting with 1, and the input is guaranteed such that every operation is valid (i.e. there is never an attempt to remove more cows than present). After processing all S operations, output the remaining cows in the line from left to right.
Mathematically, if we denote the number of operations by \(S\) with \(1 \le S \le 100000\), then the operations can be expressed in LaTeX as follows:
[ \text{Operation } i: \quad \begin{cases} \text{enter from left: } & \text{if } op_i = \text{enter L}, \ \text{enter from right: } & \text{if } op_i = \text{enter R}, \ \text{remove } k \text{ cows from left: } & \text{if } op_i = \text{leave L } k, \ \text{remove } k \text{ cows from right: } & \text{if } op_i = \text{leave R } k. \end{cases} ]
inputFormat
The first line contains an integer S \( (1 \le S \le 100000) \) representing the number of operations. Each of the following S lines contains an operation in one of the following formats:
enter L
orenter R
leave L k
orleave R k
, where k is a positive integer.
It is guaranteed that every operation is valid and that at least one cow remains in the line at the end.
outputFormat
Output a single line containing the labels of the remaining cows in the line from left to right, separated by a single space.
sample
5
enter L
enter R
enter L
leave L 1
enter R
1 2 4