PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000012. Dãy con tăng - bản dễ (Increasing Subsequence - Easy Version)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Dãy con tăng - bản dễ (Increasing Subsequence - Easy Version)

Increasing Subsequence (Easy Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of nn pairwise distinct positive integers, containing every value from 11 to nn exactly once. In each move, take either the leftmost or the rightmost element of the current sequence, append its value to the result, and remove it from the original sequence.

The selected values must form a strictly increasing sequence: each new value must be greater than the preceding one. You may stop at any moment. Maximize the number of moves and output a sequence of moves achieving this maximum.

Input

  • The first line contains an integer nn, the initial sequence length.
  • The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n from left to right.

Output

  • Print the maximum number kk of moves on the first line.
  • Print a string of exactly kk characters on the second line: L for a left-end move and R for a right-end move. Any optimal string is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 2 (30 points): 1≤n≤50001\le n\le 5000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.
  • Subtask 3 (50 points): 1≤n≤2⋅1051\le n\le 2\cdot10^5; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n; aa is a permutation of 1,2,…,n1,2,\ldots,n.

Examples

Input

5
2 1 5 4 3

Output

4
LRRR

Explanation

Take left 2, then right 3, right 4, and right 5, obtaining the strictly increasing sequence 2,3,4,5. The remaining 1 cannot be appended.