题目描述
Problem Description
There is a sequence $ A $ which is initially empty. You are given a string $ S $ of length $ N $ consisting of the characters A, B, C, D, E, F, L, R.
Let $ S_i $ denote the $ i $-th character of $ S $.
For each $i = 1, 2, 3, \dots, N$, perform the following operations in this order:
- If $ S_i $ is
L: Insert $ i $ at the beginning of $ A $. - If $ S_i $ is
R: Insert $ i $ at the end of $ A $. - If $ S_i $ is
A: If the length of $ A $ is $ 0 $ or less, outputERROR. Otherwise, output and remove the first number from $ A $. - If $ S_i $ is
B: If the length of $ A $ is $ 1 $ or less, outputERROR. Otherwise, output and remove the second number from the front of $ A $. - If $ S_i $ is
C: If the length of $ A $ is $ 2 $ or less, outputERROR. Otherwise, output and remove the third number from the front of $ A $. - If $ S_i $ is
D: If the length of $ A $ is $ 0 $ or less, outputERROR. Otherwise, output and remove the last number from $ A $. - If $ S_i $ is
E: If the length of $ A $ is $ 1 $ or less, outputERROR. Otherwise, output and remove the second last number from $ A $. - If $ S_i $ is
F: If the length of $ A $ is $ 2 $ or less, outputERROR. Otherwise, output and remove the third last number from $ A $.
Input Format
The input is given from the standard input in the following format:
$ N $ $ S $
Output Format
Output according to the instructions in the problem statement, separated by newlines.
Sample Input and Output
Sample Input #1
11
LLRLRCDEFBA
Sample Output #1
1
5
2
ERROR
3
4
Sample Input #2
36
RLLDBBDDLCLDFRLRRLRRFLRDRLALLELCAARF
Sample Output #2
1
2
ERROR
3
ERROR
ERROR
9
ERROR
17
23
26
20
28
31
29
19
Notes/Hints
Constraints
- $1 \leq N \leq 3 \times 10^5$
- $ S $ is a string of length $ N $ consisting of the characters
A,B,C,D,E,F,L,R.
Sample Explanation 1
The operations are performed as follows:
- $ S_1 $ is L, so insert $ 1 $ at the beginning. $ A = (1) $.
- $ S_2 $ is L, so insert $ 2 $ at the beginning. $ A = (2, 1) $.
- $ S_3 $ is R, so insert $ 3 $ at the end. $ A = (2, 1, 3) $.
- $ S_4 $ is L, so insert $ 4 $ at the beginning. $ A = (4, 2, 1, 3) $.
- $ S_5 $ is R, so insert $ 5 $ at the end. $ A = (4, 2, 1, 3, 5) $.
- $ S_6 $ is C, so output and remove the third number from the front, which is $ 1 $. $ A = (4, 2, 3, 5) $.
- $ S_7 $ is D, so output and remove the last number, which is $ 5 $. $ A = (4, 2, 3) $.
- $ S_8 $ is E, so output and remove the second last number, which is $ 2 $. $ A = (4, 3) $.
- $ S_9 $ is F, but the length is $ 2 $ or less, so output ERROR.
- $ S_{10} $ is B, so output and remove the second number from the front, which is $ 3 $. $ A = (4) $.
- $ S_{11} $ is A, so output and remove the first number, which is $ 4 $. $ A = () $.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分