Promblem—— C1. Increasing Subsequence (easy version) ——Codefordes

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).

You are given a sequence a consisting of n integers. All these integers are distinct, each value from 1 to n appears in the sequence exactly once.

You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the rightmost element of the sequence, write it down and remove it from the sequence. Your task is to write down a strictly increasing sequence, and among all such sequences you should take the longest (the length of the sequence is the number of elements in it).

For example, for the sequence [2,1,5,4,3] the answer is 4 (you take 2 and the sequence becomes [1,5,4,3], then you take the rightmost element 3 and the sequence becomes [1,5,4], then you take 4 and the sequence becomes [1,5] and then you take 5 and the sequence becomes [1], the obtained increasing sequence is [2,3,4,5]).

Input

The first line of the input 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

input

5
2 1 5 4 3

output

4
LRRR

input

7
1 3 5 6 7 4 2

output

7
LRLRLLL

input

3
1 2 3

output

3
LLL

input

4
1 2 4 3

output

4
LLRL

Note

The first example is described in the problem statement.

代码:

#include<iostream>
#include <ostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define dd double
#define mes(x,y) memset(x,y,sizeof(y))
using namespace std;

int main(){
	int n;
	cin>>n;
	char b[200030];
		vector<int>a;int v;
		for(int i=0;i<n;i++){
			cin>>v;
			a.push_back(v);
		}
		int l=0,r=n-1;
		int sum=0,i=0,c=0;
		while(l<=r){//判断要先看两都是不是都比刚才选的大,是,再比较大小,不是,就直接录入就行了
			if(a[l]<c&&a[r]<c)break; //如果两个都比刚才选的小那么就无法进行选择,直接出去就行
			if(a[l]<=a[r]&&a[l]>c||a[r]<c){
				c=a[l++];sum++;b[i++]='L';
			}//录入左边的,只有左边的小于右边的并且比刚才选的数大,或者右边的比刚才选的数小
			else{//同理
				c=a[r--];sum++;b[i++]='R';
			}
		}
		cout<<sum<<endl;
		for(int i=0;i<sum;i++)cout<<b[i];
		return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GUESSERR

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值