put contains one integer n (1≤n≤2⋅105) — the number of elements in a.
The second line of the input contains n integers a1,a2,…,an (1≤ai≤n), where ai is the i-th element of a. All these integers are pairwise distinct.
Output
In the first line of the output print k — the maximum number of elements in a strictly increasing sequence you can obtain.
In the second line print a string s of length k, where the j-th character of this string sj should be ‘L’ if you take the leftmost element during the j-th move and ‘R’ otherwise. If there are multiple answers, you can print any.
Examples
inputCopy
5
2 1 5 4 3
outputCopy
4
LRRR
inputCopy
7
1 3 5 6 7 4 2
outputCopy
7
LRLRLLL
inputCopy
3
1 2 3
outputCopy
3
LLL
inputCopy
4
1 2 4 3
outputCopy
4
LLRL
Note
The first example is described in the problem statement.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<vector>
#define ll long long
#define dd double
using namespace std;
int main() {
ll n;
while (cin >> n) {
string s = "";
ll a[200005];
for (ll i = 0; i < n; i++) {
cin >> a[i];
}
ll i = 0;
ll j = n - 1;
ll max = -1;
if (a[i] < a[j]) {
s += 'L';
max = a[i];
i++;
}
else {
s += 'R';
max = a[j];
j--;
}
while (i < j) {
if (max < a[i] && max < a[j]) {
if (a[i] < a[j]) {
s += 'L';
max = a[i];
i++;
}
else {
s += 'R';
max = a[j];
j--;
}
}
else if (max<a[i] && max>a[j]) {
s += 'L';
max = a[i];
i++;
}
else if (max<a[j] && max>a[i]) {
max = a[j];
s += 'R';
j--;
}
else {
break;
}
}
if (i == j && max < a[i]) {
s += 'L';
}
cout << s.size() << endl << s << endl;
}
}