Editor
题号:NC50963
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

You are going to implement the most powerful editor for integer sequences.

The sequence is empty when the editor is initialized.
There are 5 types of instructions.
  • I x Insert x after the cursor.
  • D Delete the element before the cursor.
  • L Move the cursor left unless it has already been at the begin.R Move the cursor right unless it has already been at the end.
  • Q k Suppose that the current sequence BEFORE the cursor is . Find where  

输入描述:

The input file consists of multiple test cases. For each test case:
The first line contains an integer Q, which is the number of instructions. The next Q lines contain an instruction asdescribed above.
(, for I instruction, . for Q instruction)


输出描述:

For each Q instruction, output the desired value.
示例1

输入

复制
8
I 2
I -1
I 1
Q 3
L
D
R
Q 2

输出

复制
2
3

说明

The following diagram shows the status of sequence after each instruction:

C464-1004-2.jpg

备注: