A robot resides in a linear field, where positions are from left to right labelled as \(0, 1, 2, \dots, C-1, C\).
The robot may accept an integer \(k\) as command. Suppose the robot is at position \(x\). Its reponse will be moving \(k\) units rightwards as long as it stays within \([0, C]\). Note that \(k\) may be negative, meaning that the robot will move \(|k|\) units leftwards. The final position is described as \(x' = \max(0, \min(C, x + k))\).
The central computer stores an operation sequence \(\{y_1, y_2, \dots, y_N\}\), on which the robot will execute sequentially. Irotas, the researcher, may also insert a new command to the sequence, or remove a command from it. Meanwhile, you need to answer Irotas's question every time she asked so: where will the robot eventually be if she initially places the robot at \(x_0\)?
Formally speaking, let \(N\) denote the length of the operation sequence at any time. You are asked to support the following actions:
- Irotas inserted a new command \(y_{new}\) into the operation sequence, right before \(y_k\) (\(k \in [1, N + 1]\)). If \(k=N+1\), the command is inserted at the end of the sequence.
- Irotas removed \(y_k\) from the operation sequence (\(k \in [1, N]\)).
- Irotas gives you \(x_0\) as the initial position and queries the eventual position.