#P7209. [COCI 2020/2021 #3] Knjige

[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 nn, which denotes the number of books on the left bookshelf.

The second line contains nn integers did_i, in order from top to bottom, describing the thickness of the books.

Output Format

The first line outputs an integer kk, which denotes the number of operations required by your method.

The next kk 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 100000100000. It can be proven that under the given conditions, there is always at least one valid solution.

3
2 3 1
8
UZMI L L
STAVI L D
UZMI L L
UZMI D L
STAVI L L
UZMI L D
STAVI L L
STAVI D L
4
1 1 2 5
0

Hint

Sample 1 Explanation

Constraints

For 100%100\% of the testdata, 1n1001 \le n \le 100, 1di10001 \le d_i \le 1000, 0k1050 \le k \le 10^5.

Notes

The score for this problem follows the original COCI settings, with a full score of 5050.

This problem uses a self-written unofficial Special Judge. 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 CONTEST #3 T1 Knjige.

Translated by ChatGPT 5