P7209 [COCI 2020/2021 #3] Knjige

Description

Tin thinks that books being placed out of order is the most annoying thing. Ante decides to help him. During sorting, in each step, he can do one of the following two operations: - If the corresponding hand is empty, he may take the top book from a pile and hold it in his left hand or right hand. - Put a book that he is holding onto the top of a bookshelf. Ante wants you to find a method that makes the books on the **left** bookshelf correspond, from top to bottom, to thickness from thin to thick.

Input Format

The first line contains an integer $n$, which denotes the number of books on the left bookshelf. The second line contains $n$ integers $d_i$, in order from top to bottom, describing the thickness of the books.

Output Format

The first line outputs an integer $k$, which denotes the number of operations required by your method. The next $k$ lines should be output in the format `INSTRUCTION HAND SHELF`: - `INSTRUCTION`: if Ante should take the top book from a bookshelf, output `UZMI`; if he should place a book onto the top of a bookshelf, output `STAVI`. - `HAND`: if using the left hand, output `L`, otherwise output `D` for using the right hand. - `SHELF`: if it involves the left bookshelf, output `L`, otherwise output `D` for involving the right bookshelf. Your solution does **not necessarily** need to use the minimum number of operations, but the total number of operations must not exceed $100000$. It can be proven that under the given conditions, there is always at least one valid solution.

Explanation/Hint

#### Sample 1 Explanation ![](https://cdn.luogu.com.cn/upload/image_hosting/2wyrdy5q.png) #### Constraints For $100\%$ of the testdata, $1 \le n \le 100$, $1 \le d_i \le 1000$, $0 \le k \le 10^5$. #### Notes **The score for this problem follows the original COCI settings, with a full score of $50$.** This problem uses a self-written unofficial [Special Judge](https://www.luogu.com.cn/paste/enzsg1cn). Everyone is welcome to hack it (you may PM or post directly). Note that the Special Judge is sensitive to the output format, so please do not output extra spaces at the end of each line. **Translated from [COCI2020-2021](https://hsin.hr/coci/) [CONTEST #3](https://hsin.hr/coci/contest3_tasks.pdf) _T1 Knjige_.** Translated by ChatGPT 5