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 \le n \le 2 \cdot 10^5$) — the number of elements in $a$.

The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ 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 $s_j$ 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.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms


Solutions:
n = int(input())
sl = list(map(int, input().split()))
ans = ''
current = 0
for i in range(n):
	if current < sl[0] and current < sl[-1]:
		if sl[0] == sl[-1] and i != n - 1:
			(l, r) = (1, 1)
			for j in range(len(sl)):
				if sl[j] < sl[j + 1]:
					l += 1
				else:
					break
			for j in range(len(sl)):
				if sl[-(j + 1)] < sl[-(j + 2)]:
					r += 1
				else:
					break
			if l > r:
				ans += 'L' * l
			else:
				ans += 'R' * r
			break
		elif current < sl[0] and sl[0] <= sl[-1]:
			ans += 'L'
			current = sl.pop(0)
		elif current < sl[-1] and sl[0] > sl[-1]:
			ans += 'R'
			current = sl.pop()
	elif current < sl[0] and current >= sl[-1]:
		ans += 'L'
		current = sl.pop(0)
	elif current >= sl[0] and current < sl[-1]:
		ans += 'R'
		current = sl.pop()
	else:
		break
print(len(ans))
print(ans)


n = int(input())
p = input().rstrip().split(' ')
i = 0
j = len(p) - 1
l = []
w = []
T = min(int(p[0]), int(p[len(p) - 1]))
if T == int(p[0]):
	l.append(int(p[0]))
	w.append('L')
	i += 1
elif int(p[len(p) - 1]):
	l.append(int(p[len(p) - 1]))
	w.append('R')
	j -= 1
while i < j:
	if int(p[i]) > int(l[len(l) - 1]) and int(p[i]) < int(p[j]):
		l.append(int(p[i]))
		w.append('L')
		i += 1
	elif int(p[j]) > int(l[len(l) - 1]) and int(p[j]) < int(p[i]):
		l.append(int(p[j]))
		w.append('R')
		j -= 1
	elif int(p[i]) > int(l[len(l) - 1]):
		l.append(int(p[i]))
		w.append('L')
		i += 1
	elif int(p[j]) > int(l[len(l) - 1]):
		l.append(int(p[j]))
		w.append('R')
		j -= 1
	else:
		break
if len(w) == n - 1:
	if int(p[i]) > int(l[len(l) - 1]):
		w.append('R')
print(len(w))
print(''.join(w))


n = input()
n = int(n)
array = input()
array = [int(x) for x in array.split(' ')]
maximum = 0
output = ''
left = 0
right = len(array) - 1
while left <= right:
	if array[left] > maximum and array[right] > maximum:
		if array[left] <= array[right]:
			maximum = array[left]
			output += 'L'
			left += 1
		else:
			maximum = array[right]
			output += 'R'
			right -= 1
	elif array[left] > maximum:
		maximum = array[left]
		output += 'L'
		left += 1
	elif array[right] > maximum:
		maximum = array[right]
		output += 'R'
		right -= 1
	else:
		break
print(len(output))
print(output)


def process_sequence(numbers):
	s = numbers
	result = ''
	last = -1
	l = 0
	r = len(s) - 1
	while l <= r:
		leftmost = s[l]
		rightmost = s[r]
		if leftmost < last and rightmost < last:
			break
		if leftmost <= rightmost:
			if leftmost > last:
				result += 'L'
				last = leftmost
				l += 1
			elif rightmost > last:
				result += 'R'
				last = rightmost
				r -= 1
		elif leftmost > rightmost:
			if rightmost > last:
				result += 'R'
				last = rightmost
				r -= 1
			elif leftmost > last:
				result += 'L'
				last = leftmost
				l += 1
	return result

def main():
	n = int(input())
	sequence = list(map(int, input().split()))
	result = process_sequence(sequence)
	print(len(result))
	print(result)
main()


from sys import stdin, stdout, maxsize
import math
from copy import deepcopy
from collections import defaultdict
import heapq
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
sequence = [0]
moves = []
i = 0
j = n - 1
while i != j:
	if arr[i] > arr[j]:
		if arr[j] > sequence[-1]:
			sequence.append(arr[j])
			j -= 1
			moves.append('R')
		elif arr[i] > sequence[-1]:
			sequence.append(arr[i])
			i += 1
			moves.append('L')
		else:
			break
	elif arr[i] > sequence[-1]:
		sequence.append(arr[i])
		i += 1
		moves.append('L')
	elif arr[j] > sequence[-1]:
		sequence.append(arr[j])
		j -= 1
		moves.append('R')
	else:
		break
if i == j:
	if arr[i] > sequence[-1]:
		sequence.append(arr[i])
		moves.append('R')
print(len(sequence) - 1)
for i in moves:
	print(i, end='')


from collections import deque
n = int(input())
a = deque((int(x) for x in input().split()))
ans = []
temp = 0
while a:
	if a[0] > temp:
		if a[-1] > temp and a[-1] < a[0]:
			ans.append('R')
			temp = a[-1]
			a.pop()
		else:
			ans.append('L')
			temp = a[0]
			a.popleft()
	elif a[-1] > temp:
		ans.append('R')
		temp = a[-1]
		a.pop()
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = [int(i) for i in input().split()]
(i, j, b, z, s, s1, s2, b1) = (0, n - 1, 0, 10 ** 6, '', '', '', 0)
while i <= j:
	if a[i] <= b and a[j] <= b:
		break
	if a[i] == z and a[j] == z:
		break
	if a[i] == a[j]:
		b1 = b
		while i <= n - 1:
			if a[i] > b1:
				b1 = a[i]
				s1 += 'L'
				i += 1
			else:
				break
		b1 = b
		while j >= 0:
			if a[j] > b1:
				b1 = a[j]
				s2 += 'R'
				j -= 1
			else:
				break
		s += s1 if len(s1) > len(s2) else s2
		break
	if a[i] > a[j]:
		if a[j] > b:
			b = a[j]
			j -= 1
			s += 'R'
		else:
			a[j] = z
	if a[j] > a[i]:
		if a[i] > b:
			b = a[i]
			i += 1
			s += 'L'
		else:
			a[i] = z
print(len(s))
print(s)


from __future__ import division, print_function
import itertools, os, sys, threading
import os
import sys
from io import BytesIO, IOBase

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p1
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def sub(ll, rr, s, x):
	while ll != rr:
		if l[ll] == l[rr] and l[ll] > x:
			(a, b) = (0, 0)
			xx = x
			for i in range(ll, n):
				if l[i] > x:
					x = l[i]
					a += 1
				else:
					break
			x = xx
			for i in range(rr, -1, -1):
				if l[i] > x:
					x = l[i]
					b += 1
				else:
					break
			if a > b:
				s += ['L'] * a
			else:
				s += ['R'] * b
			break
		elif l[ll] < l[rr] and l[ll] > x:
			s.append('L')
			x = l[ll]
			ll += 1
		elif l[rr] > x:
			s.append('R')
			x = l[rr]
			rr -= 1
		elif l[ll] > x:
			s.append('L')
			x = l[ll]
			ll += 1
		else:
			break
	if ll == rr:
		if l[ll] > x:
			s.append('R')
	print(len(s))
	print(''.join(s))
n = ii()
l = li()
ls = []
ns = []

def main():
	s = []
	(ll, rr) = (0, n - 1)
	x = 0
	sub(ll, rr, s, x)
main()


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
LIST = [1] * n
LIST_INV = [1] * n
for i in range(n - 2, -1, -1):
	if A[i] < A[i + 1]:
		LIST[i] = LIST[i + 1] + 1
for i in range(1, n):
	if A[i] < A[i - 1]:
		LIST_INV[i] = LIST_INV[i - 1] + 1
ANS = []
SCORE = 0
i = 0
j = n - 1
while True:
	if i == j and A[i] > SCORE:
		ANS.append('R')
		SCORE = A[i]
		break
	if A[i] > A[j] and A[j] > SCORE:
		ANS.append('R')
		SCORE = A[j]
		j -= 1
	elif A[i] < A[j] and A[i] > SCORE:
		ANS.append('L')
		SCORE = A[i]
		i += 1
	elif A[i] > A[j] and A[j] <= SCORE and (A[i] > SCORE):
		ANS.append('L')
		SCORE = A[i]
		i += 1
	elif A[i] < A[j] and A[i] <= SCORE and (A[j] > SCORE):
		ANS.append('R')
		SCORE = A[j]
		j -= 1
	elif A[i] == A[j] and A[i] > SCORE:
		if LIST[i] > LIST_INV[j]:
			ANS.append('L')
			SCORE = A[i]
			i += 1
		else:
			ANS.append('R')
			SCORE = A[j]
			j -= 1
	else:
		break
print(len(ANS))
print(''.join(ANS))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = deque(list(map(int, input().split())))
	cur = 0
	ans = [''] * n
	v = 0
	while a:
		mi = min(a[0], a[-1])
		if max(a[0], a[-1]) < cur:
			break
		if mi == a[0] and mi >= cur:
			cur = a.popleft()
			ans[v] = 'L'
			v += 1
		elif mi == a[0]:
			cur = a.pop()
			ans[v] = 'R'
			v += 1
		elif mi == a[-1] and mi >= cur:
			cur = a.pop()
			ans[v] = 'R'
			v += 1
		else:
			cur = a.popleft()
			ans[v] = 'L'
			v += 1
	print(v)
	print(*ans, sep='')


l = int(input())
arr = list(map(int, input().split()))
a = 0
ans = []
leg = 0
ri = -1
le = 0
for time in range(l):
	if len(arr) >= le - ri:
		if arr[le] > a:
			if arr[ri] > a:
				if arr[ri] > arr[le]:
					a = arr[le]
					leg += 1
					ans.append('L')
					le += 1
				else:
					a = arr[ri]
					leg += 1
					ans.append('R')
					ri -= 1
			else:
				a = arr[le]
				leg += 1
				ans.append('L')
				le += 1
		elif arr[ri] > a:
			a = arr[ri]
			leg += 1
			ans.append('R')
			ri -= 1
		else:
			break
	else:
		break
print(leg)
print(''.join((n for n in ans)))


def fun(a, n):
	ans = ''
	last = -1
	(l, r) = (0, n - 1)
	while l <= r:
		if a[l] < a[r] and a[l] > last:
			ans += 'L'
			last = a[l]
			l += 1
		elif a[r] < a[l] and a[r] > last:
			ans += 'R'
			last = a[r]
			r -= 1
		elif a[r] > last:
			ans += 'R'
			last = a[r]
			r -= 1
		elif a[l] > last:
			ans += 'L'
			last = a[l]
			l += 1
		else:
			break
	print(len(ans))
	print(ans)
n = int(input())
a = list(map(int, input().split()))
fun(a, n)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
li = listIn()
ans = [-1]
res = ''
(i, j) = (0, n - 1)
while n > 0:
	(f, b) = (li[i], li[j])
	c = 0
	if f > ans[-1]:
		c += 1
	if b > ans[-1]:
		c += 1
	if c > 0:
		if f > b:
			if b > ans[-1]:
				n -= 1
				ans.append(li[j])
				res += 'R'
				j -= 1
			elif f > ans[-1]:
				n -= 1
				ans.append(li[i])
				res += 'L'
				i += 1
			else:
				break
		elif f > ans[-1]:
			n -= 1
			ans.append(li[i])
			i += 1
			res += 'L'
		elif b > ans[-1]:
			n -= 1
			ans.append(li[j])
			res += 'R'
			j -= 1
		else:
			break
	else:
		break
print(len(res))
print(res)


n = int(input())
a = list(map(int, input().split()))
ans = []
i = 0
j = n - 1
s = [0]
if n == 1:
	print(1)
	print('L')
else:
	while n:
		if a[i] > s[-1] and a[j] > s[-1]:
			if a[i] > a[j]:
				ans.append('R')
				s.append(a[j])
				n -= 1
				j -= 1
			else:
				ans.append('L')
				s.append(a[i])
				n -= 1
				i += 1
		elif a[i] > s[-1]:
			ans.append('L')
			s.append(a[i])
			i += 1
			n -= 1
		elif a[j] > s[-1]:
			ans.append('R')
			s.append(a[j])
			j -= 1
			n -= 1
		else:
			break
	print(len(ans))
	print(*ans, sep='')


n = int(input())
arr = list(map(int, input().split()))
leftIndex = 0
rightIndex = n - 1
lastAnswer = -1
answer = ''
cnt = 0
while leftIndex < rightIndex:
	if max(arr[leftIndex], arr[rightIndex]) > lastAnswer:
		if arr[leftIndex] > lastAnswer and arr[rightIndex] > lastAnswer:
			if arr[leftIndex] >= arr[rightIndex]:
				cnt += 1
				lastAnswer = arr[rightIndex]
				answer = answer + 'R'
				rightIndex -= 1
			elif arr[rightIndex] > arr[leftIndex]:
				cnt += 1
				lastAnswer = arr[leftIndex]
				answer = answer + 'L'
				leftIndex += 1
		elif arr[leftIndex] > lastAnswer:
			cnt += 1
			lastAnswer = arr[leftIndex]
			leftIndex += 1
			answer = answer + 'L'
		elif arr[rightIndex] > lastAnswer:
			cnt += 1
			lastAnswer = arr[rightIndex]
			rightIndex -= 1
			answer = answer + 'R'
	else:
		break
if leftIndex == rightIndex and arr[leftIndex] > lastAnswer:
	cnt += 1
	answer = answer + 'L'
print(cnt)
print(answer)


input()
a = (*map(int, input().split()),)
(r, s) = (len(a) - 1, '')
l = e = 0
while l <= r:
	(L, R) = (a[l], a[r])
	if L > e and R > e:
		if L < R:
			e = L
			l += 1
			s += 'L'
		else:
			e = R
			r -= 1
			s += 'R'
	elif L > e:
		e = L
		l += 1
		s += 'L'
	elif R > e:
		e = R
		r -= 1
		s += 'R'
	else:
		break
print(len(s), s)


n = int(input())
s = [int(x) for x in input().split()]
ptr1 = 0
ptr2 = len(s) - 1
st = ''
curr = -1
while ptr1 <= ptr2:
	if ptr1 == ptr2:
		if s[ptr1] > curr:
			curr = s[ptr1]
			ptr1 += 1
			ptr2 -= 1
			st += 'L'
		else:
			break
	elif s[ptr1] < s[ptr2]:
		if s[ptr1] > curr:
			curr = s[ptr1]
			ptr1 += 1
			st += 'L'
		elif s[ptr2] > curr:
			curr = s[ptr2]
			ptr2 -= 1
			st += 'R'
		else:
			break
	elif s[ptr1] > s[ptr2]:
		if s[ptr2] > curr:
			curr = s[ptr2]
			ptr2 -= 1
			st += 'R'
		elif s[ptr1] > curr:
			curr = s[ptr1]
			ptr1 += 1
			st += 'L'
		else:
			break
	elif s[ptr1] > curr:
		c1 = 0
		lst = curr
		for i in range(ptr1, ptr2 + 1):
			if s[i] > lst:
				lst = s[i]
				c1 += 1
			else:
				break
		c2 = 0
		lst = curr
		for i in range(ptr2, ptr1 - 1, -1):
			if s[i] > lst:
				lst = s[i]
				c2 += 1
			else:
				break
		if c1 >= c2:
			curr = s[ptr1]
			ptr1 += 1
			st += 'L'
		else:
			curr = s[ptr2]
			ptr2 -= 1
			st += 'R'
	else:
		break
print(len(st))
print(st)


import os
import sys

def check(x, y, l):
	co = 0
	if x <= y:
		p = -1
		for i in range(x, y + 1, 1):
			if p < l[i]:
				p = l[i]
				co += 1
			else:
				break
	elif x > y:
		p = -1
		for i in range(x, -1, -1):
			if p < l[i]:
				p = l[i]
				co += 1
			else:
				break
	return co

def main():
	n = int(input())
	ans = []
	a = list(map(int, input().split(' ')))
	f = 0
	s = n - 1
	m = -1
	while f <= s:
		if a[f] == a[s] and m < a[f]:
			m = a[f]
			co_left = check(f, n - 1, a)
			co_right = check(s, 0, a)
			if co_left >= co_right:
				ans.append('L')
				f += 1
			else:
				ans.append('R')
				s -= 1
		elif a[f] < a[s] and m < a[f]:
			m = a[f]
			ans.append('L')
			f += 1
		elif a[f] > a[s] and m < a[s]:
			m = a[s]
			ans.append('R')
			s -= 1
		elif m < a[f]:
			m = a[f]
			ans.append('L')
			f += 1
		elif m < a[s]:
			m = a[s]
			ans.append('R')
			s -= 1
		else:
			break
	print(len(ans))
	for i in ans:
		print(i, sep='', end='')
main()


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
b = []
d = []
if a[0] < a[-1]:
	b.append('L')
	d.append(a[0])
	a.popleft()
else:
	d.append(a[-1])
	a.pop()
	b.append('R')
while a:
	c = d[-1]
	if a[0] < a[-1]:
		if c < a[0]:
			d.append(a[0])
			a.popleft()
			b.append('L')
		elif c < a[-1]:
			d.append(a[-1])
			a.pop()
			b.append('R')
		else:
			break
	elif c < a[-1]:
		d.append(a[-1])
		a.pop()
		b.append('R')
	elif c < a[0]:
		d.append(a[0])
		a.popleft()
		b.append('L')
	else:
		break
print(len(b))
print(''.join(b))


n = int(input())
a = list(map(int, input().split()))
t = 0
c = 0
l = 0
b = ''
r = n - 1
while l <= r:
	m1 = min(a[l], a[r])
	m2 = max(a[l], a[r])
	if m1 > t:
		t = m1
		if m1 == a[r]:
			r -= 1
			b += 'R'
		elif m1 == a[l]:
			l += 1
			b += 'L'
		c += 1
	elif m2 > t:
		t = m2
		if m2 == a[r]:
			r -= 1
			b += 'R'
		elif m2 == a[l]:
			l += 1
			b += 'L'
		c += 1
	else:
		break
print(c)
print(b)


n = int(input())
A = list(map(int, input().split()))
cnt = 0
seq = ''
last = -1
L = 0
R = n - 1
while L <= R:
	if A[L] < A[R] and A[L] >= last:
		seq += 'L'
		last = A[L]
		L += 1
		cnt += 1
	elif A[R] >= last:
		seq += 'R'
		last = A[R]
		R -= 1
		cnt += 1
	elif A[L] >= last:
		seq += 'L'
		last = A[L]
		L += 1
		cnt += 1
	else:
		break
print(len(seq))
print(seq)


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
import sys
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]
import timeit

def primef(n, plst=[]):
	if n == 1:
		return plst
	else:
		for m in primes:
			if n % m == 0:
				return primef(n // m, plst + [m])
		return primef(1, plst + [n])

def lmii():
	return list(map(int, input().split()))

def ii():
	return int(input())

def countOverlapping(string, sub):
	count = start = 0
	while True:
		start = string.find(sub, start) + 1
		if start > 0:
			count += 1
		else:
			return count
from collections import deque
ans = []
cur = 0
n = ii()
nums = deque(lmii())
while True:
	got = [(nums[0], 'L'), (nums[-1], 'R')]
	got.sort()
	found = False
	for i in got:
		(a, b) = i
		if a > cur:
			found = True
			cur = a
			ans.append(b)
			if b == 'L':
				nums.popleft()
			else:
				nums.pop()
			break
	if not found or len(ans) == n:
		break
print(len(ans))
print(''.join(ans))


def m(a, x):
	temp_l = temp_r = x
	L = R = 0
	l = len(a)
	for i in range(l):
		if temp_l < a[i]:
			L += 1
			temp_l = a[i]
		else:
			break
	for i in range(len(a) - 1, -1, -1):
		if temp_r < a[i]:
			R += 1
			temp_r = a[i]
		else:
			break
	if R > L:
		return 'R' * (R + 1)
	return 'L' * (L + 1)
n = int(input())
s = list(map(int, input().split()))
t = 0
ans = ''
l = 0
r = n - 1
while l <= r:
	if t < s[l] < s[r]:
		ans += 'L'
		t = s[l]
		l += 1
	elif t < s[r] < s[l]:
		ans += 'R'
		t = s[r]
		r -= 1
	elif t < s[l] == s[r] and l != r:
		ans += m(s[l + 1:r], s[l]) if r - l - 1 >= 2 else 'LL' if s[l + 1] > s[l] else 'L'
		break
	elif t < s[l]:
		ans += 'L'
		t = s[l]
		l += 1
	elif t < s[r]:
		ans += 'R'
		t = s[r]
		r -= 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = list(map(int, input().split()))
res = []
end = True
right = n - 1
left = 0
prev = 0
allowLeft = True
allowRight = True
while end:
	d_r = a[right] - prev
	if d_r <= 0 or not allowRight:
		d_r = 300000
	d_l = a[left] - prev
	if d_l <= 0 or not allowLeft:
		d_l = 300000
	if d_l < d_r and allowLeft:
		prev = a[left]
		res.append('L')
		left += 1
	elif d_r < d_l and allowRight:
		prev = a[right]
		res.append('R')
		right -= 1
	elif d_r == d_l:
		if d_r == 300000:
			end = False
		elif left == right:
			prev = a[right]
			res.append('R')
			right -= 1
		elif left != right:
			left_edge = True
			left_2 = left
			prev_2 = prev
			while a[left_2] > prev_2:
				prev_2 = a[left_2]
				left_2 += 1
			right_2 = right
			prev_2 = prev
			while a[right_2] > prev_2:
				prev_2 = a[right_2]
				right_2 -= 1
			if right - right_2 > left_2 - left:
				allowLeft = False
			else:
				allowRight = False
	if left > right:
		end = False
print(len(res))
for i in res:
	print(i, end='')


import sys
from collections import deque
fin = sys.stdin.readline
n = int(fin())
a_list = deque((int(elem) for elem in fin().split()))
last_elem = float('-inf')
length_sequence = 0
operations = []
while a_list:
	if last_elem < a_list[-1] <= a_list[0]:
		last_elem = a_list.pop()
		operations.append('R')
	elif last_elem < a_list[0] <= a_list[-1]:
		last_elem = a_list.popleft()
		operations.append('L')
	elif a_list[0] < last_elem < a_list[-1]:
		last_elem = a_list.pop()
		operations.append('R')
	elif a_list[-1] < last_elem < a_list[0]:
		last_elem = a_list.popleft()
		operations.append('L')
	else:
		break
	length_sequence += 1
print(length_sequence)
print(''.join(operations))


n = int(input())
l = list(map(int, input().split()))
import sys
lewy = 0
prawy = n - 1
wynik = 0
seq = 0
le = 0
pra = 0
wynile = 0
wynipra = 0
kol = []
mini = -1000000000000
while True:
	if lewy > prawy:
		break
	if l[lewy] != l[prawy]:
		if l[lewy] > l[prawy]:
			if l[prawy] > mini:
				mini = l[prawy]
				prawy -= 1
				wynik += 1
				kol.append('R')
			elif l[lewy] > mini:
				mini = l[lewy]
				lewy += 1
				wynik += 1
				kol.append('L')
			else:
				print(wynik)
				for i in kol:
					print(i, end='')
				sys.exit(0)
		elif l[lewy] > mini:
			mini = l[lewy]
			lewy += 1
			wynik += 1
			kol.append('L')
		elif l[prawy] > mini:
			mini = l[prawy]
			prawy -= 1
			wynik += 1
			kol.append('R')
		else:
			print(wynik)
			for i in kol:
				print(i, end='')
			sys.exit(0)
	elif l[lewy] < mini:
		print(wynik)
		for i in kol:
			print(i, end='')
		sys.exit(0)
	else:
		miniclone = mini
		seq1 = 0
		le = 0
		while True:
			if lewy + le <= prawy and l[lewy + le] > mini:
				mini = l[lewy + le]
				seq1 += 1
				le += 1
			else:
				break
		wynile = wynik + seq1
		seq2 = 0
		le = 0
		mini = miniclone
		while True:
			if prawy - le >= lewy and l[prawy - le] > mini:
				mini = l[prawy - le]
				seq2 += 1
				le += 1
			else:
				break
		wynipra = wynik + seq2
		if seq1 > seq2:
			kol = kol + ['L'] * seq1
		else:
			kol = kol + ['R'] * seq2
		print(max(wynile, wynipra))
		for i in kol:
			print(i, end='')
		sys.exit(0)


N = int(input())
number = list(map(int, input().split()))
seq = []
ans = []
l = 0
r = N - 1
while l <= r:
	n1 = number[l]
	n2 = number[r]
	if not seq:
		if n1 < n2:
			seq.append(n1)
			ans.append('L')
			l += 1
		else:
			seq.append(n2)
			ans.append('R')
			r -= 1
	else:
		last = seq[-1]
		if last < n1 < n2 or n2 <= last < n1:
			seq.append(n1)
			ans.append('L')
			l += 1
		elif last < n2 < n1 or n1 <= last < n2:
			seq.append(n2)
			ans.append('R')
			r -= 1
		elif last < n1:
			seq.append(n1)
			ans.append('L')
			l += 1
		else:
			break
print(len(ans))
print(''.join(ans))


n = int(input())
x = list(map(int, input().split()))
a = []
prev_number = 0
(left_cnt, right_cnt) = (0, 0)
for i in range(n):
	if x[left_cnt] > x[-right_cnt - 1]:
		if max(x[left_cnt], x[-right_cnt - 1]) < prev_number:
			break
		if x[-right_cnt - 1] < prev_number:
			a.append('L')
			left_cnt += 1
			try:
				prev_number = x[left_cnt - 1]
			except IndexError:
				break
		else:
			a.append('R')
			right_cnt += 1
			try:
				prev_number = x[-right_cnt]
			except IndexError:
				break
	elif x[left_cnt] <= x[-right_cnt - 1]:
		if max(x[left_cnt], x[-right_cnt - 1]) < prev_number:
			break
		if x[left_cnt] < prev_number:
			a.append('R')
			right_cnt += 1
			try:
				prev_number = x[-right_cnt]
			except IndexError:
				break
		else:
			a.append('L')
			left_cnt += 1
			try:
				prev_number = x[left_cnt - 1]
			except IndexError:
				break
print(len(a))
print(*a, sep='')


n = int(input())
a = [int(x) for x in input().split()]
start = 0
end = n - 1
pos = 0
s = []
while start <= end:
	if a[start] == a[end]:
		if a[start] > pos:
			counter1 = counter2 = 1
			for i in range(start + 1, end + 1):
				if a[i] > a[i - 1]:
					counter1 += 1
				else:
					break
				i += 1
			for i in range(end - 1, start - 1, -1):
				if a[i] > a[i + 1]:
					counter2 += 1
				else:
					break
				i -= 1
			if counter1 > counter2:
				for i in range(counter1):
					s.append('L')
			else:
				for i in range(counter2):
					s.append('R')
		break
	elif a[start] < a[end] and a[start] > pos:
		s.append('L')
		pos = a[start]
		start += 1
	elif a[end] > pos:
		s.append('R')
		pos = a[end]
		end -= 1
	elif a[start] > pos:
		s.append('L')
		pos = a[start]
		start += 1
	else:
		break
print(len(s))
print(*s, sep='')


n = int(input())
i = 0
j = n - 1
cur = 0
ls = list(map(int, input().split()))
res = []
while i <= j:
	if ls[i] > cur and ls[j] > cur:
		if ls[i] < ls[j]:
			res.append('L')
			cur = ls[i]
			i += 1
		else:
			res.append('R')
			cur = ls[j]
			j -= 1
	elif ls[i] > cur:
		res.append('L')
		cur = ls[i]
		i += 1
	elif ls[j] > cur:
		res.append('R')
		cur = ls[j]
		j -= 1
	else:
		break
print(len(res))
for i in res:
	print(i, end='')
print()


n = int(input())
l = list(map(int, input().split()))
x = l[n - 1]
c = 0
s = ''
k = l[0]
j = 0
y = 0
if k > x:
	k = x
for i in range(n):
	p = len(l)
	a = l[0 + j]
	b = l[p - 1 - y]
	if a > b:
		c = b
		d = a
	else:
		c = a
		d = b
	if c >= k:
		k = c
		if c == a:
			s = s + 'L'
			j += 1
		elif c == b:
			s = s + 'R'
			y += 1
	elif d >= k:
		k = d
		if d == a:
			s = s + 'L'
			j += 1
		elif d == b:
			s = s + 'R'
			y += 1
	else:
		break
j = len(s)
print(j)
print(s)


n = int(input())

def convert(string):
	return string.split(sep=None, maxsplit=-1)

def toint(lst):
	result = []
	for i in lst:
		result.append(int(i))
	return result

def printeach(lst):
	for i in lst:
		print(i, end='')
lst = toint(convert(input()))
done = True
val = []
a = 0
b = -1
last = 0
while done:
	try:
		A = lst[a]
		B = lst[b]
	except:
		A = 0
	if a > b + len(lst):
		done = False
	elif A < last and B < last:
		done = False
	elif A < last and B > last:
		val.append('R')
		last = B
		b -= 1
	elif B < last and A > last:
		val.append('L')
		last = A
		a += 1
	elif A > B:
		val.append('R')
		last = B
		b -= 1
	else:
		val.append('L')
		last = A
		a += 1
print(len(val))
printeach(val)


from collections import deque
n = int(input())
arr = deque(list(map(int, input().split())))
ans = ''
tmp = 0
for i in range(n):
	if tmp < min(arr[0], arr[-1]):
		if arr[0] < arr[-1]:
			ans += 'L'
			tmp = arr.popleft()
		else:
			ans += 'R'
			tmp = arr.pop()
	elif tmp < max(arr[0], arr[-1]):
		if arr[0] < arr[-1]:
			ans += 'R'
			tmp = arr.pop()
		else:
			ans += 'L'
			tmp = arr.popleft()
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = (*map(int, input().split()),)
r = ''
i = p = 0
j = n - 1
while i <= j and max(a[i], a[j]) > p:
	if a[j] < p or a[j] >= a[i] > p:
		r += 'L'
		p = a[i]
		i += 1
	else:
		r += 'R'
		p = a[j]
		j -= 1
print(len(r), r)


n = int(input())
row = list(map(int, input().split()))
l = 0
r = n - 1
last = 0
ans = ''
while 1:
	if row[l] < row[r]:
		if row[l] > last:
			ans += 'L'
			last = row[l]
			l += 1
		elif row[r] > last:
			ans += 'R'
			last = row[r]
			r -= 1
		else:
			break
	elif row[r] > last:
		ans += 'R'
		last = row[r]
		r -= 1
	elif row[l] > last:
		ans += 'L'
		last = row[l]
		l += 1
	else:
		break
print(len(ans))
print(ans)


import sys
from collections import deque

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
que = deque(A)
cur = 0
ans = []
while que:
	if que[0] <= que[-1]:
		if que[0] > cur:
			cur = que.popleft()
			ans.append('L')
			continue
		elif que[-1] > cur:
			cur = que.pop()
			ans.append('R')
			continue
		else:
			break
	elif que[-1] > cur:
		cur = que.pop()
		ans.append('R')
		continue
	elif que[0] > cur:
		cur = que.popleft()
		ans.append('L')
		continue
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(1)
	print('L')
	exit()
elif a[0] < a[-1]:
	s = [a[0]]
	l = 1
	r = n - 1
	ot = 'L'
else:
	s = [a[-1]]
	l = 0
	r = n - 2
	ot = 'R'
f = True
while f:
	f = False
	if a[l] < a[r] and a[l] > s[-1]:
		s.append(a[l])
		l += 1
		ot += 'L'
		f = True
	elif a[r] > s[-1]:
		s.append(a[r])
		r -= 1
		ot += 'R'
		f = True
	elif a[l] > s[-1]:
		s.append(a[l])
		l += 1
		ot += 'L'
		f = True
print(len(ot))
print(ot)


n = int(input())
ar = list(map(int, input().split()))
a = 0
b = n - 1
ans = []
ans.append(0)
ct = str()
for i in range(n):
	if min(ar[a], ar[b]) == ar[a] and ar[a] > ans[-1]:
		ct += 'L'
		ans.append(ar[a])
		a += 1
	elif min(ar[a], ar[b]) == ar[b] and ar[b] > ans[-1]:
		ct += 'R'
		ans.append(ar[b])
		b -= 1
	elif min(ar[a], ar[b]) == ar[a] and ar[b] > ans[-1]:
		ct += 'R'
		ans.append(ar[b])
		b -= 1
	elif min(ar[a], ar[b]) == ar[b] and ar[a] > ans[-1]:
		ct += 'L'
		ans.append(ar[a])
		a += 1
	else:
		break
print(len(ans) - 1)
print(ct)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
ans = []
temp = []
if l[0] > l[-1]:
	ans.append('R')
	j -= 1
	temp.append(l[-1])
else:
	ans.append('L')
	i += 1
	temp.append(l[0])
for k in range(1, n):
	if max(l[i], l[j]) < temp[-1]:
		break
	if l[i] > temp[-1] and l[j] > temp[-1]:
		if l[i] > l[j]:
			ans.append('R')
			temp.append(l[j])
			j -= 1
		else:
			ans.append('L')
			temp.append(l[i])
			i += 1
	elif l[i] > temp[-1]:
		ans.append('L')
		temp.append(l[i])
		i += 1
	else:
		ans.append('R')
		temp.append(l[j])
		j -= 1
print(len(ans))
print(''.join(ans))


def side_res(s, res, index, step, step_res):
	x_res = res[:]
	x_res.append(step_res)
	prev = s[index]
	index += step
	while s[index] > prev:
		x_res.append(step_res)
		prev = s[index]
		index += step
	return x_res
_ = input()
s = list(map(int, input().split()))
l_index = 0
r_index = len(s) - 1
res = []
prev = 0
while l_index <= r_index:
	if s[l_index] > prev and s[r_index] > prev:
		if l_index == r_index:
			res.append('L')
			prev = s[l_index]
			l_index += 1
		elif s[l_index] == s[r_index]:
			r_res = side_res(s, res, r_index, -1, 'R')
			l_res = side_res(s, res, l_index, 1, 'L')
			res = l_res if len(l_res) > len(r_res) else r_res
			break
		elif s[l_index] < s[r_index]:
			res.append('L')
			prev = s[l_index]
			l_index += 1
		else:
			res.append('R')
			prev = s[r_index]
			r_index -= 1
	elif s[l_index] > prev:
		res.append('L')
		prev = s[l_index]
		l_index += 1
	elif s[r_index] > prev:
		res.append('R')
		prev = s[r_index]
		r_index -= 1
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
a = list(map(int, input().split()))
(fi, bi) = (0, n - 1)
prev = 0
res = []
while fi <= bi:
	(f, b) = (a[fi], a[bi])
	if prev >= f and prev >= b:
		break
	elif f == b:
		cf = 1
		while fi < n - 1 and a[fi + 1] > a[fi]:
			fi += 1
			cf += 1
		cb = 1
		while bi > 0 and a[bi - 1] > a[bi]:
			bi -= 1
			cb += 1
		if cf >= cb:
			res.extend(['L'] * cf)
		else:
			res.extend(['R'] * cb)
		break
	elif f < b:
		if f > prev:
			res.append('L')
			fi += 1
			prev = f
		else:
			res.append('R')
			bi -= 1
			prev = b
	elif b > prev:
		res.append('R')
		bi -= 1
		prev = b
	else:
		res.append('L')
		fi += 1
		prev = f
print(len(res))
for c in res:
	print(c, end='')
print()


import math
n = int(input())
a = [int(i) for i in input().split()]
ans = []
low = 0
high = n - 1
s = ''
while low <= high:
	if len(ans) == 0:
		if low == high:
			ans.append(a[high])
			high -= 1
			s += 'R'
		elif a[low] == a[high]:
			ans.append(a[low])
			i = low + 1
			c1 = 0
			last = ans[-1]
			while i < n and a[i] > last:
				c1 += 1
				last = a[i]
				i += 1
			j = high - 1
			c2 = 0
			last = ans[-1]
			while j > 0 and a[j] > last:
				c2 += 1
				last = a[j]
				j -= 1
			if c1 > c2:
				low += 1
				s += 'L'
			else:
				high -= 1
				s += 'R'
		elif a[low] < a[high]:
			ans.append(a[low])
			low += 1
			s += 'L'
		else:
			ans.append(a[high])
			high -= 1
			s += 'R'
	elif low == high and a[low] > ans[-1]:
		ans.append(a[high])
		high -= 1
		s += 'R'
	elif a[low] == a[high] and a[high] > ans[-1]:
		i = low + 1
		ans.append(a[low])
		c1 = 0
		last = ans[-1]
		while i < n and a[i] > last:
			c1 += 1
			last = a[i]
			i += 1
		j = high - 1
		c2 = 0
		last = ans[-1]
		while j > 0 and a[j] > last:
			c2 += 1
			last = a[j]
			j -= 1
		if c1 > c2:
			low += 1
			s += 'L'
		else:
			high -= 1
			s += 'R'
	elif a[low] > ans[-1] and a[high] > ans[-1]:
		if a[low] < a[high]:
			ans.append(a[low])
			low += 1
			s += 'L'
		else:
			ans.append(a[high])
			high -= 1
			s += 'R'
	elif a[low] > ans[-1] and a[high] <= ans[-1]:
		ans.append(a[low])
		low += 1
		s += 'L'
	elif a[low] <= ans[-1] and a[high] > ans[-1]:
		ans.append(a[high])
		high -= 1
		s += 'R'
	else:
		break
print(len(s))
print(s)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = len(l) - 1
l1 = []
l2 = []
count = 0
p = ''
if l[0] < l[len(l) - 1]:
	l1.append('L')
	l2.append(l[0])
	i += 1
	count += 1
else:
	l1.append('R')
	l2.append(l[len(l) - 1])
	j -= 1
	count += 1
while i < j:
	if l[i] < l[j] and l[i] > l2[len(l2) - 1]:
		l1.append('L')
		l2.append(l[i])
		i += 1
		count += 1
	elif (l[i] < l[j] and l[i] < l2[len(l1) - 1]) and l[j] > l2[len(l2) - 1]:
		l1.append('R')
		l2.append(l[j])
		j -= 1
		count += 1
	elif (l[i] < l[j] and l[i] < l2[len(l2) - 1]) and l[j] < l2[len(l2) - 1]:
		break
	elif l[i] > l[j] and l[j] > l2[len(l2) - 1]:
		l1.append('R')
		l2.append(l[j])
		j -= 1
		count += 1
	elif (l[i] > l[j] and l[j] < l2[len(l2) - 1]) and l[i] > l2[len(l2) - 1]:
		l1.append('L')
		l2.append(l[i])
		i += 1
		count += 1
	elif (l[i] > l[j] and l[j] < l2[len(l2) - 1]) and l[i] < l2[len(l2) - 1]:
		break
if i == j and l[i] > l2[len(l2) - 1]:
	count += 1
	l1.append('L')
print(count)
for i in range(len(l1)):
	p += l1[i]
print(p)


n = int(input())
permstr = input().split()
perm = [int(permstr[i]) for i in range(n)]
final = 0
sides = []
currmin = 0
flag = True
L = 0
R = n - 1
Lb = 1
Rb = 1
jumpback = False
while flag and L <= R and (perm[L] > currmin or perm[R] > currmin):
	flag = False
	if not L == R and perm[L] == perm[R]:
		while perm[L] < perm[L + 1]:
			L += 1
			Lb += 1
		while perm[R - 1] > perm[R]:
			R -= 1
			Rb += 1
		x = max(Rb, Lb)
		final += x
		if Rb == x:
			sides += ['R'] * x
		else:
			sides += ['L'] * x
	elif perm[L] > currmin:
		if perm[R] <= currmin or perm[R] > perm[L]:
			currmin = perm[L]
			final += 1
			L += 1
			sides += ['L']
			flag = True
		else:
			currmin = perm[R]
			final += 1
			R -= 1
			sides += ['R']
			flag = True
	else:
		currmin = perm[R]
		final += 1
		R -= 1
		sides += ['R']
		flag = True
print(final)
print(''.join(sides))


n = int(input())
nums = list(map(int, input().split()))
result = []
if nums[0] < nums[len(nums) - 1]:
	last = nums.pop(0)
	result.append('L')
else:
	last = nums.pop()
	result.append('R')
left = 0
right = len(nums) - 1
while left <= right:
	if nums[left] < nums[right]:
		if nums[left] > last:
			last = nums[left]
			left += 1
			result.append('L')
		elif nums[right] > last:
			last = nums[right]
			right -= 1
			result.append('R')
		else:
			break
	elif nums[right] > last:
		last = nums[right]
		right -= 1
		result.append('R')
	elif nums[left] > last:
		last = nums[left]
		left += 1
		result.append('L')
	else:
		break
print(len(result))
print(''.join(result))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
up_acc1 = [0]
for i in range(n - 2, -1, -1):
	up_acc1.append(up_acc1[-1] + 1 if a[i] < a[i + 1] else 0)
up_acc1.reverse()
up_acc2 = [0]
for i in range(1, n):
	up_acc2.append(up_acc2[-1] + 1 if a[i - 1] > a[i] else 0)
(l_idx, r_idx) = (0, n - 1)
l = [-1]
ans = []
while l_idx <= r_idx:
	if a[l_idx] > l[-1] and a[r_idx] > l[-1]:
		if a[l_idx] == a[r_idx]:
			if up_acc1[l_idx] >= up_acc2[r_idx]:
				l.append(a[l_idx])
				ans.append('L')
				l_idx += 1
			else:
				l.append(a[r_idx])
				ans.append('R')
				r_idx -= 1
		elif a[l_idx] < a[r_idx]:
			l.append(a[l_idx])
			ans.append('L')
			l_idx += 1
		else:
			l.append(a[r_idx])
			ans.append('R')
			r_idx -= 1
	elif a[l_idx] > l[-1]:
		l.append(a[l_idx])
		ans.append('L')
		l_idx += 1
	elif a[r_idx] > l[-1]:
		l.append(a[r_idx])
		ans.append('R')
		r_idx -= 1
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
nums = list(map(int, input().split()))
moves = []
prev = float('-inf')
f = 0
e = len(nums) - 1
while f <= e:
	if nums[f] < nums[e] and nums[f] > prev:
		moves.append('L')
		prev = nums[f]
		f += 1
		continue
	elif nums[e] > prev:
		moves.append('R')
		prev = nums[e]
		e -= 1
		continue
	elif nums[f] > prev and nums[e] < prev:
		moves.append('L')
		prev = nums[f]
		f += 1
	else:
		break
print(len(moves))
print(''.join(moves))


n = int(input())
a = map(int, input().split())
a = list(a)
l = 0
r = n - 1
ans = []
la = 0
while l <= r:
	if a[l] <= la and a[r] <= la:
		break
	if l == r:
		ans.append('L')
		break
	if (a[r] <= la or a[l] < a[r]) and a[l] > la:
		ans.append('L')
		la = a[l]
		l += 1
	elif (a[l] <= la or a[r] < a[l]) and a[r] > la:
		la = a[r]
		ans.append('R')
		r -= 1
	elif a[l] == a[r] and a[l] > la:
		al = 0
		ar = 0
		ll = l + 1
		rr = r - 1
		while ll <= r and a[ll] > a[ll - 1]:
			ll += 1
			al += 1
		while rr >= l and a[rr] > a[rr + 1]:
			rr -= 1
			ar -= 1
		if al > ar:
			ans += ['L'] * al
		else:
			ans += ['R'] * ar
		break
	else:
		break
print(len(ans))
print(''.join(ans))


t = int(input())
numeros = []
numeros = input().split()
movimentos = []
flag = 0
s = 0
quantidade = 0
li = 0
ri = -1
tamanho = len(numeros)
while flag == 0:
	if -ri + li - tamanho == 1:
		break
	l = int(numeros[li])
	r = int(numeros[ri])
	if l > s and r > s:
		if l > r:
			quantidade = quantidade + 1
			movimentos.append('R')
			s = r
			ri = ri - 1
		else:
			quantidade = quantidade + 1
			movimentos.append('L')
			s = l
			li = li + 1
	elif l > s and r < s:
		quantidade = quantidade + 1
		movimentos.append('L')
		s = l
		li = li + 1
	elif l < s and r > s:
		quantidade = quantidade + 1
		movimentos.append('R')
		s = r
		ri = ri - 1
	elif l < s and r < s:
		flag = 1
print(quantidade)
print(''.join(movimentos))


import math
n = int(input().lstrip())
numbers = list(map(int, input().lstrip().split()))
(low, high) = (0, n - 1)
low_fixed = high_fixed = False
res = []
while not (low_fixed and high_fixed) and low <= high:
	if low != 0 and numbers[low] < numbers[low - 1]:
		low_fixed = True
	if high != n - 1 and numbers[high] < numbers[high + 1]:
		high_fixed = True
	if low_fixed and high_fixed:
		continue
	elif low_fixed:
		res.append('R')
		high -= 1
	elif high_fixed:
		res.append('L')
		low += 1
	elif numbers[low] > numbers[high]:
		res.append('R')
		high -= 1
	else:
		res.append('L')
		low += 1
print(len(res))
print(''.join(res))


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
l = 0
r = n - 1
ans = []
if n == 1:
	Ans = 'L'
else:
	if arr[l] < arr[r]:
		temp = arr[l]
		l += 1
		Ans = 'L'
	else:
		temp = arr[r]
		r -= 1
		Ans = 'R'
	while l <= r:
		if arr[l] < arr[r] and arr[l] > temp:
			temp = arr[l]
			l += 1
			Ans += 'L'
		elif arr[r] > temp:
			temp = arr[r]
			r -= 1
			Ans += 'R'
		elif arr[l] > temp:
			temp = arr[l]
			l += 1
			Ans += 'L'
		else:
			break
print(len(Ans))
sys.stdout.write(Ans + '\n')


def mp():
	return map(int, input().split())
n = int(input())
a = list(mp())
ans = []
i = 0
j = n - 1
last = 0
while i <= j and i < n and (j >= 0):
	if a[i] == a[j] and a[i] > last:
		c1 = c2 = 0
		q = i
		while q < n and (q == n - 1 or a[q] < a[q + 1]):
			q += 1
		c1 = q - i + 1
		q = j
		while q >= 0 and (q == 0 or a[q] < a[q - 1]):
			q -= 1
		c2 = j - q + 1
		if c1 > c2:
			ans.append('L')
			last = a[i]
			i += 1
		else:
			ans.append('R')
			last = a[j]
			j -= 1
		continue
	if a[i] > last:
		if a[i] < a[j] or a[j] <= last:
			ans.append('L')
			last = a[i]
			i += 1
		elif a[j] > last:
			ans.append('R')
			last = a[j]
			j -= 1
		else:
			break
	elif a[j] > last:
		ans.append('R')
		last = a[j]
		j -= 1
	else:
		break
print(len(ans))
print(''.join(ans))


from sys import stdin
from collections import deque as dq
n = int(stdin.readline())
nums = dq(map(int, stdin.readline().split()))
ans = ''
seqlast = -1
while len(nums) > 1:
	(l, r) = (nums[0], nums[-1])
	if seqlast >= l and seqlast >= r:
		break
	elif seqlast < l and seqlast >= r:
		ans += 'L'
		nums.popleft()
		seqlast = l
	elif seqlast < r and seqlast >= l:
		ans += 'R'
		nums.pop()
		seqlast = r
	elif seqlast < r and seqlast < l:
		if l < r:
			ans += 'L'
			nums.popleft()
			seqlast = l
		elif r < l:
			ans += 'R'
			nums.pop()
			seqlast = r
		else:
			incleft = 1
			incright = 1
			for i in range(1, len(nums)):
				if nums[i] > nums[i - 1]:
					incleft += 1
				else:
					break
			for i in range(len(nums) - 1, 0, -1):
				if nums[i] < nums[i - 1]:
					incright += 1
				else:
					break
			if incleft > incright:
				ans += 'L' * incleft
				print(len(ans))
				print(ans)
				exit()
			else:
				ans += 'R' * incright
				print(len(ans))
				print(ans)
				exit()
if len(nums):
	if nums[0] > seqlast:
		ans += 'L'
print(len(ans))
print(ans)


from collections import deque
n = int(input())
A = deque(map(int, input().split()))
ans = ''
last = 0
i = 0
while i < n and max(A[0], A[-1]) > last:
	if A[0] == A[-1] and A[0] > last:
		(left, right) = (A[0], A[-1])
		size = len(A)
		ansLeft = 'L'
		for i in range(1, size):
			if A[i] > left:
				ansLeft += 'L'
				left = A[i]
			else:
				break
		ansRight = 'R'
		for i in reversed(range(size - 1)):
			if A[i] > right:
				ansRight += 'R'
				right = A[i]
			else:
				break
		ans += ansRight if len(ansRight) >= len(ansLeft) else ansLeft
		break
	if A[0] > last and (A[0] < A[-1] or A[-1] <= last):
		ans += 'L'
		last = A.popleft()
	else:
		ans += 'R'
		last = A.pop()
	i += 1
print(len(ans))
print(ans)


import sys
sys.setrecursionlimit(10 ** 7)
N = int(input())
number = list(map(int, input().split()))
seq = []
ans = []
l = 0
r = N - 1

def correct(ans, l, r, action):
	for i in range(len(ans) - 1, -1, -1):
		if not ans[i] == 'X':
			break
		ans[i] = action
		if action == 'L':
			r += 1
		else:
			l -= 1
	return (l, r)

def run(number, l, r, seq):
	ans = []
	while l <= r:
		n1 = number[l]
		n2 = number[r]
		if n1 == n2:
			if seq and n1 <= seq[-1]:
				break
			steps = 0
			last = -1
			if seq:
				last = seq[-1]
			while l + steps <= r - steps and number[l + steps] == number[r - steps] and (number[l + steps] > last):
				seq.append(number[l + steps])
				ans.append('X')
				last = number[l + steps]
				steps += 1
			s1 = run(number, l + steps, r, [seq[-1]])
			s2 = run(number, l, r - steps, [seq[-1]])
			if len(s1) > len(s2):
				return ''.join(ans).replace('X', 'L') + s1
			else:
				return ''.join(ans).replace('X', 'R') + s2
		elif not seq:
			if n1 < n2:
				seq.append(n1)
				ans.append('L')
				l += 1
			else:
				seq.append(n2)
				ans.append('R')
				r -= 1
		else:
			last = seq[-1]
			if last < n1 < n2 or n2 <= last < n1:
				(l, r) = correct(ans, l, r, 'L')
				seq.append(n1)
				ans.append('L')
				l += 1
			elif last < n2 < n1 or n1 <= last < n2:
				(l, r) = correct(ans, l, r, 'R')
				seq.append(n2)
				ans.append('R')
				r -= 1
			else:
				break
	return ''.join(ans)
ans = run(number, 0, N - 1, [])
print(len(ans))
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = 1
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		t = []
		l = 0
		r = n - 1
		k = -1
		while a[l] != a[r]:
			if a[l] < a[r]:
				if k >= a[l]:
					break
				t.append('L')
				k = a[l]
				l += 1
			else:
				if k >= a[r]:
					break
				t.append('R')
				k = a[r]
				r -= 1
		u = []
		while l < n and k < a[l]:
			u.append('L')
			k = a[l]
			l += 1
		s = []
		while r >= 0 and k < a[r]:
			s.append('R')
			k = a[r]
			r -= 1
		if len(u) > len(s):
			t.extend(u)
		else:
			t.extend(s)
		rr.append(len(t))
		rr.append(JA(t, ''))
	return JA(rr, '\n')
print(main())


n = int(input())
a = list(map(int, input().split()))
s = []
i = 0
j = n - 1
m = 0
while True:
	if a[i] <= a[j]:
		if m > a[i]:
			if m > a[j]:
				break
			s.append('R')
			m = a[j]
			j -= 1
		else:
			s.append('L')
			m = a[i]
			i += 1
	elif m > a[j]:
		if m > a[i]:
			break
		s.append('L')
		m = a[i]
		i += 1
	else:
		s.append('R')
		m = a[j]
		j -= 1
	if i > j:
		break
print(len(s))
print(''.join(s))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	last = -1
	anz = []
	stop = False
	while i != j:
		if a[i] == a[j]:
			stop = True
			break
		if a[i] < a[j]:
			if a[i] > last:
				last = a[i]
				i += 1
				anz.append('L')
			elif a[j] > last:
				last = a[j]
				j -= 1
				anz.append('R')
			else:
				break
		elif a[j] > last:
			last = a[j]
			j -= 1
			anz.append('R')
		elif a[i] > last:
			last = a[i]
			i += 1
			anz.append('L')
		else:
			break
	if i == j and a[i] > last:
		anz.append('R')
	if stop:
		l = []
		r = []
		i1 = i
		last1 = last
		while last1 < a[i] and i != j:
			last1 = a[i]
			i += 1
			l.append('L')
		while last < a[j] and i1 != j:
			last = a[j]
			j -= 1
			r.append('R')
		if len(l) > len(r):
			print(len(anz) + len(l))
			for elem in anz:
				print(elem, end='')
			for elem in l:
				print(elem, end='')
		else:
			print(len(r) + len(anz))
			for elem in anz:
				print(elem, end='')
			for elem in r:
				print(elem, end='')
	else:
		print(len(anz))
		for elem in anz:
			print(elem, end='')
main()


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return fac

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)
n = int(input())
a = list(map(int, input().split()))
ans = ''
i = 0
j = len(a) - 1
last = -1
while i <= j:
	if a[i] < a[j]:
		if a[i] > last:
			last = a[i]
			ans += 'L'
			i += 1
		elif a[j] > last:
			last = a[j]
			ans += 'R'
			j -= 1
		else:
			break
	elif a[j] > last:
		ans += 'R'
		last = a[j]
		j -= 1
	elif a[i] > last:
		ans += 'L'
		last = a[i]
		i += 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
arr = list(map(int, input().strip().split()))
fl = 1
ans = ''
c = 0
st = 0
en = n - 1
la = 0
floop = 0
while fl:
	if st >= n or en <= -1:
		break
	if arr[st] == arr[en]:
		floop = 1
		break
	if arr[st] > la:
		if arr[en] > la:
			if arr[en] > arr[st]:
				st += 1
				la = arr[st - 1]
				ans += 'L'
				c += 1
			else:
				en -= 1
				la = arr[en + 1]
				ans += 'R'
				c += 1
		else:
			st += 1
			la = arr[st - 1]
			ans += 'L'
			c += 1
	elif arr[en] > la:
		en -= 1
		la = arr[en + 1]
		ans += 'R'
		c += 1
	else:
		break
if floop == 1:
	orig = la
	cm = 0
	s1 = ''
	for i in range(st, en + 1):
		if arr[i] > la:
			la = arr[i]
			cm += 1
			s1 += 'L'
		else:
			break
	cn = 0
	s2 = ''
	la = orig
	for i in range(en, st - 1, -1):
		if la < arr[i]:
			cn += 1
			s2 += 'R'
			la = arr[i]
		else:
			break
	if cn > cm:
		ans += s2
	else:
		ans += s1
	c += max(cn, cm)
print(c)
print(ans)


n = int(input())
nums = list(map(int, input().split()))
pattern = ''
count = 0
minimum = -float('inf')
start = 0
end = n - 1
while start <= end:
	if nums[start] <= nums[end]:
		if nums[start] > minimum:
			count += 1
			pattern += 'L'
			minimum = nums[start]
			start += 1
		elif nums[end] > minimum:
			pattern += 'R'
			count += 1
			minimum = nums[end]
			end -= 1
		else:
			break
	elif nums[end] >= minimum:
		count += 1
		pattern += 'R'
		minimum = nums[end]
		end -= 1
	elif nums[start] > minimum:
		pattern += 'L'
		count += 1
		minimum = nums[start]
		start += 1
	else:
		break
print(count)
print(pattern)


n = int(input())
a = list(map(int, input().split()))
length = 1
for i in range(1, n):
	if a[i] <= a[i - 1]:
		break
	length += 1
l = [0] * n
for i in range(length):
	l[i] = length - i - 1
length = 1
for i in range(n - 2, -1, -1):
	if a[i] <= a[i + 1]:
		break
	length += 1
r = [0] * n
for i in range(n - 1, n - 1 - length, -1):
	r[i] = length - n + i
res = []
(lo, hi) = (0, n - 1)
last = 0
while lo <= hi:
	if a[lo] <= last and a[hi] <= last:
		break
	if a[lo] == a[hi]:
		if l[lo] >= r[hi]:
			res.append('L')
			last = a[lo]
			lo += 1
		else:
			res.append('R')
			last = a[hi]
			hi -= 1
	elif a[lo] < a[hi]:
		if a[lo] > last:
			res.append('L')
			last = a[lo]
			lo += 1
		elif a[hi] > last:
			res.append('R')
			last = a[hi]
			hi -= 1
	elif a[hi] > last:
		res.append('R')
		last = a[hi]
		hi -= 1
	elif a[lo] > last:
		res.append('L')
		last = a[lo]
		lo += 1
print(len(res))
print(''.join(res))


n = int(input())
f = [*map(int, input().split())]
s = ''
L = 0
R = n - 1
MAX = -1
while True:
	if f[L] < f[R]:
		if f[L] > MAX:
			MAX = f[L]
			s += 'L'
			L += 1
		elif f[R] > MAX:
			MAX = f[R]
			s += 'R'
			R -= 1
		else:
			break
	elif f[R] > MAX:
		MAX = f[R]
		s += 'R'
		R -= 1
	elif f[L] > MAX:
		MAX = f[L]
		s += 'L'
		L += 1
	else:
		break
print(len(s))
print(s)


n = int(input())
a = list(map(int, input().split()))
x = 0
i = 0
s = ''
while i < n:
	(l, r) = (a[i], a[n - 1])
	if l > x > r or r >= l > x:
		s += 'L'
		i += 1
		x = l
	elif r > x > l or l >= r > x:
		s += 'R'
		n -= 1
		x = r
	else:
		break
print(len(s))
print(s)


n = int(input())
lst = list(map(int, input().split()))
(mn, i, j, k, res, yes) = (3000000, 0, n - 1, -1, '', 0)
while mn != -1:
	(x, y) = (lst[i], lst[j])
	if max(x, y) <= k:
		mn = -1
		continue
	elif i == j:
		res += 'R'
		break
	else:
		if x == y:
			yes = 1
			break
		if x > y:
			if y > k:
				res += 'R'
				k = y
				j -= 1
			else:
				res += 'L'
				k = x
				i += 1
		if y > x:
			if x > k:
				res += 'L'
				k = x
				i += 1
			else:
				res += 'R'
				k = y
				j -= 1
if yes == 1:
	schet1 = 0
	for e in range(i + 1, j):
		if lst[e] <= lst[e - 1]:
			break
		schet1 += 1
	schet2 = 0
	for e in range(j - 1, i, -1):
		if lst[e] <= lst[e + 1]:
			break
		schet2 += 1
	if schet1 > schet2:
		res += 'L' * (schet1 + 1)
	else:
		res += 'R' * (schet2 + 1)
print(len(res))
print(res)


import sys
import math
import collections
import bisect
import string

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	n = int(input())
	arr = get_list()
	ans = ''
	prev = 0
	start = 0
	end = n - 1
	while start <= end:
		if max(arr[start], arr[end]) < prev:
			break
		elif arr[start] > prev:
			if arr[end] > arr[start]:
				prev = arr[start]
				start += 1
				ans += 'L'
			elif arr[end] > prev:
				prev = arr[end]
				end -= 1
				ans += 'R'
			else:
				prev = arr[start]
				start += 1
				ans += 'L'
		else:
			prev = arr[end]
			end -= 1
			ans += 'R'
	print(len(ans))
	print(ans)


n = int(input())
a = list(map(int, input().split()))
s = ''
x = 0
l = 0
r = n - 1
while l <= r and (a[l] > x or a[r] > x):
	if a[l] > x and a[l] <= a[r]:
		x = a[l]
		l += 1
		s += 'L'
	if a[r] > x and a[r] < a[l]:
		x = a[r]
		r -= 1
		s += 'R'
	if a[r] > x and a[l] < x:
		x = a[r]
		r -= 1
		s += 'R'
	if a[r] < x and a[l] > x:
		x = a[l]
		l += 1
		s += 'L'
print(len(s))
print(s)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
n = ii()
l = li()
d = ''
i = 0
j = n - 1
z = 0
o1 = o2 = True
while i <= j:
	if i == j and l[i] > z:
		d += 'L'
		z = l[i]
		i += 1
		o1 = o2 = False
	if o1 and o2:
		if l[i] > z and l[i] < l[j]:
			d += 'L'
			z = l[i]
			i += 1
		elif l[i] < z:
			o1 = False
		elif l[j] > z and l[j] < l[i]:
			d += 'R'
			z = l[j]
			j -= 1
		elif l[j] < z:
			o2 = False
	elif o2:
		if l[j] > z:
			d += 'R'
			z = l[j]
			j -= 1
		elif l[j] < z:
			o2 = False
	elif o1:
		if l[i] > z:
			d += 'L'
			z = l[i]
			i += 1
		elif l[i] < z:
			o1 = False
	else:
		break
print(len(d))
print(d)


import sys
N = int(input())
nums = list(map(int, input().split(' ')))
res = []
curr = 0
left = 0
right = N - 1
while True:
	if nums[left] == nums[right] or left > right or (nums[left] <= curr and nums[right] <= curr):
		break
	if nums[left] < nums[right] and nums[left] > curr or (nums[right] <= curr and nums[left] > nums[right]):
		res.append('L')
		curr = nums[left]
		left += 1
	elif nums[left] > nums[right] and nums[right] > curr or (nums[left] <= curr and nums[right] > nums[left]):
		res.append('R')
		curr = nums[right]
		right -= 1
	else:
		break
if nums[left] != nums[right] or left == right:
	if left == right and nums[left] > curr:
		res.append('L')
	print(len(res))
	print(''.join(res))
	sys.exit(0)
s = [0, 0]
temp_left = left
temp_curr = curr
while True:
	if temp_left >= right:
		break
	if nums[temp_left] > temp_curr:
		s[0] += 1
		temp_curr = nums[temp_left]
		temp_left += 1
	else:
		break
temp_right = right
temp_curr = curr
while True:
	if temp_right <= left:
		break
	if nums[temp_right] > temp_curr:
		s[1] += 1
		temp_curr = nums[temp_right]
		temp_right -= 1
	else:
		break
if s[0] > s[1]:
	res.append('L' * s[0])
else:
	res.append('R' * s[1])
res = ''.join(res)
print(len(res))
print(res)


n = int(input())
lis = list(map(int, input().split()))
l = 0
r = len(lis) - 1
s = ''
li = [0] * 1
while l <= r:
	if (lis[l] < lis[r] or lis[r] < li[-1]) and lis[l] > li[-1]:
		s += 'L'
		li.append(lis[l])
		l += 1
	elif lis[r] > li[-1]:
		s += 'R'
		li.append(lis[r])
		r -= 1
	else:
		break
print(len(s))
print(s)


n = int(input())
ar = list(map(int, input().split()))
ans1 = 1
li = []
for i in range(1, 200001):
	li.append(0)
li[ar[0] - 1] = 'L'
for i in range(1, n):
	if li[ar[i] - 1] == 0 and ar[i] > ar[i - 1]:
		ans1 += 1
		li[ar[i] - 1] = 'L'
	else:
		pre = -1
		for j in range(1, n - i + 1):
			if li[ar[-j] - 1] == 0 and ar[-j] > pre:
				li[ar[-j] - 1] = 'R'
				ans1 += 1
				pre = ar[-j]
			else:
				break
		break
main1 = []
for i in li:
	if i != 0:
		main1.append(i)
ll = ans1
ar = ar[::-1]
ans1 = 1
li = []
for i in range(1, 200001):
	li.append(0)
li[ar[0] - 1] = 'R'
for i in range(1, n):
	if li[ar[i] - 1] == 0 and ar[i] > ar[i - 1]:
		ans1 += 1
		li[ar[i] - 1] = 'R'
	else:
		pre = -1
		for j in range(1, n - i + 1):
			if li[ar[-j] - 1] == 0 and ar[-j] > pre:
				ans1 += 1
				pre = ar[-j]
				li[ar[-j] - 1] = 'L'
			else:
				break
		break
main2 = []
for i in li:
	if i != 0:
		main2.append(i)
if ll >= ans1:
	print(ll)
	print(''.join(main1))
else:
	print(ans1)
	print(''.join(main2))


n = input()
data = input()
data = data.split(' ')
sub_sequence = []
temp = min(int(data[0]), int(data[-1]))
idx = 0 if temp == int(data[0]) else -1
i = 0
j = -1
str_ = ''
sub_sequence.append(temp)
if idx == 0:
	str_ += 'L'
	i += 1
else:
	str_ += 'R'
	j -= 1
while len(sub_sequence) < len(data):
	d0 = int(data[i])
	d1 = int(data[j])
	if d0 > d1:
		if d1 > sub_sequence[-1]:
			sub_sequence.append(d1)
			str_ += 'R'
			j -= 1
		elif d0 > sub_sequence[-1]:
			sub_sequence.append(d0)
			str_ += 'L'
			i += 1
		else:
			break
	elif d0 > sub_sequence[-1]:
		sub_sequence.append(d0)
		str_ += 'L'
		i += 1
	elif d1 > sub_sequence[-1]:
		sub_sequence.append(d1)
		str_ += 'R'
		j -= 1
	else:
		break
print(len(sub_sequence))
print(str_)


import math
read = lambda : map(int, input().split())
input()
a = list(read())
l = 0
r = len(a) - 1
pre = 0
ans = ''
while l <= r:
	if a[l] > pre and (a[l] < a[r] or a[r] < pre):
		ans += 'L'
		pre = a[l]
		l += 1
	elif a[r] > pre and (a[l] > a[r] or a[l] < pre):
		ans += 'R'
		pre = a[r]
		r -= 1
	elif l == r and a[l] > pre:
		ans += 'L'
		break
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = list(map(int, input().split()))
now = 0
ans = 0
ptrl = 0
ptrr = n - 1
ans = []
while ptrl <= ptrr:
	if a[ptrl] < a[ptrr] and now < a[ptrl]:
		ans += 'L'
		now = a[ptrl]
		ptrl += 1
	elif now < a[ptrr]:
		ans += 'R'
		now = a[ptrr]
		ptrr -= 1
	elif now < a[ptrl]:
		ans += 'L'
		now = a[ptrl]
		ptrl += 1
	else:
		break
print(len(ans))
print(*ans, sep='')


from collections import deque

def solve(A):
	res = []
	last = 0
	while A:
		if max(A[0], A[-1]) <= last:
			return res
		if A[0] == A[-1]:
			v = A[0] - 1
			for (i, a) in enumerate(A):
				if v < a:
					v = a
				else:
					break
			else:
				i += 1
			L = i
			v = A[-1] - 1
			for (i, a) in enumerate(reversed(A)):
				if v < a:
					v = a
				else:
					break
			else:
				i += 1
			R = i
			(_, op) = max((L, ['L'] * L), (R, ['R'] * R))
			res.extend(op)
			return res
		(v, op) = min(((v, op) for (v, op) in ((A[0], 'L'), (A[-1], 'R')) if v > last))
		last = v
		res.append(op)
		if op == 'L':
			A.popleft()
		else:
			A.pop()

def main():
	input()
	A = deque(map(int, input().split()))
	res = solve(A)
	print(len(res))
	print(*res, sep='')
main()


n = int(input())
a = list(map(int, input().split(' ')))
pl = 0
pr = len(a) - 1
last = 0
op = []
while pl <= pr:
	l = a[pl]
	r = a[pr]
	if l <= last and r <= last:
		break
	elif l <= last:
		op.append('R')
		last = r
		pr -= 1
	elif r <= last:
		op.append('L')
		last = l
		pl += 1
	elif l < r:
		op.append('L')
		last = l
		pl += 1
	elif l > r:
		op.append('R')
		last = r
		pr -= 1
	else:
		llen = 1
		rlen = 1
		for i in range(pl + 1, pr + 1):
			if a[i] <= a[i - 1]:
				break
			llen += 1
		for i in range(pr - 1, pl - 1, -1):
			if a[i] <= a[i + 1]:
				break
			rlen += 1
		if llen >= rlen:
			while llen > 0:
				op.append('L')
				llen -= 1
		else:
			while rlen > 0:
				op.append('R')
				rlen -= 1
		break
print(len(op))
print(''.join(op))


n = int(input())
arr = list(map(int, input().strip().split()))
fl = 1
ans = ''
c = 0
st = 0
en = n - 1
la = 0
while fl:
	if st >= n or en <= -1:
		break
	if arr[st] > la:
		if arr[en] > la:
			if arr[en] > arr[st]:
				st += 1
				la = arr[st - 1]
				ans += 'L'
				c += 1
			else:
				en -= 1
				la = arr[en + 1]
				ans += 'R'
				c += 1
		else:
			st += 1
			la = arr[st - 1]
			ans += 'L'
			c += 1
	elif arr[en] > la:
		en -= 1
		la = arr[en + 1]
		ans += 'R'
		c += 1
	else:
		break
print(c)
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
l = 0
r = n - 1
prev_val = 0
lr = []
cnt = 0
while l <= r:
	if arr[l] > prev_val and arr[r] > prev_val:
		if arr[l] < arr[r]:
			prev_val = arr[l]
			l += 1
			lr.append('L')
		else:
			prev_val = arr[r]
			r -= 1
			lr.append('R')
		cnt += 1
	elif arr[l] > prev_val:
		prev_val = arr[l]
		l += 1
		lr.append('L')
		cnt += 1
	elif arr[r] > prev_val:
		prev_val = arr[r]
		r -= 1
		lr.append('R')
		cnt += 1
	else:
		break
print(cnt)
for var in lr:
	print(var, end='')


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
ans = ''
l = 0
r = n - 1
last_num = None
while l <= r:
	if a[r] < a[l]:
		num1 = a[r]
		num2 = a[l]
	elif a[r] > a[l]:
		num1 = a[l]
		num2 = a[r]
	if a[r] == a[l]:
		if last_num is not None and last_num >= a[r]:
			break
		max_gre_l = 0
		temp_l = l
		while temp_l < r and temp_l < n - 1:
			if a[temp_l] < a[temp_l + 1]:
				max_gre_l += 1
				temp_l += 1
			else:
				break
		max_gre_r = 0
		temp_r = r
		while temp_r > l and temp_r > 0:
			if a[temp_r] < a[temp_r - 1]:
				max_gre_r += 1
				temp_r -= 1
			else:
				break
		last_num = a[r]
		if max_gre_r > max_gre_l:
			r -= 1
			ans += 'R'
		else:
			l += 1
			ans += 'L'
	elif last_num is None or last_num < num1:
		last_num = num1
		if num1 == a[l]:
			l += 1
			ans += 'L'
		else:
			r -= 1
			ans += 'R'
	elif last_num is None or last_num < num2:
		last_num = num2
		if num2 == a[l]:
			l += 1
			ans += 'L'
		else:
			r -= 1
			ans += 'R'
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
last = -1
i = 0
j = n - 1
ans = ''
while i <= j:
	if max(a[i], a[j]) <= last:
		break
	if a[i] < a[j]:
		if a[i] > last:
			ans += 'L'
			last = a[i]
			i += 1
		else:
			ans += 'R'
			last = a[j]
			j -= 1
	elif a[j] > last:
		ans += 'R'
		last = a[j]
		j -= 1
	else:
		ans += 'L'
		last = a[i]
		i += 1
print(len(ans))
print(ans)


while True:
	try:
		n = int(input())
		a = list(map(int, input().strip().split()))
		(c, l, r) = (0, 0, len(a) - 1)
		s = []
		o = []
		while (not o or a[l] >= s[-1] or a[r] >= s[-1]) and l <= r:
			if not s:
				if a[l] < a[r]:
					s.append(a[l])
					o.append('L')
					l += 1
				else:
					s.append(a[r])
					o.append('R')
					r -= 1
			elif a[l] < s[-1]:
				s.append(a[r])
				o.append('R')
				r -= 1
			elif a[r] < s[-1]:
				s.append(a[l])
				o.append('L')
				l += 1
			elif a[l] < a[r]:
				s.append(a[l])
				o.append('L')
				l += 1
			else:
				s.append(a[r])
				o.append('R')
				r -= 1
		print(len(o))
		print(''.join(o))
	except:
		break


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque

def main():
	n = int(input())
	nums = deque(list(map(int, input().split())))
	ri = 0
	rs = []
	rs.append('D')
	t1 = 0
	if n == 1:
		print(1)
		print('L')
		sys.exit()
	while nums:
		if rs[-1] == 'L':
			l = nums.popleft()
		elif rs[-1] == 'R':
			r = nums.pop()
		elif rs[-1] == 'D':
			l = nums.popleft()
			r = nums.pop()
		if t1 < min(l, r):
			t1 = min(l, r)
			ri += 1
			rs += 'L' if l < r else 'R'
		elif t1 < max(l, r):
			t1 = max(l, r)
			ri += 1
			rs += 'L' if l > r else 'R'
		else:
			break
	if rs[-1] == 'L' and t1 < r:
		ri += 1
		rs += 'L'
	elif rs[-1] == 'R' and t1 < l:
		ri += 1
		rs += 'L'
	print(ri)
	print(''.join(rs[1:]))
main()


n = int(input())
a = list(map(int, input().split()))
Lind = 0
Rind = n - 1
flag = True
ans = list()
ans.append(0)
ans2 = list()
flag5 = True
flag6 = True
while flag and Rind >= Lind and flag5 and flag6:
	if a[Rind] > a[Lind]:
		if a[Lind] > ans[-1]:
			ans.append(a[Lind])
			Lind += 1
			ans2.append('L')
		else:
			flag5 = False
	elif a[Lind] > a[Rind]:
		if a[Rind] > ans[-1]:
			ans.append(a[Rind])
			Rind -= 1
			ans2.append('R')
		else:
			flag6 = False
	else:
		flag = False
if not flag or not flag5 or (not flag6):
	lmax = 0
	rmax = 0
	for i in range(Lind, Rind):
		if a[i] > ans[-1]:
			if a[i + 1] > a[i]:
				lmax += 1
			else:
				lmax += 1
				break
		else:
			break
	for i in reversed(range(Lind + 1, Rind + 1)):
		if a[i] > ans[-1]:
			if a[i - 1] > a[i]:
				rmax += 1
			else:
				rmax += 1
				break
		else:
			break
	if lmax > rmax:
		i = Lind
		while Lind <= Rind:
			if a[i] > ans[-1]:
				ans.append(a[i])
				ans2.append('L')
				i += 1
			else:
				break
	else:
		i = Rind
		while Rind >= Lind:
			if a[i] > ans[-1]:
				ans.append(a[i])
				ans2.append('R')
				i -= 1
			else:
				break
print(len(ans) - 1)
print(*ans2, end='', sep='')


n = int(input())
s = input().split()
a = [int(num) for num in s]
i = 0
j = n - 1
last = 0
ans = ''
count = 0
count1 = 0
count2 = 0
while max(a[i], a[j]) > last and i <= j:
	if a[i] == a[j]:
		if i == j:
			ans += 'L'
			count += 1
			break
		if max(a[i + 1], a[j - 1]) <= a[i]:
			ans += 'L'
			count += 1
			break
		i1 = i + 1
		while a[i1] > a[i1 - 1]:
			count1 += 1
			i1 += 1
		j1 = j - 1
		while a[j1] > a[j1 + 1]:
			count2 += 1
			j1 -= 1
		if count1 > count2:
			ans += 'L' * (count1 + 1)
			count = count + count1 + 1
		else:
			ans += 'R' * (count2 + 1)
			count = count + count2 + 1
		break
	elif a[i] > last and a[i] <= a[j] or a[j] <= last:
		last = a[i]
		i += 1
		ans += 'L'
		count += 1
		if i > j:
			break
	elif a[j] > last and a[j] <= a[i] or a[i] <= last:
		last = a[j]
		j -= 1
		ans += 'R'
		count += 1
		if i > j:
			break
	else:
		break
print(count)
print(ans)


n = int(input())
l = list(map(int, input().split()))
res = ''
left = 0
right = n - 1
curr = 0
while left <= right:
	if l[left] > curr and l[right] > curr:
		if l[left] < l[right]:
			left = left + 1
			curr = l[left - 1]
			res += 'L'
		else:
			right = right - 1
			curr = l[right + 1]
			res += 'R'
	elif l[left] > curr and l[right] < curr:
		left = left + 1
		curr = l[left - 1]
		res += 'L'
	elif l[right] > curr and l[left] < curr:
		right = right - 1
		curr = l[right + 1]
		res += 'R'
	else:
		break
print(len(res))
print(res)


def soln(l):
	sol = []
	str = ''
	i = 0
	j = len(l) - 1
	if l[i] < l[j]:
		sol.append(l[i])
		str = str + 'L'
		i += 1
	else:
		sol.append(l[j])
		str = str + 'R'
		j -= 1
	while i <= j:
		if l[i] > sol[-1] and l[j] > sol[-1]:
			if l[i] <= l[j]:
				sol.append(l[i])
				str = str + 'L'
				i += 1
			else:
				sol.append(l[j])
				str = str + 'R'
				j -= 1
		elif l[i] > sol[-1]:
			sol.append(l[i])
			str = str + 'L'
			i += 1
		elif l[j] > sol[-1]:
			sol.append(l[j])
			str = str + 'R'
			j -= 1
		else:
			break
	return (len(sol), str)
no_of_elements = int(input())
l = [int(x) for x in input().split()]
(no, str) = soln(l)
print(no)
print(str)


n = int(input())
arr = list(map(int, input().split()))
arr = [arr[0] - 1] + arr + [arr[n - 1] - 1]
lbound = 1
while arr[lbound] < arr[lbound + 1]:
	lbound += 1
rbound = n
while arr[rbound] < arr[rbound - 1]:
	rbound -= 1
if lbound == rbound:
	if lbound != 0:
		lbound -= 1
	else:
		rbound += 1
lb = 1
rb = n
size = lbound + (n + 1 - rbound)
cnt = 0
step = [None] * size
while cnt < size:
	if arr[lb] < arr[rb]:
		step[cnt] = 'L'
		lb += 1
		if lb > lbound:
			arr[lb] = 999999999
	elif rb >= rbound:
		step[cnt] = 'R'
		rb -= 1
		if rb < rbound:
			arr[rb] = 999999999
	cnt += 1
print(size)
if size > 0:
	print(''.join(step))


n = int(input())
a = list(map(int, input().split()))
sp = [0]
s = ''
l = 0
r = n - 1
while r - l != -1:
	if a[l] > sp[-1] and a[r] < sp[-1]:
		sp.append(a[l])
		l += 1
		s += 'L'
	elif a[r] > sp[-1] and a[l] < sp[-1]:
		sp.append(a[r])
		r -= 1
		s += 'R'
	elif a[l] > sp[-1] and a[r] > sp[-1]:
		if a[l] < a[r]:
			sp.append(a[l])
			l += 1
			s += 'L'
		else:
			sp.append(a[r])
			r -= 1
			s += 'R'
	else:
		break
print(len(sp) - 1)
print(s)


n = int(input())
arr = list(map(int, input().split()))
res = ''
last = -1
(l, r) = (0, n - 1)
while l <= r:
	if arr[l] < arr[r] and arr[l] > last:
		res += 'L'
		last = arr[l]
		l += 1
	elif arr[r] < arr[l] and arr[r] > last:
		res += 'R'
		last = arr[r]
		r -= 1
	elif arr[r] > last:
		res += 'R'
		last = arr[r]
		r -= 1
	elif arr[l] > last:
		res += 'L'
		last = arr[l]
		l += 1
	else:
		break
print(len(res))
print(res)


n = int(input())
arr = [int(i) for i in input().split()]
ans = ''
cl = 0
start = 0
for i in range(n):
	(l, r) = (arr[start] * (arr[start] > cl), arr[-1] * (arr[-1] > cl))
	if l > cl and (l < r or r == 0):
		cl = arr[start]
		start += 1
		ans += 'L'
		continue
	if r > cl and (l > r or l == 0):
		cl = arr.pop()
		ans += 'R'
		continue
	if l == r and l > cl:
		ans += 'L'
	break
print(len(ans))
print(ans)


from sys import stdin
input = stdin.readline
n = int(input())
l = list(map(int, input().split()))
fin = ''
finL = 0
(i, j) = (0, n - 1)
while i <= j:
	if l[i] <= finL or l[j] <= finL:
		break
	if l[i] < l[j]:
		fin += 'L'
		finL = l[i]
		i += 1
	elif l[j] < l[i]:
		fin += 'R'
		finL = l[j]
		j -= 1
	else:
		break
(l1, l2) = (0, 0)
pre = finL
for x in range(i, j + 1):
	if finL < l[x]:
		finL = l[x]
		l1 += 1
	else:
		break
finL = pre
for x in range(j, i - 1, -1):
	if finL < l[x]:
		finL = l[x]
		l2 += 1
	else:
		break
fin += l1 * 'L' if l1 > l2 else l2 * 'R'
print(len(fin))
print(fin)


from collections import deque as dq
n = int(input())
l = dq(map(int, input().split()))
cur = 0
r = [''] * n
v = 0
while len(l) > 0:
	mi = min(l[0], l[-1])
	if max(l[0], l[-1]) < cur:
		break
	if mi == l[0] and mi >= cur:
		cur = l.popleft()
		r[v] = 'L'
		v += 1
	elif mi == l[0]:
		cur = l.pop()
		r[v] = 'R'
		v += 1
	elif mi == l[-1] and mi >= cur:
		cur = l.pop()
		r[v] = 'R'
		v += 1
	else:
		cur = l.popleft()
		r[v] = 'L'
		v += 1
print(v)
print(*r, sep='')


n = int(input())
m = input().split()
last = 0
o = []
index_front = 0
index_back = n - 1
pointer_front = int(m[index_front])
pointer_back = int(m[index_back])
while n != 0 and (last < pointer_front or last < pointer_back):
	if pointer_back > pointer_front > last or pointer_back <= last:
		last = pointer_front
		index_front += 1
		o.append('L')
	else:
		last = pointer_back
		o.append('R')
		index_back -= 1
	if n != 1:
		pointer_front = int(m[index_front])
		pointer_back = int(m[index_back])
	n -= 1
print(len(o))
print(''.join(o))


n = int(input())
nums = list(map(int, input().split()))
temps = []
last_num = -1
left = 0
right = n - 1
answer = ''
while left <= right and max(nums[left], nums[right]) > last_num:
	if nums[left] > last_num > nums[right] or last_num < nums[left] < nums[right]:
		answer += 'L'
		last_num = nums[left]
		left += 1
	else:
		answer += 'R'
		last_num = nums[right]
		right -= 1
print(len(answer))
print(answer)


n = int(input())
a = list(map(int, input().split()))
now = 0
ans = 0
ptrl = 0
ptrr = n - 1
ans = []
while ptrl <= ptrr:
	if min(a[ptrl], a[ptrr]) > now:
		if a[ptrl] == a[ptrr]:
			cntr = 1
			cntl = 1
			while a[(ptrl + 1) % n] > a[ptrl]:
				cntl += 1
				ptrl += 1
			while a[ptrr - 1] > a[ptrr]:
				cntr += 1
				ptrr -= 1
			if cntl > cntr:
				ans += 'L' * cntl
			else:
				ans += 'R' * cntr
			break
		if a[ptrl] < a[ptrr]:
			now = a[ptrl]
			ptrl += 1
			ans += 'L'
		else:
			now = a[ptrr]
			ptrr -= 1
			ans += 'R'
	elif max(a[ptrl], a[ptrr]) > now:
		if a[ptrl] < a[ptrr]:
			ans += 'R'
			while a[ptrr - 1] > a[ptrr]:
				ans += 'R'
				ptrr -= 1
		else:
			ans += 'L'
			while a[(ptrl + 1) % n] > a[ptrl]:
				ans += 'L'
				ptrl += 1
		break
	else:
		break
print(len(ans))
print(*ans, sep='')


def increaseSequence(n, a):
	result = []
	last = -1
	left = 0
	right = n - 1

	def addLeft():
		nonlocal last, left, result
		last = a[left]
		left += 1
		result.append('L')

	def addRight():
		nonlocal last, right, result
		last = a[right]
		right -= 1
		result.append('R')
	while True:
		if left > right:
			break
		smaller = min(a[left], a[right])
		bigger = max(a[left], a[right])
		if bigger < last:
			break
		if smaller > last:
			if a[left] == smaller:
				addLeft()
			else:
				addRight()
		elif a[left] > last:
			addLeft()
		else:
			addRight()
	return ''.join(result)
n = int(input())
a = [int(item) for item in input().split()]
result = increaseSequence(n, a)
print(len(result))
print(result)


n = int(input())
l1 = list(map(int, input().split()))
i = 0
j = n - 1
l2 = []
ans = ''
if n == 1:
	print(1)
	print('L')
else:
	m = min(l1[i], l1[j])
	if m == l1[i]:
		ans += 'L'
		i += 1
		l2.append(m)
	elif m == l1[j]:
		ans += 'R'
		j -= 1
		l2.append(m)
	while i <= j:
		if l1[i] > l2[len(l2) - 1] and l1[j] < l2[len(l2) - 1]:
			ans += 'L'
			l2.append(l1[i])
			i += 1
		elif l1[i] < l2[len(l2) - 1] and l1[j] > l2[len(l2) - 1]:
			ans += 'R'
			l2.append(l1[j])
			j -= 1
		elif l1[i] < l2[len(l2) - 1] and l1[j] < l2[len(l2) - 1]:
			break
		else:
			m = min(l1[i], l1[j])
			if m == l1[i]:
				ans += 'L'
				l2.append(l1[i])
				i += 1
			elif m == l1[j]:
				ans += 'R'
				l2.append(l1[j])
				j -= 1
	print(len(ans))
	print(ans)


n = int(input())
nums = list(map(int, input().split()))
result = []
last = -1
left = 0
right = len(nums) - 1
while left <= right:
	if nums[left] < nums[right]:
		if nums[left] > last:
			last = nums[left]
			left += 1
			result.append('L')
		elif nums[right] > last:
			last = nums[right]
			right -= 1
			result.append('R')
		else:
			break
	elif nums[left] > nums[right]:
		if nums[right] > last:
			last = nums[right]
			right -= 1
			result.append('R')
		elif nums[left] > last:
			last = nums[left]
			left += 1
			result.append('L')
		else:
			break
	elif nums[left] == nums[right]:
		l_n = left
		r_n = right
		l_c = 0
		r_c = 0
		l_last = last
		r_last = last
		while l_n <= right:
			if nums[l_n] > l_last:
				l_c += 1
				l_last = nums[l_n]
				l_n += 1
			else:
				break
		while r_n >= left:
			if nums[r_n] > r_last:
				r_c += 1
				r_last = nums[r_n]
				r_n -= 1
			else:
				break
		if l_c > r_c:
			for i in range(l_c):
				result.append('L')
		else:
			for i in range(r_c):
				result.append('R')
		break
print(len(result))
print(''.join(result))


n = int(input())
a = list(map(int, input().split()))
l = 0
r = len(a) - 1
ans = []
last = 0
while True:
	if l > r:
		break
	if a[l] <= a[r] and a[l] > last:
		ans.append('L')
		last = a[l]
		l += 1
	elif a[r] > last:
		ans.append('R')
		last = a[r]
		r -= 1
	elif a[l] > last:
		ans.append('L')
		last = a[l]
		l += 1
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
ans = ''
l = 0
r = n - 1
last_num = None
while l <= r:
	if a[r] < a[l]:
		num1 = a[r]
		num2 = a[l]
	else:
		num1 = a[l]
		num2 = a[r]
	if last_num is None or last_num < num1:
		last_num = num1
		if num1 == a[l]:
			l += 1
			ans += 'L'
		else:
			r -= 1
			ans += 'R'
	elif last_num is None or last_num < num2:
		last_num = num2
		if num2 == a[l]:
			l += 1
			ans += 'L'
		else:
			r -= 1
			ans += 'R'
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
last = -1
s = []
while l <= r:
	if a[l] == a[r]:
		nl = 0
		ll = last
		while l + nl <= r and a[l + nl] > ll:
			ll = a[l + nl]
			nl += 1
		nr = 0
		lr = last
		while l <= r - nr and a[r - nr] > lr:
			lr = a[r - nr]
			nr += 1
		if nr > nl:
			s.extend(nr * ['R'])
		else:
			s.extend(nl * ['L'])
		break
	elif a[l] > last and (a[r] > a[l] or a[r] <= last):
		last = a[l]
		s.append('L')
		l += 1
	elif a[r] > last and (a[l] > a[r] or a[l] <= last):
		last = a[r]
		s.append('R')
		r -= 1
	else:
		break
print(len(s))
print(''.join(s))


n = int(input())
arr = list(map(int, input().split()))
(l, r) = (0, n - 1)
last = 0
s = ''
while True:
	if l > r or last > max(arr[l], arr[r]):
		break
	elif arr[l] > arr[r] and arr[r] > last or arr[r] > last > arr[l]:
		last = arr[r]
		r -= 1
		s += 'R'
	else:
		last = arr[l]
		l += 1
		s += 'L'
print(len(s))
print(s)


n = int(input())
a = [int(i) for i in input().split()]
i = 0
j = n - 1
b = 0
s = ''
while i <= j:
	if a[i] == 10 ** 6 and a[j] == 10 ** 6:
		break
	if a[i] > b or a[j] > b:
		if a[i] > a[j]:
			if a[j] > b:
				b = a[j]
				s += 'R'
				j -= 1
			else:
				a[j] = 10 ** 6
		elif a[i] > b:
			b = a[i]
			s += 'L'
			i += 1
		else:
			a[i] = 10 ** 6
	else:
		break
print(len(s))
print(s)


n = int(input())
s = list(map(int, input().split()))
(i, j) = (0, n - 1)
r = [0]
re = []
while i < n and j > -1:
	if s[i] == min(s[i], s[j]):
		if s[i] > r[-1]:
			r.append(s[i])
			re.append('L')
			i += 1
		elif s[j] > r[-1]:
			r.append(s[j])
			re.append('R')
			j -= 1
		else:
			break
	elif s[j] > r[-1]:
		r.append(s[j])
		re.append('R')
		j -= 1
	elif s[i] > r[-1]:
		r.append(s[i])
		re.append('L')
		i += 1
	else:
		break
print(len(re))
print(*re, sep='')


import sys

def gao(n, arr):
	opr = []
	top = -1
	num = 0
	left = 0
	right = n - 1
	while left <= right:
		if arr[left] < top and arr[right] < top:
			break
		if arr[left] > arr[right] > top or arr[right] > top > arr[left]:
			top = arr[right]
			opr.append('R')
			num += 1
			right -= 1
		elif arr[right] >= arr[left] >= top or arr[left] > top > arr[right]:
			top = arr[left]
			opr += 'L'
			num += 1
			left += 1
	return [num, ''.join(opr)]

def main():
	lines = [sys.stdin.readline(), sys.stdin.readline()]
	lines = [l.strip(' \r\n') for l in lines]
	n = int(lines[0])
	vals = [int(v) for v in lines[1].split(' ')]
	ret = gao(n, vals)
	print(ret[0])
	print(ret[1])
main()


n = int(input())
a = list(map(int, input().split()))
t = int(0)
ans = ''
n -= 1
mr = n
ml = 0
while n >= 0:
	l = a[ml]
	r = a[mr]
	if l < r and l > t:
		ml += 1
		t = l
		ans += 'L'
		n -= 1
	elif r > t:
		mr -= 1
		t = r
		ans += 'R'
		n -= 1
	elif r < l and l > t and (r < t):
		ml += 1
		t = l
		ans += 'L'
		n -= 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
s = list(map(int, input().split()))
c = 1
l = 0
r = n - 1
a = 0
y = ''
while l <= r:
	if a > s[l] and a > s[r]:
		break
	elif s[l] > a and s[r] > a:
		a = min(s[l], s[r])
		if a == s[l]:
			y = y + 'L'
			l = l + 1
		else:
			y = y + 'R'
			r = r - 1
	else:
		a = max(s[l], s[r])
		if a == s[l]:
			y = y + 'L'
			l = l + 1
		else:
			y = y + 'R'
			r = r - 1
print(len(y))
print(y)


from collections import deque
n = int(input())
a = map(int, input().split())
d = deque(a, n)
r = ''
t = 0
while len(d) > 0:
	if t < d[0] < d[-1]:
		r += 'L'
		t = d.popleft()
	elif t < d[-1]:
		r += 'R'
		t = d.pop()
	elif t < d[0]:
		r += 'L'
		t = d.popleft()
	else:
		break
print(len(r))
print(r)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
flag = True
if a[0] < a[r]:
	l = 1
	cur = a[0]
	ans = ['L']
else:
	r = n - 2
	cur = a[n - 1]
	ans = ['R']
while flag:
	if cur < a[l] and (a[l] < a[r] or cur > a[r]):
		ans.append('L')
		cur = a[l]
		l += 1
	elif cur < a[r] and (a[r] < a[l] or cur > a[l]):
		ans.append('R')
		cur = a[r]
		r -= 1
	else:
		flag = False
	if l == r and a[l] > cur:
		ans.append('L')
		flag = False
print(len(ans))
for i in range(len(ans)):
	print(ans[i], end='')


sz = int(input())
lst = list(map(int, input().split(' ')))
(l, r, out) = (0, sz - 1, [])
for i in range(len(lst)):
	if not i:
		if lst[l] < lst[r]:
			out.append('L')
			prev = lst[l]
			l += 1
		else:
			out.append('R')
			prev = lst[r]
			r -= 1
	else:
		b = False
		if l < len(lst) and lst[l] > prev and (lst[l] < lst[r]):
			out.append('L')
			prev = lst[l]
			l += 1
			b = True
		elif r >= 0 and lst[r] > prev:
			out.append('R')
			prev = lst[r]
			r -= 1
			b = True
		if not b and l < len(lst) and (lst[l] > prev):
			out.append('L')
			prev = lst[l]
			l += 1
print(len(out))
if len(out) == len(lst):
	out[len(out) - 1] = 'L'
print(*out, sep='')


n = int(input())
d = [int(x) for x in input().strip().split(' ')]
p = -1
l = 0
r = n - 1
res = []
while l <= r:
	if p < d[l] or p < d[r]:
		if d[l] == d[r] and r - l + 1 > 3:
			if d[r - 1] > d[l + 1] > d[l] > p:
				res.append('L')
				p = d[l]
				l += 1
			else:
				res.append('R')
				p = d[r]
				r -= 1
		elif d[r] > d[l] > p or d[r] <= p:
			res.append('L')
			p = d[l]
			l += 1
		else:
			res.append('R')
			p = d[r]
			r -= 1
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
a = list(map(int, input().split()))
ma = 0
otv = ''
n -= 1
l = 0
r = n
cr = 0
cl = 0
while r >= l:
	b = a[l]
	c = a[r]
	if b == c and r - l > 2:
		cl = l
		cr = r
		xa = ma
		sl = 0
		sr = 0
		while cl <= r and a[cl] > xa:
			xa = a[cl]
			cl += 1
			sl += 1
		xa = ma
		while cr >= l and a[cr] > xa:
			xa = a[cr]
			cr -= 1
			sr += 1
		if sl >= sr:
			otv += 'L' * sl
		else:
			otv += 'R' * sr
		break
	if b < c and b > ma:
		ma = a[l]
		otv += 'L'
		l += 1
	elif c > ma:
		ma = a[r]
		otv += 'R'
		r -= 1
	elif b > ma:
		ma = a[l]
		otv += 'L'
		l += 1
	else:
		break
print(len(otv))
print(otv)


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
res = []
cur = 0
left = 0
right = n - 1
while left <= right:
	if cur < a[left] < a[right] or a[right] <= cur < a[left]:
		cur = a[left]
		left += 1
		res.append('L')
	elif cur < a[right] < a[left] or a[left] <= cur < a[right]:
		cur = a[right]
		right -= 1
		res.append('R')
	elif cur < a[left] and a[left] == a[right]:
		if left == right:
			cur = a[right]
			right -= 1
			res.append('R')
		else:
			(l, r) = (left, right)
			(cl, cr) = (0, 0)
			while l < r and a[l] < a[l + 1]:
				cl += 1
				l += 1
			(l, r) = (left, right)
			while r > l and a[r] < a[r - 1]:
				cr += 1
				r -= 1
			if cl > cr:
				res.append('L' * (cl + 1))
			else:
				res.append('R' * (cr + 1))
			break
	else:
		break
print(len(res) - 1 + len(res[-1]))
print(''.join(res))


n = int(input())
ar = list(map(int, input().split()))
if n == 1:
	print(1)
	print('L')
else:
	l = 0
	x = 0
	y = n - 1
	ans = []
	while x <= y:
		if x == y and ar[x] > l:
			x += 1
			y -= 1
			ans.append('L')
		elif ar[x] == ar[y] and ar[x] > l:
			x1 = x + 1
			y1 = y - 1
			c1 = 1
			for i in range(x1, y + 1):
				if ar[i] > ar[i - 1]:
					c1 += 1
				else:
					break
			c2 = 1
			while y1 > x:
				if ar[y1] > ar[y1 + 1]:
					c2 += 1
				else:
					break
				y1 -= 1
			if c1 >= c2:
				for i in range(c1):
					ans.append('L')
			else:
				for i in range(c2):
					ans.append('R')
			break
		elif ar[x] > l and ar[y] > l:
			if ar[x] > ar[y]:
				ans.append('R')
				l = ar[y]
				y -= 1
			else:
				ans.append('L')
				l = ar[x]
				x += 1
		elif ar[x] > l:
			ans.append('L')
			l = ar[x]
			x += 1
		elif ar[y] > l:
			ans.append('R')
			l = ar[y]
			y -= 1
		else:
			break
	print(len(ans))
	print(''.join(ans))


def count(b, dir, g):
	n = 0
	if dir == 'L':
		while g >= l and a[g] > b:
			b = a[g]
			g -= 1
			n += 1
	else:
		while g <= r and a[g] > b:
			b = a[g]
			g += 1
			n += 1
	return n
n = int(input())
a = [int(i) for i in input().split()]
b = 0
s = ''
l = 0
r = n - 1
n1 = 0
while l <= r and (a[l] > b or a[r] > b):
	if a[l] < a[r]:
		if a[l] > b:
			b = a[l]
			n1 += 1
			l += 1
			s += 'L'
		else:
			b = a[r]
			n1 += 1
			r -= 1
			s += 'R'
	elif a[r] < a[l]:
		if a[r] > b:
			b = a[r]
			n1 += 1
			r -= 1
			s += 'R'
		else:
			b = a[l]
			n1 += 1
			l += 1
			s += 'L'
	else:
		n2 = count(b, 'L', r)
		n3 = count(b, 'R', l)
		if n3 > n2:
			n1 += n3
			s += n3 * 'L'
			break
		else:
			n1 += n2
			s += n2 * 'R'
			break
print(n1)
print(s)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	(l, r) = (0, n - 1)
	last = 0
	s = ''
	while True:
		if l > r or last > max(arr[l], arr[r]):
			break
		elif arr[l] > arr[r] and arr[r] > last or arr[r] > last > arr[l]:
			last = arr[r]
			r -= 1
			s += 'R'
		else:
			last = arr[l]
			l += 1
			s += 'L'
	print(len(s))
	print(s)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
num = list(map(int, input().split()))
c = -1
t = ''
l = 0
r = n - 1
tl = ''
tr = ''
while l <= r:
	maxA = max(num[l], num[r], c)
	if maxA == c:
		break
	highVlaue = max(num[l], num[r])
	next = max(min(num[l], num[r]), c)
	if num[l] == num[r] and l != r:
		c1 = c
		c2 = c
		tl = t
		tr = t
		for i in range(l, r):
			if num[i] > c1:
				tl += 'L'
				c1 = num[i]
			else:
				break
		for i in range(r, l, -1):
			if num[i] > c2:
				tr += 'R'
				c2 = num[i]
			else:
				break
		break
	if next == c:
		if num[l] == highVlaue:
			t += 'L'
			l += 1
		else:
			t += 'R'
			r -= 1
		c = highVlaue
	elif num[l] == next:
		t += 'L'
		l += 1
		c = next
	else:
		t += 'R'
		c = next
		r -= 1
arr = [[len(t), t], [len(tl), tl], [len(tr), tr]]
arr.sort()
print(arr[-1][0])
print(arr[-1][1])


n_len = int(input())
n = list(map(int, input().split()))
start = 0
end = n_len - 1
ans = [-1]
direction = []
while ans[len(ans) - 1] < n[start] or ans[len(ans) - 1] < n[end]:
	last_item = ans[len(ans) - 1]
	s = n[start]
	e = n[end]
	if s == e:
		if last_item < s:
			ans.append(s)
			start += 1
			direction.append('L')
			break
		else:
			break
	if s < last_item and e < last_item:
		break
	if s < e and last_item < s:
		ans.append(s)
		start += 1
		direction.append('L')
	elif e < s and last_item < e:
		ans.append(e)
		end -= 1
		direction.append('R')
	elif e > last_item and s < last_item:
		ans.append(e)
		end -= 1
		direction.append('R')
	elif s > last_item and e < last_item:
		ans.append(s)
		start += 1
		direction.append('L')
print(len(ans) - 1)
print(*direction, sep='')


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
ot = []
prot = ''
if a[l] < a[r]:
	ot.append(a[l])
	l += 1
	prot += 'L'
else:
	ot.append(a[r])
	r -= 1
	prot += 'R'
run = True
while run:
	if l > r:
		run = False
	elif l == r:
		if a[l] >= ot[-1]:
			prot += 'R'
		run = False
	elif ot[-1] <= a[l] <= a[r]:
		ot.append(a[l])
		l += 1
		prot += 'L'
	elif ot[-1] <= a[r] <= a[l]:
		ot.append(a[r])
		r -= 1
		prot += 'R'
	elif ot[-1] <= a[l]:
		ot.append(a[l])
		l += 1
		prot += 'L'
	elif ot[-1] <= a[r]:
		ot.append(a[r])
		r -= 1
		prot += 'R'
	else:
		run = False
print(len(prot))
print(prot)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
else:
	_str = str
	str = lambda x=b'': x if type(x) is bytes else _str(x).encode()

def main():
	n = int(readline())
	a = deque(readlist())
	(res, seq) = ([], [0])
	while a:
		if len(a) == 1 and a[0] > seq[-1]:
			seq.append(a.pop())
			res.append('R')
		elif a[0] < a[-1] and a[0] > seq[-1]:
			seq.append(a.popleft())
			res.append('L')
		elif a[-1] < a[0] and a[-1] > seq[-1]:
			seq.append(a.pop())
			res.append('R')
		elif a[0] == a[-1] and a[0] > seq[-1]:
			(case_1, case_2) = (1, 1)
			start = a[0]
			i = 1
			while i < len(a) and a[i] > start:
				start = a[i]
				i += 1
				case_1 += 1
			start = a[-1]
			i = len(a) - 2
			while i >= 0 and a[i] > start:
				start = a[i]
				i -= 1
				case_2 += 1
			res += ['L'] * case_1 if case_1 > case_2 else ['R'] * case_2
			break
		elif a[0] > seq[-1]:
			seq.append(a.popleft())
			res.append('L')
		elif a[-1] > seq[-1]:
			seq.append(a.pop())
			res.append('R')
		else:
			break
	print(len(res))
	print(''.join(res))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._buffer = BytesIO()
		self._fd = file.fileno()
		self._writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self._buffer.write if self._writable else None

	def read(self):
		if self._buffer.tell():
			return self._buffer.read()
		return os.read(self._fd, os.fstat(self._fd).st_size)

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self._buffer.tell()
			(self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr))
		self.newlines -= 1
		return self._buffer.readline()

	def flush(self):
		if self._writable:
			os.write(self._fd, self._buffer.getvalue())
			(self._buffer.truncate(0), self._buffer.seek(0))

class ostream:

	def __lshift__(self, a):
		if a is endl:
			sys.stdout.write(b'\n')
			sys.stdout.flush()
		else:
			sys.stdout.write(str(a))
		return self

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', b' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', b'\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
(cout, endl) = (ostream(), object())
readline = sys.stdin.readline
readlist = lambda var=int: [var(n) for n in readline().split()]
input = lambda : readline().rstrip(b'\r\n')
main()


n = int(input())
num = list(map(int, input().split()))
c = -1
t = ''
l = 0
r = n - 1
while l <= r:
	maxA = max(num[l], num[r], c)
	if maxA == c:
		break
	highVlaue = max(num[l], num[r])
	next = max(min(num[l], num[r]), c)
	if next == c:
		if num[l] == highVlaue:
			t += 'L'
			l += 1
		else:
			t += 'R'
			r -= 1
		c = highVlaue
	elif num[l] == next:
		t += 'L'
		l += 1
		c = next
	else:
		t += 'R'
		c = next
		r -= 1
print(len(t))
print(t)


n = int(input())
a = [int(x) for x in input().split()]
(i, j) = (0, len(a) - 1)
cur_min = float('-inf')
dirs = []
while i <= j:
	if a[i] <= a[j]:
		if a[i] > cur_min:
			cur_min = a[i]
			dirs.append('L')
			i += 1
		elif a[j] > cur_min:
			cur_min = a[j]
			dirs.append('R')
			j -= 1
		else:
			break
	elif a[j] > cur_min:
		cur_min = a[j]
		dirs.append('R')
		j -= 1
	elif a[i] > cur_min:
		cur_min = a[i]
		dirs.append('L')
		i += 1
	else:
		break
print(len(dirs))
print(''.join(dirs))


N = int(input())
numbers = list(map(int, input().split(' ')))
lastElement = 0
moves = []
lowIndex = 0
highIndex = len(numbers) - 1
while True:
	if lowIndex > highIndex:
		break
	availableLow = numbers[lowIndex] > lastElement
	availableHigh = numbers[highIndex] > lastElement
	if not availableLow and (not availableHigh):
		break
	if not availableHigh or (availableLow and numbers[lowIndex] <= numbers[highIndex]):
		moves += ['L']
		lastElement = numbers[lowIndex]
		lowIndex += 1
		continue
	if not availableLow or (availableHigh and numbers[highIndex] < numbers[lowIndex]):
		moves += ['R']
		lastElement = numbers[highIndex]
		highIndex -= 1
		continue
print(len(moves))
print(''.join(moves))


import sys
from collections import deque
input = sys.stdin.readline

def main():
	_ = int(input())
	q = deque(map(int, input().split()))
	lst = 0
	ans = []
	while q[0] != q[-1]:
		t = []
		if q[0] > lst:
			t.append(0)
		if q[-1] > lst:
			t.append(-1)
		if not t:
			break
		idx = min(t, key=lambda x: q[x])
		lst = q[idx]
		if idx == 0:
			ans.append('L')
			q.popleft()
		else:
			ans.append('R')
			q.pop()
	cpq = deque(q)
	lft = []
	c_lst = lst
	while cpq and cpq[0] > c_lst:
		c_lst = cpq[0]
		lft.append('L')
		cpq.popleft()
	cpq = deque(q)
	rgt = []
	c_lst = lst
	while cpq and cpq[-1] > c_lst:
		c_lst = cpq[-1]
		rgt.append('R')
		cpq.pop()
	if len(lft) < len(rgt):
		(lft, rgt) = (rgt, lft)
	ans += lft
	print(len(ans))
	print(''.join(ans))
main()


n = int(input())
lst = list(map(int, input().split()))
(mn, i, j, k, res) = (3000000, 0, n - 1, -1, '')
while mn != -1:
	(x, y) = (lst[i], lst[j])
	if max(x, y) < k:
		mn = -1
		continue
	elif i == j:
		res += 'L'
		break
	else:
		if x > y:
			if y > k:
				res += 'R'
				k = y
				j -= 1
			else:
				res += 'L'
				k = x
				i += 1
		if y > x:
			if x > k:
				res += 'L'
				k = x
				i += 1
			else:
				res += 'R'
				k = y
				j -= 1
print(len(res))
print(res)


n = int(input())
l = list(map(int, input().split()))
ans = []
j = 0
k = n
seq = [0]
if n == 1:
	print(1)
	print('L')
else:
	while j < k:
		if l[j] == l[k - 1]:
			break
		elif l[j] < l[k - 1] and l[j] > seq[-1]:
			seq.append(l[j])
			j += 1
			ans.append('L')
		elif l[k - 1] > seq[-1]:
			seq.append(l[k - 1])
			k -= 1
			ans.append('R')
		else:
			break
	one_sec = seq[:]
	two_sec = seq[:]
	one_ans = ans[:]
	two_ans = ans[:]
	i = j
	while i < k and one_sec[-1] < l[i]:
		one_sec.append(l[i])
		i += 1
		one_ans.append('L')
	i = k - 1
	while i > j and two_sec[-1] < l[i]:
		two_sec.append(l[i])
		i -= 1
		two_ans.append('R')
	if len(one_ans) > len(two_ans):
		print(len(one_ans))
		print(*one_ans, sep='')
	else:
		print(len(two_ans))
		print(*two_ans, sep='')


n = int(input())
a = [int(_) for _ in input().split(' ')]
(s, left, right, last) = ('', 0, n - 1, 0)
while left <= right:
	min_value = min(a[left], a[right])
	max_value = max(a[left], a[right])
	if min_value == max_value:
		if min_value > last:
			(l, r) = (left + 1, right - 1)
			(left_len, right_len) = (1, 1)
			while l <= right:
				if a[l] > a[l - 1]:
					l += 1
					left_len += 1
				else:
					break
			while r >= left:
				if a[r] > a[r + 1]:
					r -= 1
					right_len += 1
				else:
					break
			if left_len >= right_len:
				s = s + 'L' * left_len
			else:
				s = s + 'R' * right_len
		break
	elif max_value <= last:
		break
	elif min_value > last:
		if a[left] == min_value:
			s = s + 'L'
			left += 1
			last = min_value
		else:
			s = s + 'R'
			right -= 1
			last = min_value
	elif a[left] == max_value:
		s = s + 'L'
		left += 1
		last = max_value
	else:
		s = s + 'R'
		right -= 1
		last = max_value
print(len(s))
print(s)


from collections import deque
n = int(input())
l = list(map(int, input().split()))
l = deque(l)
x = 0
a = []
while len(l) > 0:
	if l[0] > x and l[-1] > x:
		if l[0] < l[-1]:
			x = l.popleft()
			a.append('L')
		elif l[0] >= l[-1]:
			x = l.pop()
			a.append('R')
	elif l[0] > x:
		x = l.popleft()
		a.append('L')
	elif l[-1] > x:
		x = l.pop()
		a.append('R')
	else:
		break
print(n - len(l))
print(''.join(a))


from sys import *
from math import *
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
x = 0
s = []
j = 0
l = n - 1
for i in range(n):
	f = 0
	if a[j] < a[l]:
		if a[j] > x:
			x = a[j]
			s.append('L')
			f = 1
			j += 1
		elif a[l] > x:
			x = a[l]
			l -= 1
			s.append('R')
			f = 1
	elif a[l] > x:
		x = a[l]
		l -= 1
		s.append('R')
		f = 1
	elif a[j] > x:
		x = a[j]
		s.append('L')
		f = 1
		j += 1
	if f == 0:
		break
print(len(s))
print(*s, sep='')


n = int(input())
a = list(map(int, input().split()))
k = 0
ops = []

def search(left, right, k, last, res):
	while left <= right:
		if a[left] <= last and a[right] <= last:
			break
		if a[right] > last and (left == right or a[left] <= last or a[right] < a[left]):
			res.append('R')
			k += 1
			last = a[right]
			right -= 1
		elif a[left] > last and (a[left] < a[right] or a[right] <= last):
			res.append('L')
			k += 1
			last = a[left]
			left += 1
		else:
			k = max(search(left, right - 1, k + 1, a[right], res + ['R']), search(left + 1, right, k + 1, a[left], res + ['L']))
			break
	global ops
	if len(res) > len(ops):
		ops = res[:]
	return k
k = search(0, n - 1, 0, 0, [])
print(k)
print(''.join(map(str, ops)))


from sys import stdin, stdout
input = stdin.readline

def search(l, r, out):
	c1 = 1
	c2 = 1
	for i in range(l + 1, r):
		if a[i] > a[i - 1]:
			c1 += 1
		else:
			break
	for i in range(r - 1, l, -1):
		if a[i] > a[i + 1]:
			c2 += 1
		else:
			break
	if c2 > c1:
		out += 'R' * c2
	else:
		out += 'L' * c1
	return out
n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
out = ''
m = min(a[l], a[r]) - 1
while l != r:
	if a[l] == a[r] and a[l] > m:
		out = search(l, r, out)
		break
	elif a[l] < a[r] and a[l] > m:
		out += 'L'
		m = a[l]
		l += 1
	elif a[l] > a[r] and a[r] > m:
		out += 'R'
		m = a[r]
		r -= 1
	elif a[l] > m:
		out += 'L'
		m = a[l]
		l += 1
	elif a[r] > m:
		out += 'R'
		m = a[r]
		r -= 1
	else:
		break
if l == r:
	if a[l] < a[r] and a[l] > m:
		out += 'L'
	elif a[l] > a[r] and a[r] > m:
		out += 'R'
	elif a[l] > m:
		out += 'L'
	elif a[r] > m:
		out += 'R'
print(str(len(out)))
print(out)


n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(1)
	print('L')
else:
	(L, R) = (0, n - 1)
	ele = []
	st = ''
	while L <= R:
		if ele == []:
			if arr[L] <= arr[R]:
				ele = arr[L]
				L += 1
				st += 'L'
			else:
				ele = arr[R]
				R -= 1
				st += 'R'
		elif arr[L] <= arr[R] and arr[L] > ele:
			ele = arr[L]
			L += 1
			st += 'L'
		elif arr[R] <= arr[L] and arr[R] > ele:
			ele = arr[R]
			R -= 1
			st += 'R'
		else:
			m = max(arr[L], arr[R])
			if m > ele:
				ele = m
				if m == arr[L]:
					L += 1
					st += 'L'
				else:
					R -= 1
					st += 'R'
			else:
				break
	print(len(st))
	print(st)


n = int(input())
a = list(map(int, input().split()))
r = []
lastNum = -1
lPos = 0
rPos = n - 1
while lPos < rPos:
	if a[lPos] < a[rPos] and a[lPos] > lastNum:
		r.append('L')
		lastNum = a[lPos]
		lPos += 1
		continue
	if a[lPos] < a[rPos] and a[lPos] < lastNum and (a[rPos] > lastNum):
		r.append('R')
		lastNum = a[rPos]
		rPos -= 1
		continue
	if a[lPos] > a[rPos] and a[rPos] > lastNum:
		r.append('R')
		lastNum = a[rPos]
		rPos -= 1
		continue
	if a[lPos] > a[rPos] and a[rPos] < lastNum and (a[lPos] > lastNum):
		r.append('L')
		lastNum = a[lPos]
		lPos += 1
		continue
	if a[lPos] < lastNum and a[rPos] < lastNum:
		break
if lPos == rPos and a[lPos] > lastNum:
	r.append('L')
print(len(r))
print(*r, sep='')


n = int(input())
a = list(map(int, input().split()))
res = []
num = []
l = a[0]
r = a[-1]
if l < r:
	num.append(l)
	res.append('L')
	a.pop(0)
else:
	num.append(r)
	res.append('R')
	a.pop(-1)
if n == 1:
	print(1)
	print(res[0])
elif n == 2:
	if a[0] > num[-1]:
		res.append('R')
	print(len(res))
	print(''.join(res))
else:
	(i, j, k) = (0, 0, 0)
	while True:
		l = a[i]
		r = a[-j - 1]
		if r > num[-1] and r <= l or (r > num[-1] and l <= num[-1]):
			res.append('R')
			num.append(r)
			j += 1
		elif l > num[-1] and l < r or (l > num[-1] and r < num[-1]):
			res.append('L')
			num.append(l)
			i += 1
		else:
			break
		if i + j == n - 1:
			break
	print(len(res))
	print(''.join(res))


n = int(input())
a = list(map(int, input().split()))
left = 0
right = n - 1
prev = 0
b = []
d = []
while left <= right:
	cand = []
	for i in [left, right]:
		if a[i] > prev:
			cand.append(i)
	if len(cand) == 0:
		break
	if len(cand) == 1:
		b.append(a[cand[0]])
	elif a[left] < a[right]:
		b.append(a[left])
	else:
		b.append(a[right])
	if b[-1] == a[right]:
		right -= 1
		d.append('R')
	else:
		left += 1
		d.append('L')
	prev = b[-1]
k = n - (right + 1 - left)
print(k)
print(''.join(d))


from math import *
n = int(input())
a = list(map(int, input().split(' ')))
i = 0
j = n - 1
l = []
curr = 0
while i <= j:
	if a[i] > a[j]:
		if a[j] > curr:
			curr = a[j]
			l.append('R')
			j -= 1
		elif a[i] > curr:
			curr = a[i]
			l.append('L')
			i += 1
		else:
			break
	elif a[j] > a[i]:
		if a[i] > curr:
			curr = a[i]
			l.append('L')
			i += 1
		elif a[j] > curr:
			curr = a[j]
			l.append('R')
			j -= 1
		else:
			break
	elif i == j:
		if a[i] > curr:
			l.append('L')
			i += 1
			j -= 1
		break
print(len(l))
for i in l:
	print(i, end='')
print()


ri = lambda : int(input())
ric = lambda : list(map(int, input().split()))
pc = lambda c: print(''.join(map(str, c)))
pcr = lambda c: print(' '.join(map(str, c)))
from collections import deque

def main():
	n = ri()
	m = deque(ric())
	s = ''
	tmp = -1
	while len(m) > 1 and max(m[0], m[-1]) > tmp:
		if m[0] > tmp:
			if m[0] < m[-1] or m[-1] < tmp:
				tmp = m[0]
				m.popleft()
				s += 'L'
			else:
				tmp = m[-1]
				m.pop()
				s += 'R'
		else:
			tmp = m[-1]
			m.pop()
			s += 'R'
	if m[0] > tmp:
		s += 'R'
	print(len(s))
	print(s)
	return 0
main()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		a = li()
		l = 0
		r = n - 1
		cc = 0
		pp = []
		last = 0
		while l <= r:
			cc += 1
			if a[l] > last and a[r] > last:
				if a[l] < a[r]:
					last = a[l]
					l += 1
					pp.append('L')
				elif a[l] > a[r]:
					last = a[r]
					r -= 1
					pp.append('R')
				else:
					break
				continue
			elif a[l] > last:
				last = a[l]
				l += 1
				pp.append('L')
				continue
			elif a[r] > last:
				last = a[r]
				r -= 1
				pp.append('R')
				continue
			break
		if a[l] == a[r] and a[l] > last:
			zp = []
			vc = []
			op = l
			oi = r
			lul = last
			while op <= r and a[op] > lul:
				lul = a[op]
				op += 1
				zp.append('L')
			lul = last
			while oi >= l and a[oi] > lul:
				lul = a[oi]
				oi -= 1
				vc.append('R')
			if len(zp) >= len(vc):
				pp += zp
			else:
				pp += vc
		print(len(pp))
		print(*pp, sep='')
solve()


n = int(input())
a = list(map(int, input().split()))
start = 0
end = n - 1
count = 0
prev = 0
if a[start] < a[end]:
	prev = a[start]
	start += 1
	count += 1
elif a[end] < a[start]:
	prev = a[end]
	end -= 1
	count += 1
while start <= end:
	if start == end:
		if a[start] > prev:
			count += 1
		break
	if a[start] < a[end]:
		if a[start] > prev:
			prev = a[start]
			start += 1
			count += 1
		elif a[end] > prev:
			prev = a[end]
			end -= 1
			count += 1
		else:
			break
	elif a[end] < a[start]:
		if a[end] > prev:
			prev = a[end]
			end -= 1
			count += 1
		elif a[start] > prev:
			prev = a[start]
			start += 1
			count += 1
		else:
			break
	else:
		break
print(count)
start = 0
end = n - 1
count = 0
prev = 0
if a[start] < a[end]:
	prev = a[start]
	start += 1
	count += 1
	print('L', end='')
elif a[end] < a[start]:
	prev = a[end]
	end -= 1
	count += 1
	print('R', end='')
while start <= end:
	if start == end:
		if a[start] > prev:
			count += 1
			print('L', end='')
		break
	if a[start] < a[end]:
		if a[start] > prev:
			prev = a[start]
			start += 1
			count += 1
			print('L', end='')
		elif a[end] > prev:
			prev = a[end]
			end -= 1
			count += 1
			print('R', end='')
		else:
			break
	elif a[end] < a[start]:
		if a[end] > prev:
			prev = a[end]
			end -= 1
			count += 1
			print('R', end='')
		elif a[start] > prev:
			prev = a[start]
			start += 1
			count += 1
			print('L', end='')
		else:
			break
	else:
		break


n = int(input())
a = [int(x) for x in input().split()]
lg = 0
k = 0
rg = n - 1
lst = -1
b = []
while rg >= lg:
	l = a[lg]
	r = a[rg]
	s = min(l, r)
	if s == l:
		lg += 1
	else:
		rg -= 1
	if s > lst:
		lst = s
		if s == l:
			b.append('L')
		else:
			b.append('R')
		k += 1
	else:
		if s == l:
			s = r
			lg -= 1
			rg -= 1
		else:
			s = l
			lg += 1
			rg += 1
		if s > lst:
			lst = s
			k += 1
			if s == l:
				b.append('L')
			else:
				b.append('R')
		else:
			print(k)
			for i in b:
				print(i, end='')
			exit()
print(k)
for i in b:
	print(i, end='')


n = int(input())
a = [int(x) for x in input().split()]
s = []
l = 0
r = n - 1
m = 0
while l <= r:
	if a[l] > m and a[l] < a[r]:
		m = a[l]
		l += 1
		s.append('L')
	elif a[r] > m:
		m = a[r]
		r -= 1
		s.append('R')
	elif a[l] > m:
		m = a[l]
		l += 1
		s.append('L')
	elif a[l] < m and a[r] < m:
		break
print(len(s))
print(''.join(s))


n = int(input())
a = [int(i) for i in input().split()]
b = []
s = ''
l = 0
r = n - 1
if a[0] < a[-1]:
	b.append(a[0])
	s += 'L'
	l += 1
else:
	b.append(a[-1])
	s += 'R'
	r -= 1
while len(a) > 0 and (a[l] > b[-1] or a[r] > b[-1]):
	if a[l] < a[r]:
		if a[l] > b[-1]:
			b.append(a[l])
			l += 1
			s += 'L'
		else:
			b.append(a[r])
			r -= 1
			s += 'R'
	elif a[r] > b[-1]:
		b.append(a[r])
		r -= 1
		s += 'R'
	else:
		b.append(a[l])
		l += 1
		s += 'L'
print(len(b))
print(s)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
ans = ''
cur = 0
while l <= r:
	(l1, r1) = (l, r)
	if cur < a[l1] and cur < a[r1]:
		if a[r1] >= a[l1]:
			ans += 'L'
			cur = a[l1]
			l1 += 1
		elif a[r1] <= a[l1]:
			ans += 'R'
			cur = a[r1]
			r1 -= 1
	elif cur < a[l1]:
		ans += 'L'
		cur = a[l1]
		l1 += 1
	elif cur < a[r1]:
		ans += 'R'
		cur = a[r1]
		r1 -= 1
	if l1 == l and r1 == r:
		break
	l = l1
	r = r1
print(len(ans))
print(ans)


import sys
import collections
from math import floor, ceil, log2
inp = lambda : sys.stdin.readline().strip()
n = int(inp())
a = list(map(int, inp().split()))
(l, r) = (0, n - 1)
s = ''
e = 0
while l <= r:
	if a[l] <= a[r] and a[l] > e:
		s += 'L'
		e = a[l]
		l += 1
	elif a[l] <= a[r] and a[r] > e:
		s += 'R'
		e = a[r]
		r -= 1
	elif a[l] >= a[r] and a[r] > e:
		s += 'R'
		e = a[r]
		r -= 1
	elif a[l] >= a[r] and a[l] > e:
		s += 'L'
		e = a[l]
		l += 1
	elif a[l] <= e and a[r] < e:
		break
print(len(s))
print(s)


l = 'L'
r = 'R'
n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
ln = 0
curr = -1
st = []
while i <= j:
	if a[i] < a[j]:
		if curr < a[i]:
			st.append(l)
			curr = a[i]
			i += 1
		elif curr < a[j]:
			st.append(r)
			curr = a[j]
			j -= 1
		else:
			break
	elif a[j] < a[i]:
		if curr < a[j]:
			st.append(r)
			curr = a[j]
			j -= 1
		elif curr < a[i]:
			st.append(l)
			curr = a[i]
			i += 1
		else:
			break
	else:
		if curr > a[j]:
			break
		ll = 1
		i_ = i + 1
		while i_ < j and a[i_] > a[i_ - 1]:
			ll += 1
			i_ += 1
		lr = 1
		j_ = j - 1
		while i < j_ and a[j_ + 1] < a[j_]:
			lr += 1
			j_ -= 1
		if ll > lr:
			for ii in range(ll):
				st.append(l)
		else:
			for ii in range(lr):
				st.append(r)
		break
print(len(st))
print(''.join(st))


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
n = INI()
A = INL()
ans = ''
if A[0] < A[-1]:
	ans += 'L'
	i = 1
	j = n - 1
else:
	ans += 'R'
	i = 0
	j = n - 2
while i <= j:
	if ans[-1] == 'L':
		if A[i] < A[j]:
			if A[i - 1] < A[i]:
				ans += 'L'
				i += 1
			elif A[i - 1] < A[j]:
				ans += 'R'
				j -= 1
			else:
				break
		elif A[i - 1] < A[j]:
			ans += 'R'
			j -= 1
		elif A[i - 1] < A[i]:
			ans += 'L'
			i += 1
		else:
			break
	elif A[i] < A[j]:
		if A[j + 1] < A[i]:
			ans += 'L'
			i += 1
		elif A[j + 1] < A[j]:
			ans += 'R'
			j -= 1
		else:
			break
	elif A[j + 1] < A[j]:
		ans += 'R'
		j -= 1
	elif A[j + 1] < A[i]:
		ans += 'L'
		i += 1
	else:
		break
OPS(len(ans))
OPS(ans)


import sys
import collections

def solve():
	N = int(sys.stdin.readline().rstrip())
	A = list(map(int, sys.stdin.readline().rstrip().split()))
	q = collections.deque(A)
	ans = []
	old = 0
	for i in range(N - 1):
		l = q.popleft()
		r = q.pop()
		if l < r:
			if old < l:
				old = l
				ans.append('L')
				q.append(r)
			elif old < r:
				old = r
				ans.append('R')
				q.appendleft(l)
			else:
				break
		elif old < r:
			old = r
			ans.append('R')
			q.appendleft(l)
		elif old < l:
			old = l
			ans.append('L')
			q.append(r)
		else:
			break
	else:
		r = q.pop()
		if old < r:
			old = r
			ans.append('R')
	print(len(ans))
	print(''.join(ans))
solve()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	last = -1
	anz = []
	while i != j:
		if a[i] < a[j]:
			if a[i] > last:
				last = a[i]
				i += 1
				anz.append('L')
			elif a[j] > last:
				last = a[j]
				j -= 1
				anz.append('R')
			else:
				break
		elif a[j] > last:
			last = a[j]
			j -= 1
			anz.append('R')
		elif a[i] > last:
			last = a[i]
			i += 1
			anz.append('L')
		else:
			break
	if i == j and a[i] > last:
		anz.append('R')
	print(len(anz))
	for elem in anz:
		print(elem, end='')
main()


R = lambda : map(int, input().split())
(n, a) = (int(input()), list(R()))
res = []
(i, j) = (0, n - 1)
v = 0
while i <= j:
	if a[i] > v and (a[j] > a[i] or a[j] <= v):
		res.append('L')
		v = a[i]
		i += 1
	elif a[j] > v:
		res.append('R')
		v = a[j]
		j -= 1
	else:
		break
res = ''.join(res)
print(len(res))
print(res)


import math
n = int(input())
lst = list(map(int, input().strip().split(' ')))
i1 = 0
i2 = n - 1
l = []
ln = []
while i1 < n and i2 >= 0:
	if i1 == i2 and (i2 == n - 1 or i1 == 0):
		l.append('L')
		break
	elif i1 == 0 and i2 == n - 1:
		if lst[i1] < lst[i2]:
			ln.append(lst[i1])
			i1 += 1
			l.append('L')
		else:
			ln.append(lst[i2])
			i2 -= 1
			l.append('R')
	elif lst[i1] < lst[i2]:
		if lst[i1] > ln[-1]:
			ln.append(lst[i1])
			l.append('L')
			i1 += 1
		elif lst[i2] > ln[-1]:
			ln.append(lst[i2])
			l.append('R')
			i2 -= 1
		else:
			break
	elif lst[i2] > ln[-1]:
		ln.append(lst[i2])
		l.append('R')
		i2 -= 1
	elif lst[i1] > ln[-1]:
		ln.append(lst[i1])
		l.append('L')
		i1 += 1
	else:
		break
print(len(l))
for j in range(len(l)):
	print(l[j], end='')


n = int(input())
arr = list(map(int, input().split()))
ans = ''
l = 0
r = n - 1
prev = -10
if arr[l] < arr[r]:
	prev = arr[l]
	l += 1
	ans += 'L'
else:
	prev = arr[r]
	ans += 'R'
	r -= 1
k = 1
while True and k < n:
	if arr[l] < prev and arr[r] < prev:
		break
	elif arr[l] > prev and arr[r] > prev:
		if arr[l] < arr[r]:
			ans += 'L'
			prev = arr[l]
			l += 1
		else:
			ans += 'R'
			prev = arr[r]
			r -= 1
	elif arr[l] > prev:
		ans += 'L'
		prev = arr[l]
		l += 1
	elif arr[r] > prev:
		ans += 'R'
		prev = arr[r]
		r -= 1
	k += 1
print(len(ans))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = n - 1
prev = -1
ans = []
while i <= j:
	if a[i] < a[j]:
		if a[i] > prev:
			ans += 'L'
			prev = a[i]
			i += 1
		elif a[j] > prev:
			ans += 'R'
			prev = a[j]
			j -= 1
		else:
			break
	elif a[i] > a[j]:
		if a[j] > prev:
			ans += 'R'
			prev = a[j]
			j -= 1
		elif a[i] > prev:
			ans += 'L'
			prev = a[i]
			i += 1
		else:
			break
	elif a[i] > prev:
		l = 0
		for p in range(i + 1, j):
			if a[p] > a[p - 1]:
				l += 1
			else:
				break
		r = 0
		for p in range(j - 1, i, -1):
			if a[p] > a[p + 1]:
				r += 1
			else:
				break
		if r > l:
			ans += 'R' * (r + 1)
			prev = a[j]
			j -= 1
		else:
			ans += 'L' * (l + 1)
			prev = a[i]
			i += 1
		break
	else:
		break
print(len(ans))
print(*ans, sep='')


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
res = []
cur = 0
left = 0
right = n - 1
while left <= right:
	if cur < min(a[left], a[right]):
		cur = min(a[left], a[right])
		if a[left] < a[right]:
			left += 1
			res.append('L')
		else:
			right -= 1
			res.append('R')
	elif cur < max(a[left], a[right]):
		cur = max(a[left], a[right])
		if a[left] > a[right]:
			left += 1
			res.append('L')
		else:
			right -= 1
			res.append('R')
	else:
		break
print(len(res))
print(''.join(res))


numero = int(input())
pos = []
contador = 0
lista = [int(x) for x in input().split()]
if len(lista) == 1:
	pos.append('R')
	contador += 1
	print(contador)
	for x in pos:
		print(x, end='')
	print()
	quit()
if lista[0] > lista[len(lista) - 1]:
	pos.append('R')
	menor = lista.pop(len(lista) - 1)
else:
	pos.append('L')
	menor = lista.pop(0)
contador += 1
inicio = 0
fim = len(lista) - 1
tamanho = len(lista)
while True:
	if tamanho == 1:
		if lista[inicio] > menor:
			contador += 1
			pos.append('L')
			break
		else:
			break
	if lista[inicio] > lista[fim] and lista[fim] > menor:
		pos.append('R')
		menor = lista[fim]
		fim = fim - 1
		tamanho -= 1
	elif lista[inicio] < lista[fim] and lista[inicio] > menor:
		pos.append('L')
		menor = lista[inicio]
		inicio += 1
		tamanho -= 1
	elif lista[inicio] > lista[fim] and lista[inicio] > menor:
		pos.append('L')
		menor = lista[inicio]
		inicio += 1
		tamanho -= 1
	elif lista[inicio] < lista[fim] and lista[fim] > menor:
		pos.append('R')
		menor = lista[fim]
		fim = fim - 1
		tamanho -= 1
	else:
		break
	contador += 1
print(contador)
for x in pos:
	print(x, end='')
print()


n = int(input())
l = list(map(int, input().split()))
inn = 0
ex = n - 1
pr = 0
su = 0
ll = ''
lol = 0
while inn <= ex:
	if inn == ex:
		if l[inn] > pr:
			ll += 'L'
			su += 1
			break
	if l[inn] <= pr and l[ex] <= pr:
		break
	if l[inn] > pr and l[ex] > pr and (l[inn] == l[ex]):
		lol = 1
		j = inn
		k = ex
		s1 = ''
		cou1 = 0
		s2 = ''
		cou2 = 0
		pr1 = pr
		pr2 = pr
		while j < ex and l[j] > pr1:
			pr1 = l[j]
			cou1 += 1
			s1 += 'L'
			j += 1
		while k > inn and l[k] > pr2:
			pr2 = l[k]
			cou2 += 1
			s2 += 'R'
			k -= 1
		break
	if l[inn] > pr and l[ex] <= pr:
		su += 1
		ll += 'L'
		pr = l[inn]
		inn += 1
	elif l[inn] <= pr and l[ex] > pr:
		su += 1
		ll += 'R'
		pr = l[ex]
		ex -= 1
	elif l[inn] > pr and l[ex] > pr:
		if l[inn] > l[ex]:
			su += 1
			pr = l[ex]
			ex -= 1
			ll += 'R'
		elif l[inn] < l[ex]:
			su += 1
			pr = l[inn]
			ll += 'L'
			inn += 1
if lol == 1:
	if cou1 >= cou2:
		su += cou1
		ll += s1
	else:
		su += cou2
		ll += s2
print(su)
print(ll)


n = int(input())
arr = [int(z) for z in input().split()]
cnt = 0
res = []
m = 0
(rdepth, ldepth) = (1, 0)
while True:
	if ldepth + rdepth > n or (arr[ldepth] <= m and arr[n - rdepth] <= m):
		break
	if m < arr[ldepth] <= arr[n - rdepth]:
		m = arr[ldepth]
		ldepth += 1
		res.append('L')
	elif m < arr[n - rdepth] <= arr[ldepth]:
		m = arr[n - rdepth]
		rdepth += 1
		res.append('R')
	elif m < arr[ldepth]:
		m = arr[ldepth]
		ldepth += 1
		res.append('L')
	elif m < arr[n - rdepth]:
		m = arr[n - rdepth]
		rdepth += 1
		res.append('R')
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
s = list(map(int, input().split()))
t = 0
ans = ''
l = 0
r = n - 1
while l <= r:
	if t < s[l] < s[r]:
		ans += 'L'
		t = s[l]
		l += 1
	elif t < s[r] < s[l]:
		ans += 'R'
		t = s[r]
		r -= 1
	elif t < s[l]:
		ans += 'L'
		t = s[l]
		l += 1
	elif t < s[r]:
		ans += 'R'
		t = s[r]
		r -= 1
	else:
		break
print(len(ans))
print(ans)


r = int(input()) - 1
a = (*map(int, input().split()),)
s = ''
l = e = 0
while l <= r and max(a[l], a[r]) > e:
	(L, R) = (a[l], a[r])
	if L > e > R or R > L > e:
		e = L
		l += 1
		s += 'L'
	else:
		e = R
		r -= 1
		s += 'R'
print(len(s), s)


N = int(input())
queue = list(map(int, input().split()))
t = -90
val = ''
var = 0
pi = list(queue)
pi.sort()
if pi == queue:
	print(len(queue))
	print('L' * len(queue))
else:
	while len(queue) > 0:
		if queue[0] < queue[-1]:
			if queue[0] > t:
				t = queue.pop(0)
				var += 1
				val += 'L'
			elif queue[-1] > t:
				t = queue.pop(-1)
				var += 1
				val += 'R'
			else:
				break
		elif queue[0] > queue[-1]:
			if queue[-1] > t:
				t = queue.pop()
				var += 1
				val += 'R'
			elif queue[0] > t:
				t = queue.pop(0)
				var += 1
				val += 'L'
			else:
				break
		elif queue[0] > t:
			t = queue.pop(0)
			var += 1
			val += 'L'
		else:
			break
	print(var)
	print(val)


def check_l(a, l, r):
	d = 0
	last = 0
	while l <= r and a[l] > last:
		last = a[l]
		l += 1
		d += 1
	return d

def check_r(a, l, r):
	d = 0
	last = 0
	while l <= r and a[r] > last:
		last = a[r]
		r -= 1
		d += 1
	return d

def main():
	input()
	a = [int(x) for x in input().split(' ')]
	n = len(a)
	(l, r) = (0, n - 1)
	res = []
	last = 0
	picked = True
	while l <= r and picked:
		picked = False
		if last < a[l] and last < a[r]:
			if a[l] < a[r]:
				last = a[l]
				res.append('L')
				l += 1
			elif a[l] == a[r]:
				dl = check_l(a, l, r)
				dr = check_r(a, l, r)
				if dl > dr:
					res.extend(['L'] * dl)
					last = a[l + dl - 1]
					l += dl
				else:
					res.extend(['R'] * dr)
					last = a[r - dr + 1]
					r -= dr
			else:
				last = a[r]
				res.append('R')
				r -= 1
			picked = True
			continue
		if last < a[l]:
			last = a[l]
			res.append('L')
			l += 1
			picked = True
			continue
		if last < a[r]:
			last = a[r]
			res.append('R')
			r -= 1
			picked = True
			continue
	print(len(res))
	print(''.join(res))
main()


def function(cheating):
	cheating = 'cheating is a punishable offence'
n = int(input())
arrr = list(map(int, input().split()))
sequence = [0]
move = []
i = 0
j = n - 1
while i != j:
	if arrr[i] >= arrr[j]:
		if arrr[j] > sequence[-1]:
			sequence.append(arrr[j])
			j -= 1
			move.append('R')
		elif arrr[i] > sequence[-1]:
			sequence.append(arrr[i])
			i += 1
			move.append('L')
		else:
			break
	elif arrr[i] > sequence[-1]:
		sequence.append(arrr[i])
		i += 1
		move.append('L')
	elif arrr[j] > sequence[-1]:
		sequence.append(arrr[j])
		j -= 1
		move.append('R')
	else:
		break
if i == j:
	if arrr[i] > sequence[-1]:
		sequence.append(arrr[i])
		move.append('R')
print(len(sequence) - 1)
for i in move:
	print(i, end='')


n = int(input())
array = list(map(int, input().split()))
rr = []
last_element = 0
l = 0
r = n - 1
while max(array[l], array[r]) > last_element and l <= r:
	if last_element < array[l] <= array[r] or array[r] <= last_element:
		rr.append('L')
		last_element = array[l]
		l += 1
		if l > r:
			break
	elif last_element < array[r] <= array[l] or array[l] <= last_element:
		rr.append('R')
		last_element = array[r]
		r -= 1
		if l > r:
			break
	else:
		break
print(len(rr))
print(''.join(rr))


x = int(input())
a = list(map(int, input().strip().split()))
y = []
c = 0
f1 = 1
f2 = 1
l = 0
r = x - 1
op = []
while f1 or f2:
	if l > r:
		break
	if a[l] < c:
		f1 = 0
	if a[r] < c:
		f2 = 0
	if f1 and f2:
		if a[l] <= a[r]:
			c = a[l]
			l = l + 1
			op.append('L')
		else:
			c = a[r]
			r = r - 1
			op.append('R')
	elif f1:
		c = a[l]
		l = l + 1
		op.append('L')
	elif f2:
		c = a[r]
		r = r - 1
		op.append('R')
print(len(op))
print(''.join(op))


n = int(input())
arr = [int(x) for x in input().split()]
ans = ''
i = 0
j = n - 1
last = 0
while i <= j:
	if arr[i] > last and arr[j] > last:
		if arr[i] > arr[j]:
			ans += 'R'
			last = arr[j]
			j -= 1
		else:
			ans += 'L'
			last = arr[i]
			i += 1
	elif arr[i] > last:
		ans += 'L'
		last = arr[i]
		i += 1
	elif arr[j] > last:
		ans += 'R'
		last = arr[j]
		j -= 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
a = list(map(int, input().split()))
ma = 0
otv = ''
n -= 1
l = 0
r = n
while r >= l:
	b = a[l]
	c = a[r]
	if b < c and b > ma:
		ma = a[l]
		otv += 'L'
		l += 1
	elif c > ma:
		ma = a[r]
		otv += 'R'
		r -= 1
	elif b > ma:
		ma = a[l]
		otv += 'L'
		l += 1
	else:
		break
print(len(otv))
print(otv)


def solve():
	N = int(input())
	lst = list(map(int, input().split()))
	ans = ''
	if lst.count(lst[0]) == N:
		print('1')
		print('L')
		exit()

	def judge_left(left, rigt, lst):
		left_leng = 1
		rigt_leng = 1
		now_l = lst[left]
		now_r = lst[rigt]
		N = len(lst)
		for (e, l) in enumerate(lst[left + 1:], left + 1):
			if e > rigt:
				break
			if l > now_l:
				left_leng += 1
				now_l = l
			else:
				break
		e = rigt - 1
		l = lst[e]
		while True:
			if e < left:
				break
			if l > now_r:
				rigt_leng += 1
				now_r = l
			else:
				break
			e = e - 1
			l = lst[e]
		if left_leng < rigt_leng:
			return 'RIGHT'
		else:
			return 'LEFT'
	done = 0
	left = 0
	rigt = len(lst) - 1
	while True:
		if left <= rigt:
			(l, r) = (lst[left], lst[rigt])
			if max(l, r) <= done:
				left = rigt + 1
				continue
			elif min(l, r) > done:
				if l == r:
					v_ = judge_left(left, rigt, lst)
					if v_ == 'LEFT':
						left += 1
						done = l
						ans += 'L'
					else:
						rigt -= 1
						done = r
						ans += 'R'
					continue
				elif l < r:
					left += 1
					done = l
					ans += 'L'
					continue
				elif r < l:
					rigt -= 1
					done = r
					ans += 'R'
			elif l > r:
				left += 1
				done = l
				ans += 'L'
			elif r > l:
				rigt -= 1
				done = r
				ans += 'R'
			elif r == l:
				v_ = judge_left(left, rigt, lst)
				if v_ == 'LEFT':
					left += 1
					done = l
					ans += 'L'
				else:
					rigt -= 1
					done = r
					ans += 'R'
				continue
		else:
			print(len(ans))
			print(ans)
			exit()
solve()


import sys

def main():
	n = int(input())
	nums = list(map(int, input().split()))
	(lo, hi) = (0, n - 1)
	cur = 0
	ops = []
	while lo <= hi:
		if nums[lo] <= nums[hi]:
			if nums[lo] > cur:
				cur = nums[lo]
				lo += 1
				ops.append('L')
			elif nums[hi] > cur:
				cur = nums[hi]
				hi -= 1
				ops.append('R')
			else:
				break
		elif nums[hi] > cur:
			cur = nums[hi]
			ops.append('R')
			hi -= 1
		elif nums[lo] > cur:
			cur = nums[lo]
			lo += 1
			ops.append('L')
		else:
			break
	print(len(ops))
	print(''.join(ops))
main()


n = int(input())
a = list(map(int, input().split()))
last = -1
results = []
runer = [0, n - 1]
while runer[1] >= runer[0] and max(a[runer[0]], a[runer[1]]) > last:
	if a[runer[0]] == a[runer[1]]:
		cat1 = [0, 0]
		bound = [[runer[0], runer[1] + 1, 1], [runer[1], runer[0] - 1, -1]]
		for j in range(2):
			lst = last
			for i in range(*bound[j]):
				if a[i] <= lst:
					break
				cat1[j] += 1
				lst = a[i]
		results.extend(list('LR'[cat1[0] < cat1[1]] * max(cat1)))
		break
	options = sorted([[a[runer[0]], 0], [a[runer[1]], 1]])
	for par1 in options:
		if par1[0] > last:
			results.append('LR'[par1[1]])
			runer[par1[1]] += -1 if par1[1] else 1
			last = par1[0]
			break
	else:
		break
print(len(results))
print(''.join(results))


n = int(input())
a = list(map(int, input().split()))
k = 0
ans = ''
x = 0
(l, r) = (0, n - 1)
while l <= r and (a[l] > x or a[r] > x):
	k += 1
	if a[l] > x and a[r] > x:
		if a[l] <= a[r]:
			x = a[l]
			ans += 'L'
			l += 1
		else:
			x = a[r]
			ans += 'R'
			r -= 1
	elif a[l] > x:
		x = a[l]
		ans += 'L'
		l += 1
	else:
		x = a[r]
		ans += 'R'
		r -= 1
print(k)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
ans = ''
seq = [0]
forward = 0
back = -1
for q in range(n):
	if arr[forward] <= seq[-1] and arr[back] <= seq[-1]:
		break
	if arr[forward] > seq[-1] and arr[back] > seq[-1]:
		if arr[forward] < arr[back]:
			seq.append(arr[forward])
			ans += 'L'
			forward += 1
		else:
			seq.append(arr[back])
			ans += 'R'
			back -= 1
	elif arr[forward] > seq[-1] > arr[back]:
		seq.append(arr[forward])
		ans += 'L'
		forward += 1
	elif arr[forward] < seq[-1] < arr[back]:
		seq.append(arr[back])
		ans += 'R'
		back -= 1
print(len(seq) - 1)
print(ans)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
from math import *
from decimal import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN():
	return list(numIN())

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))

def divi(n):
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l += [i, n // i]
	l.sort()
	return l

def lcm(a, b):
	return a * b // gcd(a, b)
n = int(input())
a = arrIN()
i = 0
j = n - 1
if a[0] < a[-1]:
	l = [a[0]]
	ans = 'L'
	i += 1
else:
	l = [a[-1]]
	j -= 1
	ans = 'R'
while i <= j:
	if a[i] < a[j]:
		if a[i] > l[-1]:
			l.append(a[i])
			ans += 'L'
			i += 1
		elif a[j] > l[-1]:
			ans += 'R'
			l.append(a[j])
			j -= 1
		else:
			break
	elif a[j] > l[-1]:
		ans += 'R'
		l.append(a[j])
		j -= 1
	elif a[i] > l[-1]:
		ans += 'L'
		l.append(a[i])
		i += 1
	else:
		break
print(len(l))
print(ans)


def solve():
	N = int(input())
	lst = list(map(int, input().split()))
	ans = ''
	done = 0
	left = 0
	rigt = len(lst) - 1
	while True:
		if (left <= len(lst) - 1 and rigt >= 0) and left <= rigt:
			(l, r) = (lst[left], lst[rigt])
			if max(l, r) > done:
				if l == r:
					ans += 'L'
					left += 1
					continue
				if min(l, r) > done:
					if l < r:
						ans += 'L'
						done = l
						left += 1
						continue
					elif r < l:
						ans += 'R'
						done = r
						rigt -= 1
						continue
				elif l < r:
					ans += 'R'
					done = r
					rigt -= 1
					continue
				elif r < l:
					ans += 'L'
					done = l
					left += 1
					continue
			else:
				print(len(ans))
				print(ans)
				exit()
		else:
			print(len(ans))
			print(ans)
			exit()
solve()


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	stack = []
	nums = []
	l = 0
	r = n - 1
	while l <= r:
		if not stack:
			if arr[l] < arr[r]:
				stack.append('L')
				nums.append(arr[l])
				l += 1
			else:
				stack.append('R')
				nums.append(arr[r])
				r -= 1
		elif nums[-1] < arr[l] and nums[-1] < arr[r] and (l != r):
			if arr[l] < arr[r]:
				nums.append(arr[l])
				stack.append('L')
				l += 1
			else:
				nums.append(arr[r])
				stack.append('R')
				r -= 1
		elif nums[-1] < arr[l]:
			nums.append(arr[l])
			stack.append('L')
			l += 1
		elif nums[-1] < arr[r]:
			nums.append(arr[r])
			stack.append('R')
			r -= 1
		else:
			break
	print(len(stack))
	print(''.join(stack))
t = 1
for _ in range(t):
	main()


n = int(input())
a = list(map(int, input().split()))
ans = ''
l = 0
r = n - 1
last = -1
while l <= r:
	if min(a[l], a[r]) <= last:
		break
	if a[l] < a[r]:
		ans += 'L'
		last = a[l]
		l += 1
	elif a[l] > a[r]:
		ans += 'R'
		last = a[r]
		r -= 1
	else:
		break
last1 = last
ans1 = ans
l1 = l
while l1 <= r and a[l1] > last1:
	ans1 += 'L'
	last1 = a[l1]
	l1 += 1
last2 = last
ans2 = ans
r2 = r
while r2 >= l and a[r2] > last2:
	ans2 = ans2 + 'R'
	last2 = a[r2]
	r2 -= 1
if len(ans1) > len(ans2):
	print(len(ans1))
	print(ans1)
else:
	print(len(ans2))
	print(ans2)


n = int(input())
a = list(map(int, input().split()))
ll = [0] * n
rr = [0] * n
l = 0
r = 0
while l < n:
	if l >= r:
		r = l + 1
		while r < n and a[r] > a[r - 1]:
			r += 1
	ll[l] = r - l
	l += 1
l = n - 1
r = n - 1
while r >= 0:
	if r <= l:
		l = r - 1
		while l >= 0 and a[l] > a[l + 1]:
			l -= 1
	rr[r] = r - l
	r -= 1
l = 0
r = n - 1
pre = -1
res = []
while l <= r:
	if max(a[l], a[r]) <= pre:
		break
	get_l = True
	if a[l] == a[r]:
		if ll[l] < rr[r]:
			get_l = False
	elif a[r] < a[l] and a[r] > pre or a[l] <= pre:
		get_l = False
	if get_l:
		res.append('L')
		pre = a[l]
		l += 1
	else:
		res.append('R')
		pre = a[r]
		r -= 1
print(len(res))
for i in res:
	print(i, end='')


while True:
	try:
		n = int(input())
		a = list(map(int, input().strip().split()))
		(o, t, l, r) = ([], 0, 0, len(a) - 1)
		while l <= r and max(a[l], a[r]) > t:
			if a[l] > t and a[r] > t:
				if a[l] < a[r]:
					t = a[l]
					o.append('L')
					l += 1
				elif a[r] < a[l]:
					t = a[r]
					o.append('R')
					r -= 1
				else:
					(dl, dr) = (0, 0)
					for i in range(l, r):
						if a[i] < a[i + 1]:
							dl += 1
						else:
							break
					for i in range(r, l, -1):
						if a[i] < a[i - 1]:
							dr += 1
						else:
							break
					if dl > dr:
						t = a[l]
						o.append('L')
						l += 1
					else:
						t = a[r]
						o.append('R')
						r -= 1
			elif a[l] > t:
				t = a[l]
				o.append('L')
				l += 1
			elif a[r] > t:
				t = a[r]
				o.append('R')
				r -= 1
		print(len(o))
		print(''.join(o))
	except:
		break


def main():
	n = int(input())
	seq = list(map(int, input().split(' ')))
	i = 0
	j = len(seq) - 1
	res = []
	res_seq = []
	while i < j:
		if len(res) == 0:
			if seq[i] <= seq[j]:
				res.append(seq[i])
				i += 1
				res_seq.append('L')
			else:
				res.append(seq[j])
				j -= 1
				res_seq.append('R')
		elif seq[i] > res[len(res) - 1] and seq[j] > res[len(res) - 1]:
			if seq[i] < seq[j]:
				res.append(seq[i])
				i += 1
				res_seq.append('L')
			else:
				res.append(seq[j])
				j -= 1
				res_seq.append('R')
		elif seq[i] > res[len(res) - 1]:
			res.append(seq[i])
			res_seq.append('L')
			i += 1
		elif seq[j] > res[len(res) - 1]:
			res.append(seq[j])
			res_seq.append('R')
			j -= 1
		else:
			break
	if i == j and len(res) == 0:
		res.append(seq[i])
		res_seq.append('L')
	elif i == j and seq[i] >= res[len(res) - 1]:
		res.append(seq[i])
		res_seq.append('L')
	print(len(res))
	print(''.join(res_seq))
main()


n = int(input())
u = list(map(int, input().split()))
i1 = 0
i2 = n - 1
ans = []
m = 0
p = []
while 1 == 1:
	m1 = min(u[i1], u[i2])
	m2 = max(u[i1], u[i2])
	if m > m2:
		break
	if m > m1:
		p.append(m2)
		m = m2
		if u[i1] > u[i2]:
			i1 += 1
			ans.append('L')
		else:
			i2 -= 1
			ans.append('R')
	else:
		p.append(m1)
		m = m1
		if u[i1] < u[i2]:
			i1 += 1
			ans.append('L')
		else:
			i2 -= 1
			ans.append('R')
	if i1 > i2:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = [int(i) for i in input().split()]
moves = ''
last = 0
left = 0
right = n - 1
while left <= right and max(a[left], a[right]) > last:
	if a[left] == a[right] and left != right:
		l = left + 1
		r = right - 1
		while a[l] > a[l - 1]:
			l += 1
		while a[r] > a[r + 1]:
			r -= 1
		if l - left > right - r:
			last = a[left]
			moves += 'L'
			left += 1
		else:
			last = a[right]
			moves += 'R'
			right -= 1
	elif a[left] > a[right]:
		if a[right] > last:
			last = a[right]
			moves += 'R'
			right -= 1
		else:
			last = a[left]
			moves += 'L'
			left += 1
	elif a[right] > a[left]:
		if a[left] > last:
			last = a[left]
			moves += 'L'
			left += 1
		else:
			last = a[right]
			moves += 'R'
			right -= 1
	elif a[left] == a[right] and left == right:
		last = a[right]
		moves += 'R'
		right -= 1
	else:
		break
print(len(moves))
print(moves)


from collections import deque
n = int(input())
A = list(map(int, input().split()))
q = deque(A)
if q[0] > q[-1]:
	tmp = q.pop()
	Ans = 'R'
else:
	tmp = q.popleft()
	Ans = 'L'
L = [tmp]
cnt = 1
while q:
	a = L[-1]
	(l, r) = (q[0], q[-1])
	if a > l and a > r:
		break
	if a > l:
		L.append(r)
		q.pop()
		Ans += 'R'
	elif a > r:
		L.append(l)
		q.popleft()
		Ans += 'L'
	elif r > l:
		L.append(l)
		q.popleft()
		Ans += 'L'
	else:
		L.append(r)
		q.pop()
		Ans += 'R'
	cnt += 1
print(cnt)
print(Ans)


from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	n = ii()
	a = li()
	b = []
	l = 0
	r = n - 1
	x = 0
	while l <= r:
		if a[l] <= x and a[r] <= x:
			break
		if a[l] > x and a[r] > x:
			if a[l] < a[r]:
				b.append('L')
				x = a[l]
				l += 1
			elif l != r and a[l] == a[r]:
				(a1, b1) = (0, 0)
				x1 = x
				for i in range(l, r):
					if a[i] > x1:
						x1 = a[i]
						a1 += 1
					else:
						break
				x2 = x
				for i in range(r, l, -1):
					if a[i] > x2:
						x2 = a[i]
						b1 += 1
					else:
						break
				if a1 > b1:
					b += ['L'] * a1
				else:
					b += ['R'] * b1
				break
			else:
				x = a[r]
				b.append('R')
				r -= 1
		elif a[l] > x:
			x = a[l]
			b.append('L')
			l += 1
		elif a[r] > x:
			x = a[r]
			b.append('R')
			r -= 1
		else:
			break
	print(len(b))
	print(''.join(b))
solve()


class deque(list):

	def __init__(self):
		super(deque, self).__init__()
		self.i = 0
		self.j = -1

	def get_l(self):
		return self[self.i]

	def get_r(self):
		return self[self.j]

	def use_l(self):
		self.i += 1
		return self[self.i - 1]

	def use_r(self):
		self.j -= 1
		return self[self.j + 1]

	def size(self):
		return len(self) - self.i + self.j + 1

	def pop_by_item(self, item):
		if item == self.get_l():
			return self.use_l()
		elif item == self.get_r():
			return self.use_r()
n = input()
qq = [int(i) for i in input().split()]
sample = deque()
sample.extend(qq)
anslist = []
compdic = {sample.get_l(): 'L', sample.get_r(): 'R'}
anslist.append(compdic[min(compdic)])
while 1:
	if anslist[-1] == 'L':
		last = sample.use_l()
	elif anslist[-1] == 'R':
		last = sample.use_r()
	if sample.size():
		compdic = {sample.get_r(): 'R', sample.get_l(): 'L'}
		for each in compdic.copy():
			if each < last:
				del compdic[each]
		if len(compdic):
			anslist.append(compdic[min(compdic)])
		else:
			break
	else:
		break
print(len(anslist))
print(''.join(anslist))


class Node:

	def __init__(self, data=None, prev_node=None, next_node=None):
		self.data = data
		self.prev = prev_node
		self.next = next_node

	def __repr__(self):
		return str(self.data)

	def __le__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data <= other else False

	def __eq__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data == other else False

	def __lt__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data < other else False

	def __gt__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data > other else False

	def __ge__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data >= other else False

	def __ne__(self, other):
		if isinstance(other, Node):
			other = other.data
		return True if self.data != other else False

def catdog(iterable, reverse=False):
	new_catdog = CatDog()
	for item in iterable:
		if reverse:
			new_catdog.pushcat(item)
		else:
			new_catdog.pushdog(item)
	return new_catdog

def change_len(func, val):

	def wrapped(self, *args, **kwargs):
		out = func(self, *args, **kwargs)
		self.len += val
		return out
	return wrapped

def increment_len(func):
	return change_len(func, 1)

def decrement_len(func):
	return change_len(func, -1)

class CatDog:

	def __init__(self, *items, reverse=False):
		self.cat = None
		self.dog = None
		self._cur = None
		self.len = 0
		for item in items:
			if reverse:
				self.pushcat(item)
			else:
				self.pushdog(item)

	def __len__(self):
		return self.len

	def __iter__(self):
		self._cur = self.cat
		return self

	def __next__(self):
		if self._cur is None:
			self._cur = self.cat
			raise StopIteration
		else:
			data = self._cur.data
			self._cur = self._cur.next
			return data

	def __repr__(self):
		items = ', '.join(map(str, self))
		in_brackets = f'[{items}]'
		return in_brackets

	def showcat(self):
		return self.cat.data

	def showdog(self):
		return self.dog.data

	@increment_len
	def pushdog(self, data):
		new = Node(data=data)
		old = self.dog
		if old is None:
			self.dog = new
			self.cat = new
		else:
			self._chain(old, new)
			self.dog = new

	@increment_len
	def pushcat(self, data):
		new = Node(data=data)
		old = self.cat
		if old is None:
			self.cat = new
			self.dog = new
		else:
			self._chain(new, old)
			self.cat = new

	@decrement_len
	def popcat(self):
		if self.is_empty():
			raise Exception
		cat = self.cat
		if cat.next is not None:
			cat.next.prev = None
		else:
			self.dog = None
		self.cat = cat.next
		return cat.data

	@decrement_len
	def popdog(self):
		if self.is_empty():
			raise Exception
		dog = self.dog
		if dog.prev is not None:
			dog.prev.next = None
		else:
			self.cat = None
		self.dog = dog.prev
		return dog.data

	def is_empty(self):
		return False if self.len else True

	def _chain(self, first, second):
		first.next = second
		second.prev = first

def main():
	n = int(input())
	A = catdog(map(int, input().split()))
	B = ''
	last = 0
	(cat, dog) = (A.cat, A.dog)
	while not A.is_empty() and (cat > last or dog > last):
		if cat > dog and dog > last:
			last = A.popdog()
			B += 'R'
		elif cat < dog and cat > last:
			last = A.popcat()
			B += 'L'
		elif cat == dog and cat is not dog:
			break
		elif cat > last:
			last = A.popcat()
			B += 'L'
		elif dog > last:
			last = A.popdog()
			B += 'R'
		(cat, dog) = (A.cat, A.dog)
	else:
		print(len(B))
		print(B)
		return
	cntcat = 1
	pcat = cat
	cat = cat.next
	while cat is not None and cat > pcat:
		pcat = cat
		cat = cat.next
		cntcat += 1
	cntdog = 1
	pdog = dog
	dog = dog.prev
	while dog is not None and dog > pdog:
		pdog = dog
		dog = dog.prev
		cntdog += 1
	if cntcat > cntdog:
		B += 'L' * cntcat
	else:
		B += 'R' * cntdog
	print(len(B))
	print(B)
main()


import sys
import collections as cc
import bisect as bi
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
ar = I()
ans = ''
l = 0
r = n - 1
prev = -1
while l <= r:
	if min(ar[l], ar[r]) <= prev:
		break
	if ar[l] < ar[r]:
		ans += 'L'
		prev = ar[l]
		l += 1
	elif ar[l] > ar[r]:
		ans += 'R'
		prev = ar[r]
		r -= 1
	else:
		break
pre = prev
an = ans
ll = l
while ll <= r and ar[ll] > pre:
	an += 'L'
	pre = ar[ll]
	ll += 1
pr = prev
ann = ans
rr = r
while rr >= l and ar[rr] > pr:
	ann += 'R'
	pr = ar[rr]
	rr -= 1
if len(an) > len(ann):
	print(len(an))
	print(an)
else:
	print(len(ann))
	print(ann)


N = int(input())
a = [int(i) for i in input().split(' ')]
i = 0
p = 0
j = len(a) - 1
r = ''
while i <= j and max(a[i], a[j]) > p:
	if a[j] < p or a[j] >= a[i] > p:
		p = a[i]
		r += 'L'
		i += 1
	else:
		p = a[j]
		r += 'R'
		j -= 1
print(len(r), r)


n = int(input())
a = [int(x) for x in input().split()]
ans = ''
l = 0
r = len(a) - 1
last = -1
while l <= r:
	if min(a[l], a[r]) <= last:
		break
	if a[l] < a[r]:
		ans = ans + 'L'
		last = a[l]
		l += 1
	elif a[l] > a[r]:
		ans = ans + 'R'
		last = a[r]
		r -= 1
	else:
		break
last1 = last
ans1 = ans
l1 = l
while l1 <= r and a[l1] > last1:
	ans1 = ans1 + 'L'
	last1 = a[l1]
	l1 += 1
last2 = last
ans2 = ans
r2 = r
while r2 >= l and a[r2] > last2:
	ans2 = ans2 + 'R'
	last2 = a[r2]
	r2 -= 1
ans = ans1 if len(ans1) > len(ans2) else ans2
print(len(ans))
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
(x, i) = (0, 0)
s = ''
while i < n:
	(l, r) = (a[i], a[n - 1])
	if l > x > r or r >= l > x:
		s += 'L'
		i += 1
		x = l
	elif r > x > l or l >= r > x:
		s += 'R'
		n -= 1
		x = r
	else:
		break
print(len(s))
print(s)


from collections import deque
n = int(input())
array = list(map(int, input().split()))
k = 0
string = ''
array = deque(array)
lenght = n - 1
prev = 0
for i in range(n):
	if array[0] > array[lenght] > prev:
		prev = array[lenght]
		array.pop()
		k += 1
		string += 'R'
		lenght -= 1
		continue
	if array[lenght] > array[0] > prev:
		prev = array[0]
		array.popleft()
		k += 1
		string += 'L'
		lenght -= 1
		continue
	elif array[0] > prev:
		prev = array[0]
		array.popleft()
		k += 1
		string += 'L'
		lenght -= 1
		continue
	elif array[lenght] > prev:
		prev = array[lenght]
		array.pop()
		k += 1
		string += 'R'
		lenght -= 1
		continue
	if lenght == 0:
		if array[0] > prev:
			k += 1
			string += 'L'
print(k)
print(string)


n = input()
data = input()
data = data.split(' ')

def Left_or_Right_Move(data_temp, direct):
	str_temp = direct
	i_ = 0
	j_ = len(data_temp) - 1
	if direct == 'L':
		while i_ + 1 < j_:
			if int(data_temp[i_]) < int(data_temp[i_ + 1]):
				str_temp += 'L'
				i_ += 1
			else:
				return str_temp
	else:
		while j_ - 1 > 0:
			if int(data_temp[j_]) < int(data_temp[j_ - 1]):
				str_temp += 'R'
				j_ -= 1
			else:
				return str_temp
	return str_temp

def find_increase_string():
	i = 0
	j = int(n) - 1
	sub_sequence = []
	str_ = ''
	if int(data[0]) > int(data[-1]):
		temp = int(data[-1])
		idx = -1
	elif int(data[0]) < int(data[-1]):
		temp = int(data[0])
		idx = 0
	else:
		l_ = Left_or_Right_Move(data[i:j + 1], 'L')
		r_ = Left_or_Right_Move(data[i:j + 1], 'R')
		if len(l_) > len(r_):
			str_ += l_
		else:
			str_ += r_
		print(len(str_))
		print(str_)
		return
	sub_sequence.append(temp)
	if idx == 0:
		str_ += 'L'
		i += 1
	else:
		str_ += 'R'
		j -= 1
	while i <= j:
		d0 = int(data[i])
		d1 = int(data[j])
		if d0 > d1:
			if d1 > sub_sequence[-1]:
				sub_sequence.append(d1)
				str_ += 'R'
				j -= 1
			elif d0 > sub_sequence[-1]:
				sub_sequence.append(d0)
				str_ += 'L'
				i += 1
			else:
				break
		elif d0 < d1:
			if d0 > sub_sequence[-1]:
				sub_sequence.append(d0)
				str_ += 'L'
				i += 1
			elif d1 > sub_sequence[-1]:
				sub_sequence.append(d1)
				str_ += 'R'
				j -= 1
			else:
				break
		else:
			if d0 > sub_sequence[-1]:
				l_ = Left_or_Right_Move(data[i:j + 1], 'L')
				r_ = Left_or_Right_Move(data[i:j + 1], 'R')
				if len(l_) > len(r_):
					str_ += l_
				else:
					str_ += r_
			break
	print(len(str_))
	print(str_)
find_increase_string()


n = int(input())
a = list(map(int, input().split()))
ans = ''
temp = -1
i = 0
j = -1
while n > 0:
	if max(a[i], a[j]) < temp:
		break
	elif len(ans) == 0:
		if a[i] < a[j]:
			temp = a[i]
			ans += 'L'
			i += 1
		else:
			temp = a[j]
			j -= 1
			ans += 'R'
		n -= 1
	else:
		if a[i] > temp and a[j] > temp:
			if a[i] > a[j]:
				temp = a[j]
				ans += 'R'
				j -= 1
			else:
				temp = a[i]
				ans += 'L'
				i += 1
		elif a[j] > temp:
			temp = a[j]
			ans += 'R'
			j -= 1
		elif a[i] > temp:
			temp = a[i]
			ans += 'L'
			i += 1
		else:
			break
		n -= 1
print(len(ans))
print(ans)


n = int(input())
l = list(map(int, input().split()))
seq = [0]
left = 0
right = n - 1
ans = ''
while left <= right:
	if l[left] > seq[-1] and l[right] > seq[-1]:
		if l[left] < l[right]:
			ans += 'L'
			seq.append(l[left])
			left += 1
		else:
			ans += 'R'
			seq.append(l[right])
			right -= 1
	elif l[left] > seq[-1]:
		ans += 'L'
		seq.append(l[left])
		left += 1
	elif l[right] > seq[-1]:
		ans += 'R'
		seq.append(l[right])
		right -= 1
	else:
		break
print(len(ans))
print(ans)


from sys import *
from math import *
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
x = 0
s = []
j = 0
l = n - 1
while j <= l:
	f = 0
	if a[j] < a[l]:
		if a[j] > x:
			x = a[j]
			s.append('L')
			f = 1
			j += 1
		elif a[l] > x:
			x = a[l]
			l -= 1
			s.append('R')
			f = 1
	elif a[l] > x:
		x = a[l]
		l -= 1
		s.append('R')
		f = 1
	elif a[j] > x:
		x = a[j]
		s.append('L')
		f = 1
		j += 1
	if f == 0:
		break
print(len(s))
print(*s, sep='')


n = int(input())
l = list(map(int, input().split()))
d = []
dd = 0
i = 0
j = n - 1
while i <= j:
	if l[i] <= l[j] and l[i] > dd:
		d.append('L')
		dd = l[i]
		i = i + 1
	elif l[j] > dd:
		d.append('R')
		dd = l[j]
		j -= 1
	elif l[i] > dd:
		d.append('L')
		dd = l[i]
		i += 1
	else:
		break
print(len(d))
print(''.join(d))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
last = 0
left = 0
right = n - 1
ans = 0
output = []
while left <= right:
	if a[left] > last:
		if a[right] > last:
			if a[left] < a[right]:
				last = a[left]
				output.append('L')
				left += 1
			else:
				last = a[right]
				output.append('R')
				right -= 1
		else:
			last = a[left]
			output.append('L')
			left += 1
		ans += 1
	elif a[right] > last:
		last = a[right]
		output.append('R')
		right -= 1
		ans += 1
	else:
		break
print(ans)
print(''.join(output))


n = int(input())
l = list(map(int, input().split()))
inn = 0
ex = n - 1
pr = 0
su = 0
ll = ''
while inn <= ex:
	if inn == ex:
		if l[inn] > pr:
			ll += 'L'
			su += 1
			break
	if l[inn] < pr and l[ex] < pr:
		break
	if l[inn] > pr and l[ex] < pr:
		su += 1
		ll += 'L'
		pr = l[inn]
		inn += 1
	elif l[inn] < pr and l[ex] > pr:
		su += 1
		ll += 'R'
		pr = l[ex]
		ex -= 1
	elif l[inn] > pr and l[ex] > pr:
		if l[inn] > l[ex]:
			su += 1
			pr = l[ex]
			ex -= 1
			ll += 'R'
		elif l[inn] < l[ex]:
			su += 1
			pr = l[inn]
			ll += 'L'
			inn += 1
print(su)
print(ll)


n = int(input())
seq = list(map(int, input().split()))
incSeq = []
moves = ''
rightCount = 0
leftCount = 0
if seq[0] == seq[-1] and len(seq) > 2:
	for i in range(len(seq) - 1, 0, -1):
		if seq[i] < seq[i - 1]:
			rightCount += 1
		else:
			break
	for i in range(0, len(seq) - 1):
		if seq[i] < seq[i + 1]:
			leftCount += 1
		else:
			break
	if rightCount > leftCount:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
	else:
		x = seq.pop(0)
		incSeq.append(x)
		moves += 'L'
elif seq[0] > seq[-1]:
	x = seq.pop()
	incSeq.append(x)
	moves += 'R'
else:
	x = seq.pop(0)
	incSeq.append(x)
	moves += 'L'
while seq and (seq[0] > incSeq[-1] or seq[-1] > incSeq[-1]):
	if len(seq) == 1:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
	elif seq[0] == seq[-1] and len(seq) > 1:
		for i in range(len(seq) - 1, 0, -1):
			if seq[i] <= seq[i - 1]:
				rightCount += 1
			else:
				break
		for i in range(0, len(seq) - 1):
			if seq[i] <= seq[i + 1]:
				leftCount += 1
			else:
				break
		if rightCount > leftCount:
			x = seq.pop()
			incSeq.append(x)
			moves += 'R'
		else:
			x = seq.pop(0)
			incSeq.append(x)
			moves += 'L'
	elif seq[0] > seq[-1] > incSeq[-1]:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
	elif seq[0] > seq[-1] and seq[-1] <= incSeq[-1]:
		x = seq.pop(0)
		incSeq.append(x)
		moves += 'L'
	elif seq[-1] > seq[0] > incSeq[-1]:
		x = seq.pop(0)
		incSeq.append(x)
		moves += 'L'
	elif seq[-1] > seq[0] and seq[0] <= incSeq[-1]:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
print(len(moves))
print(moves)


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	i = 0
	j = n - 1
	last = -1
	ans = []
	while i <= j:
		if i == j:
			if A[i] > last:
				i += 1
				ans.append('L')
			else:
				break
		elif A[i] < A[j]:
			if A[i] > last:
				last = A[i]
				i += 1
				ans.append('L')
			elif A[j] > last:
				last = A[j]
				j -= 1
				ans.append('R')
			else:
				break
		elif A[j] > last:
			last = A[j]
			j -= 1
			ans.append('R')
		elif A[i] > last:
			last = A[i]
			i += 1
			ans.append('L')
		else:
			break
	print(len(ans))
	print(''.join(ans))
main()


from sys import stdin
from collections import deque as dq
n = int(stdin.readline())
nums = dq(map(int, stdin.readline().split()))
ans = ''
seqlast = -1
while len(nums) > 1:
	(l, r) = (nums[0], nums[-1])
	if seqlast > l and seqlast > r:
		break
	elif seqlast < l and seqlast > r:
		ans += 'L'
		nums.popleft()
		seqlast = l
	elif seqlast < r and seqlast > l:
		ans += 'R'
		nums.pop()
		seqlast = r
	elif l < r:
		ans += 'L'
		nums.popleft()
		seqlast = l
	else:
		ans += 'R'
		nums.pop()
		seqlast = r
if len(nums):
	if nums[0] > seqlast:
		ans += 'L'
print(len(ans))
print(ans)


from collections import deque
N = int(input())
L = deque(list(map(int, input().split())))
A = deque([])
A.append(0)
B = ''
while True:
	if len(L) == 0:
		break
	if A[-1] < L[0] and A[-1] < L[-1]:
		if L[0] < L[-1]:
			A.append(L[0])
			L.popleft()
			B += 'L'
		else:
			A.append(L[-1])
			L.pop()
			B += 'R'
	elif A[-1] < L[0]:
		A.append(L[0])
		L.popleft()
		B += 'L'
	elif A[-1] < L[-1]:
		A.append(L[-1])
		L.pop()
		B += 'R'
	else:
		break
print(len(A) - 1)
print(B)


n = int(input())
a = list(map(int, input().split()))
p1 = 0
p2 = n - 1
m = 0
s = ''
while p1 <= p2:
	if m < a[p1] < a[p2]:
		s += 'L'
		m = a[p1]
		p1 += 1
	elif a[p1] < m < a[p2]:
		s += 'R'
		m = a[p2]
		p2 -= 1
	elif m < a[p2] < a[p1]:
		s += 'R'
		m = a[p2]
		p2 -= 1
	elif a[p2] < m < a[p1]:
		s += 'L'
		m = a[p1]
		p1 += 1
	elif a[p1] < m and a[p2] < m:
		break
	else:
		s += 'R'
		p1 += 1
print(len(s))
print(s)


from collections import deque
n = int(input())
o = list(map(int, input().split()))
l = deque(o)
p = []
ans = []
while len(l) != 0:
	if len(ans) == 0:
		if len(ans) == 0:
			if l[0] < l[-1]:
				ans.append('L')
				x = l.popleft()
				p.append(x)
			else:
				ans.append('R')
				x = l.pop()
				p.append(x)
			continue
	if l[0] > p[-1] or l[-1] > p[-1]:
		if l[0] > p[-1] and l[-1] < p[-1]:
			ans.append('L')
			x = l.popleft()
			p.append(x)
			continue
		if l[0] < p[-1] and l[-1] > p[-1]:
			ans.append('R')
			x = l.pop()
			p.append(x)
			continue
		if l[0] <= l[-1] and l[0] > p[-1]:
			ans.append('L')
			x = l.popleft()
			p.append(x)
			continue
		if l[0] > l[-1] and l[-1] > p[-1]:
			ans.append('R')
			x = l.pop()
			p.append(x)
			continue
	break
print(len(ans))
print(''.join(ans))


n = int(input())
d = list(map(int, input().split()))
p = [0, n - 1]
e = [0]
c = ''
while p[0] <= p[1]:
	if d[p[0]] < d[p[1]]:
		if e[-1] < d[p[0]]:
			e.append(d[p[0]])
			p[0] += 1
			c += 'L'
		elif e[-1] < d[p[1]]:
			e.append(d[p[1]])
			p[1] -= 1
			c += 'R'
		else:
			break
	elif e[-1] < d[p[1]]:
		e.append(d[p[1]])
		p[1] -= 1
		c += 'R'
	elif e[-1] < d[p[0]]:
		e.append(d[p[0]])
		p[0] += 1
		c += 'L'
	else:
		break
print(len(c))
print(c)


n = int(input())
lis = list(map(int, input().split()))
i = 0
j = n - 1
s = ''
if lis[i] > lis[j]:
	j -= 1
	s = s + 'R'
	x = lis[j + 1]
else:
	i += 1
	s = s + 'L'
	x = lis[i - 1]
while i <= j:
	if x < lis[i] and x < lis[j]:
		if lis[i] > lis[j]:
			j -= 1
			s = s + 'R'
			x = lis[j + 1]
		else:
			i += 1
			s = s + 'L'
			x = lis[i - 1]
	elif x < lis[j]:
		j -= 1
		s = s + 'R'
		x = lis[j + 1]
	elif x < lis[i]:
		i += 1
		s = s + 'L'
		x = lis[i - 1]
	else:
		break
print(len(s))
print(s)


length = int(input())
number = [item for item in map(int, input().split(' '))]
smallest = min(number) - 1

def solver(number, smallest, left, right):
	res = []
	if right - left == 0:
		if smallest < number[0]:
			res.append('L')
			return res
	while left < right:
		if number[left] != number[right] and smallest < number[left] and (smallest < number[right]):
			if number[left] > number[right]:
				res.append('R')
				smallest = number[right]
				right -= 1
			elif number[left] < number[right]:
				res.append('L')
				smallest = number[left]
				left += 1
		elif number[left] != number[right] and smallest > min(number[left], number[right]) and (smallest < max(number[left], number[right])):
			if number[left] > number[right]:
				res.append('L')
				smallest = number[left]
				left += 1
			elif number[left] < number[right]:
				res.append('R')
				smallest = number[right]
				right -= 1
		elif number[right] == number[left] and smallest < number[left]:
			test1 = solver(number, number[left], left + 1, right)
			test2 = solver(number, number[right], left, right - 1)
			if len(test1) > len(test2):
				res.append('L')
				res.extend(test1)
				left += 1
			else:
				res.append('R')
				res.extend(test2)
				right -= 1
			return res
		elif smallest == min(number[left], number[right]):
			if number[left] < number[right]:
				res.append('R')
				smallest = number[right]
				right -= 1
			elif number[right] < number[left]:
				res.append('L')
				smallest = number[left]
				left += 1
			else:
				return res
		else:
			break
	if right == left and number[left] > smallest:
		res.append('R')
	return res
res = solver(number, smallest, 0, length - 1)
print(len(res), ''.join(res), sep='\n')


n = int(input())
v = [int(i) for i in input().split()]
last = 0
tam = 0
extra = 0
m = ''
i = 0
j = n - 1
while i <= j:
	if v[i] < v[j] and v[i] > last or (v[i] > last and v[j] <= last):
		last = v[i]
		tam += 1
		m += 'L'
		i += 1
	elif v[j] < v[i] and v[j] > last or (v[j] > last and v[i] <= last):
		last = v[j]
		tam += 1
		m += 'R'
		j -= 1
	elif v[i] == v[j] and v[i] > last:
		pd = 1
		pe = 1
		id = i
		jd = j
		me = 'L'
		md = 'R'
		while id < jd:
			if v[id] < v[id + 1]:
				pe += 1
				me += 'L'
				id += 1
			else:
				break
		id = i
		jd = j
		while id < jd:
			if v[jd] < v[jd - 1]:
				pd += 1
				md += 'R'
				jd -= 1
			else:
				break
		if pd == 1 and pe == 1:
			tam += 1
			m += 'R'
		elif pd > pe:
			m += md
			tam += pd
		else:
			tam += pe
			m += me
		break
	else:
		break
print(tam)
print(m)


n = int(input())
a = [int(i) for i in input().split()]
l = 0
r = n - 1
ans = []
li = []
while r >= l:
	if l == 0 and r == n - 1:
		if a[l] < a[r]:
			li.append(a[l])
			ans.append('L')
			l += 1
		else:
			li.append(a[r])
			ans.append('R')
			r -= 1
	elif a[l] > li[-1] and a[r] > li[-1]:
		if a[l] <= a[r]:
			li.append(a[l])
			ans.append('L')
			l += 1
		else:
			li.append(a[r])
			ans.append('R')
			r -= 1
	elif a[l] > li[-1] and a[r] < li[-1]:
		li.append(a[l])
		ans.append('L')
		l += 1
	elif a[l] < li[-1] and a[r] > li[-1]:
		li.append(a[r])
		ans.append('R')
		r -= 1
	elif a[l] < li[-1] and a[r] < li[-1]:
		break
print(len(ans))
for i in range(len(ans)):
	print(ans[i], end='')


n = int(input())
a = [int(x) for x in input().split()]
answ = ''
smax = -float('inf')
l = 0
r = len(a) - 1
while l <= r:
	if a[l] < a[r]:
		if a[l] > smax:
			answ += 'L'
			smax = a[l]
			l += 1
		elif a[r] > smax:
			answ += 'R'
			smax = a[r]
			r -= 1
		else:
			break
	elif a[r] > smax:
		answ += 'R'
		smax = a[r]
		r -= 1
	elif a[l] > smax:
		answ += 'L'
		smax = a[l]
		l += 1
	else:
		break
print(len(answ))
print(answ)


def main():
	n = int(input())
	l = list(map(int, input().split()))
	result = ''
	current = 0
	left = 0
	right = -1
	while n > 0:
		first = l[left]
		last = l[right]
		if first > current and first < last:
			current = first
			result += 'L'
			left += 1
		elif last > current and last < first:
			current = last
			result += 'R'
			right -= 1
		elif first > current:
			current = first
			result += 'L'
			left += 1
		elif last > current:
			current = last
			result += 'R'
			right -= 1
		else:
			break
		n -= 1
	print(len(result))
	print(result)
main()


n = int(input())
a = [int(x) for x in input().split(' ')]
left = 0
right = n - 1
curr = 0
ans = ''
while True:
	if curr < a[left] and curr < a[right]:
		if a[left] < a[right]:
			ans += 'L'
			curr = a[left]
			left += 1
		else:
			ans += 'R'
			curr = a[right]
			right -= 1
	elif curr < a[left]:
		ans += 'L'
		curr = a[left]
		left += 1
	elif curr < a[right]:
		ans += 'R'
		curr = a[right]
		right -= 1
	else:
		break
print(len(ans))
print(ans)


saida = []
lista = []
n = int(input())
lista = input()
lista = list(map(int, lista.split(' ')))
ini = 0
fim = len(lista) - 1
pos = 0
while ini <= fim and max(lista[ini], lista[fim]) > pos:
	if lista[fim] < pos or lista[fim] >= lista[ini] > pos:
		saida.append('L')
		pos = lista[ini]
		ini += 1
	else:
		saida.append('R')
		pos = lista[fim]
		fim -= 1
print(len(saida))
saidaS = ''.join(saida)
print(str(saidaS))


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	seq = list()
	prev = 0
	ln = 0
	while i <= j and (prev < l[i] or prev < l[j]):
		ln += 1
		if l[j] < l[i] and prev < l[j] or prev > l[i]:
			seq.append('R')
			prev = l[j]
			j -= 1
		else:
			seq.append('L')
			prev = l[i]
			i += 1
	print(ln)
	print(''.join(seq))
main()


import sys, collections
n = int(sys.stdin.readline())
arr = collections.deque(list(map(int, sys.stdin.readline().split())))
st = [(0, '-')]
while len(arr) > 1:
	if arr[0] > st[-1][0] and arr[-1] > st[-1][0]:
		if arr[0] < arr[-1]:
			st.append((arr[0], 'L'))
			arr.popleft()
		else:
			st.append((arr[-1], 'R'))
			arr.pop()
	elif arr[0] > st[-1][0] and arr[-1] < st[-1][0]:
		st.append((arr[0], 'L'))
		arr.popleft()
	elif arr[0] < st[-1][0] and arr[-1] > st[-1][0]:
		st.append((arr[-1], 'R'))
		arr.pop()
	else:
		break
if len(arr) == 1:
	if arr[0] > st[-1][0]:
		st.append((arr[0], 'L'))
ans = []
for i in range(1, len(st)):
	ans.append(st[i][1])
print(len(ans))
print(''.join(ans))


n = int(input())
a = list(map(int, input().split()))
l_index = 0
r_index = n - 1
result = []
if a[l_index] > a[r_index]:
	prev_number = a[r_index]
	r_index -= 1
	result.append('R')
else:
	prev_number = a[l_index]
	l_index += 1
	result.append('L')
while r_index >= l_index:
	if a[l_index] > prev_number and a[r_index] > prev_number:
		if a[l_index] > a[r_index]:
			prev_number = a[r_index]
			r_index -= 1
			result.append('R')
		else:
			prev_number = a[l_index]
			l_index += 1
			result.append('L')
	elif a[l_index] > prev_number:
		prev_number = a[l_index]
		l_index += 1
		result.append('L')
	elif a[r_index] > prev_number:
		prev_number = a[r_index]
		r_index -= 1
		result.append('R')
	else:
		break
print(len(result))
print(''.join(result))


n = int(input())
a = list(map(int, input().split()))
res = []
end = True
right = n - 1
left = 0
prev = 0
while end:
	d_r = a[right] - prev
	if d_r <= 0:
		d_r = n + 1
	d_l = a[left] - prev
	if d_l <= 0:
		d_l = n + 1
	if d_l < d_r:
		prev = a[left]
		res.append('L')
		left += 1
	elif d_r < d_l:
		prev = a[right]
		res.append('R')
		right -= 1
	elif d_r == d_l and d_r != n + 1:
		prev = a[right]
		res.append('R')
		right -= 1
	if left > right:
		end = False
	if d_r == n + 1 and d_l == n + 1:
		end = False
print(len(res))
for i in res:
	print(i, end='')


n = int(input())
a = [int(i) for i in input().split()]
aa = 0
c = 0
l = 0
b = ''
r = n - 1
while l <= r:
	m1 = min(a[l], a[r])
	m2 = max(a[l], a[r])
	if m1 > aa:
		aa = m1
		if m1 == a[r]:
			r -= 1
			b += 'R'
		elif m1 == a[l]:
			l += 1
			b += 'L'
		c += 1
	elif m2 > aa:
		aa = m2
		if m2 == a[r]:
			r -= 1
			b += 'R'
		elif m2 == a[l]:
			l += 1
			b += 'L'
		c += 1
	else:
		break
print(c)
print(b)


import sys
import math
import re
import io

def solve(my_list):
	n = len(my_list)
	i = 0
	j = n - 1
	cur = 0
	ans = io.StringIO()
	while i <= j:
		if my_list[i] > cur and my_list[j] > cur:
			if my_list[i] < my_list[j]:
				ans.write('L')
				cur = my_list[i]
				i = i + 1
			else:
				ans.write('R')
				cur = my_list[j]
				j = j - 1
		elif my_list[i] > cur:
			ans.write('L')
			cur = my_list[i]
			i = i + 1
		elif my_list[j] > cur:
			ans.write('R')
			cur = my_list[j]
			j = j - 1
		else:
			break
	return ans.getvalue()

def main():
	input()
	s = list(map(int, input().split()))
	ans = solve(s)
	print(len(ans))
	print(ans)
main()


class Node:

	def __init__(self, data=None, prev_node=None, next_node=None):
		self.data = data
		self.prev = prev_node
		self.next = next_node

	def __repr__(self):
		return str(self.data)

def catdog(iterable, reverse=False):
	new_catdog = CatDog()
	for item in iterable:
		if reverse:
			new_catdog.pushcat(item)
		else:
			new_catdog.pushdog(item)
	return new_catdog

def change_len(func, val):

	def wrapped(self, *args, **kwargs):
		out = func(self, *args, **kwargs)
		self.len += val
		return out
	return wrapped

def increment_len(func):
	return change_len(func, 1)

def decrement_len(func):
	return change_len(func, -1)

class CatDog:

	def __init__(self, *items, reverse=False):
		self.cat = None
		self.dog = None
		self._cur = None
		self.len = 0
		for item in items:
			if reverse:
				self.pushcat(item)
			else:
				self.pushdog(item)

	def __len__(self):
		return self.len

	def __iter__(self):
		self._cur = self.cat
		return self

	def __next__(self):
		if self._cur is None:
			self._cur = self.cat
			raise StopIteration
		else:
			data = self._cur.data
			self._cur = self._cur.next
			return data

	def __repr__(self):
		items = ', '.join(map(str, self))
		in_brackets = f'[{items}]'
		return in_brackets

	def showcat(self):
		return self.cat.data

	def showdog(self):
		return self.dog.data

	@increment_len
	def pushdog(self, data):
		new = Node(data=data)
		old = self.dog
		if old is None:
			self.dog = new
			self.cat = new
		else:
			self._chain(old, new)
			self.dog = new

	@increment_len
	def pushcat(self, data):
		new = Node(data=data)
		old = self.cat
		if old is None:
			self.cat = new
			self.dog = new
		else:
			self._chain(new, old)
			self.cat = new

	@decrement_len
	def popcat(self):
		if self.is_empty():
			raise Exception
		cat = self.cat
		if cat.next is not None:
			cat.next.prev = None
		else:
			self.dog = None
		self.cat = cat.next
		return cat.data

	@decrement_len
	def popdog(self):
		if self.is_empty():
			raise Exception
		dog = self.dog
		if dog.prev is not None:
			dog.prev.next = None
		else:
			self.cat = None
		self.dog = dog.prev
		return dog.data

	def is_empty(self):
		return False if self.len else True

	def _chain(self, first, second):
		first.next = second
		second.prev = first

def main():
	n = int(input())
	A = catdog(map(int, input().split()))
	B = ''
	last = 0
	(cat, dog) = (A.cat, A.dog)
	while not A.is_empty() and (cat.data > last or dog.data > last):
		if cat.data > dog.data and dog.data > last:
			last = A.popdog()
			B += 'R'
		elif cat.data < dog.data and cat.data > last:
			last = A.popcat()
			B += 'L'
		elif cat.data == dog.data and cat is not dog:
			nc = cat
			nd = dog
			while nc.data == nd.data and nc is not nd:
				nc = cat.next
				nd = dog.prev
			if nc.data >= nd.data:
				last = A.popdog()
				B += 'R'
			elif nc.data < nd.data:
				last = A.popcat()
				B += 'L'
		elif cat.data > last:
			last = A.popcat()
			B += 'L'
		elif dog.data > last:
			last = A.popdog()
			B += 'R'
		(cat, dog) = (A.cat, A.dog)
	print(len(B))
	print(B)
main()


alen = int(input())
elems = list(map(int, input().split()))
l = 0
r = 0
current = 0
seq = []
while True:
	if l + r >= alen:
		break
	left = elems[l]
	right = elems[-1 - r]
	choice = None
	if left < current:
		if right < current:
			break
		choice = 'r'
	elif right < current:
		choice = 'l'
	elif left < right:
		choice = 'l'
	else:
		choice = 'r'
	seq.append(choice.capitalize())
	if choice == 'l':
		l += 1
		current = left
	else:
		r += 1
		current = right
print(l + r)
print(''.join(seq))


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	L = 0
	R = n - 1
	last = 0
	res = []
	while L <= R:
		if a[L] < a[R]:
			if a[L] > last:
				res.append('L')
				last = a[L]
				L += 1
			elif a[R] > last:
				res.append('R')
				last = a[R]
				R -= 1
			else:
				break
		elif a[R] > last:
			res.append('R')
			last = a[R]
			R -= 1
		elif a[L] > last:
			res.append('L')
			last = a[L]
			L += 1
		else:
			break
	print(len(res))
	print(''.join(res))
main()


import sys
import collections as cc
import bisect as bi
input = sys.stdin.buffer.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
ar = I()
ans = ''
temp = []
l = 0
r = n - 1
prev = 0
while l < r:
	x = ar[l]
	y = ar[r]
	if x < prev and y < prev:
		break
	if min(x, y) > prev:
		if min(x, y) == ar[l]:
			ans += 'L'
			l += 1
			prev = min(x, y)
		else:
			ans += 'R'
			r -= 1
			prev = min(x, y)
	elif max(x, y) > prev:
		if max(x, y) == ar[r]:
			ans += 'R'
			r -= 1
			prev = max(x, y)
		else:
			ans += 'L'
			l += 1
			prev = max(x, y)
	else:
		break
if l == r and ar[l] > prev:
	ans += 'L'
print(len(ans))
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
b = 0
cnt = 0
s = ''
while l <= r and max(a[l], a[r]) > b:
	cnt += 1
	if b < a[l] < a[r] or b > a[r]:
		s += 'L'
		b = a[l]
		l += 1
	else:
		s += 'R'
		b = a[r]
		r -= 1
print(cnt)
print(s)


import sys
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
left = [0 for _ in range(n)]
right = [0 for _ in range(n)]
left[0] = 1
right[-1] = 1
if n == 1:
	print(1)
	print('L')
else:
	for i in range(1, n):
		if arr[i - 1] < arr[i]:
			pass
		else:
			break
	count = 1
	for j in range(i - 1, -1, -1):
		left[j] = count
		count += 1
	for i in range(n - 2, -1, -1):
		if arr[i + 1] < arr[i]:
			pass
		else:
			break
	count = 1
	for j in range(i + 1, n):
		right[j] = count
		count += 1
	ans = [0 for _ in range(n)]
	(l, r) = (0, n - 1)
	i = 0
	a = [0 for _ in range(n)]
	z = True
	lim = 0
	last = -float('inf')
	while l <= r and z:
		if arr[l] < arr[r]:
			if arr[l] > last and left[l] > 0:
				last = arr[l]
				ans[i] = arr[l]
				a[i] = 'L'
				l += 1
				lim += 1
				i += 1
				continue
			if arr[r] > last and right[r] > 0:
				last = arr[r]
				ans[i] = arr[r]
				a[i] = 'R'
				r -= 1
				lim += 1
				i += 1
				continue
			z = False
		if arr[r] < arr[l]:
			if arr[r] > last and right[r] > 0:
				last = arr[r]
				ans[i] = arr[r]
				a[i] = 'R'
				r -= 1
				lim += 1
				i += 1
				continue
			if arr[l] > last and left[l] > 0:
				last = arr[l]
				a[i] = 'L'
				ans[i] = arr[l]
				l += 1
				lim += 1
				i += 1
				continue
		z = False
	if arr[l] == arr[r]:
		if left[l] > right[r]:
			c = left[l]
			while c > 0:
				ans[i] = arr[l]
				l += 1
				a[i] = 'L'
				lim += 1
				i += 1
				c -= 1
		else:
			c = right[r]
			while c > 0:
				ans[i] = arr[r]
				r -= 1
				lim += 1
				a[i] = 'R'
				i += 1
				c -= 1
	print(lim)
	print(''.join((x for x in a[:lim])))


def f(lis, x):
	if lis[0] <= x and lis[-1] <= x:
		return 0
	cnt = 1
	if lis[0] > x:
		for i in range(1, len(lis)):
			if lis[i] > lis[i - 1]:
				cnt += 1
			else:
				break
	if lis[-1] > x:
		for i in range(len(lis) - 1, 0, -1):
			if lis[i - 1] > lis[i]:
				cnt += 1
			else:
				break
	return cnt
n = int(input())
s = list(map(int, input().split()))
(i, j) = (0, n - 1)
res = [[0, '']]
bo = False
while i <= n - 1 and j >= 0:
	if s[i] == s[j] and i != j and (s[i] > res[-1][0]):
		bo = True
		break
	if max(s[i], s[j]) <= res[-1][0]:
		break
	elif s[i] < s[j]:
		if s[i] > res[-1][0]:
			res.append([s[i], 'L'])
			i += 1
		else:
			res.append([s[j], 'R'])
			j -= 1
	elif s[j] > res[-1][0]:
		res.append([s[j], 'R'])
		j -= 1
	else:
		res.append([s[i], 'L'])
		i += 1
if bo:
	cnt1 = f(s[i + 1:j + 1], s[i])
	cnt2 = f(s[i:j], s[j])
	if cnt1 >= cnt2:
		for k in range(cnt1 + 1):
			res.append('L')
	else:
		for k in range(cnt2 + 1):
			res.append('R')
print(len(res) - 1)
for i in res[1:]:
	print(i[-1], end='')


n = int(input())
a = list(map(int, input().split()))
moves = ''
current = 0
l = 0
r = len(a) - 1
while l <= r and max(a[l], a[r]) > current:
	if current < a[l] <= a[r] or a[r] <= current < a[l]:
		current = a[l]
		moves += 'L'
		l += 1
	elif current < a[r] < a[l] or a[l] <= current < a[r]:
		current = a[r]
		moves += 'R'
		r -= 1
	else:
		break
print(len(moves))
print(moves)


class mystr:

	def __init__(self):
		self.s = ''

	def __add__(self, o: str):
		self.s += o
		return self.s

	def __str__(self):
		return self.s

	def __len__(self):
		return len(self.s)

def left_move(ar, moves):
	moves += 'L'
	return ar.pop(0)

def right_move(ar, moves):
	moves += 'R'
	return ar.pop(-1)
n = int(input())
ar = list(map(int, input().split()))
n = len(ar)
moves = ''
last_el = None
i = 0
j = n - 1
if ar[i] < ar[j]:
	last_el = ar[i]
	i += 1
	moves += 'L'
else:
	last_el = ar[j]
	j -= 1
	moves += 'R'
while i <= j and max(ar[i], ar[j]) > last_el:
	if last_el < ar[i] < ar[j] or ar[j] < last_el < ar[i]:
		last_el = ar[i]
		moves += 'L'
		i += 1
	elif last_el < ar[j] < ar[i] or ar[i] < last_el < ar[j]:
		last_el = ar[j]
		moves += 'R'
		j -= 1
	elif ar[j] == ar[i] and last_el < ar[i]:
		last_el = ar[j]
		moves += 'L'
		i += 1
print(len(moves))
print(moves)


n = int(input())
x = list(map(int, input().split()))
l = 0
r = n - 1
ans1 = 0
ans2 = ''
now = 0
while l <= r:
	if now < x[l]:
		if x[l] < x[r]:
			ans1 += 1
			ans2 = ans2 + 'L'
			now = x[l]
			l += 1
		elif now > x[r]:
			ans1 += 1
			ans2 = ans2 + 'L'
			now = x[l]
			l += 1
		else:
			ans1 += 1
			ans2 = ans2 + 'R'
			now = x[r]
			r -= 1
	elif now < x[r]:
		ans1 += 1
		ans2 = ans2 + 'R'
		now = x[r]
		r -= 1
	else:
		break
print(ans1)
print(ans2)


N = int(input())
V = list(map(int, input().split()))
last = -1
res = []
run = [0, N - 1]
while run[1] >= run[0] and max(V[run[0]], V[run[1]]) > last:
	if V[run[0]] == V[run[1]]:
		cat = [0, 0]
		bound = [[run[0], run[1] + 1, 1], [run[1], run[0] - 1, -1]]
		for t in range(2):
			lst = last
			for i in range(*bound[t]):
				if V[i] <= lst:
					break
				cat[t] += 1
				lst = V[i]
		res.extend(list('LR'[cat[0] < cat[1]] * max(cat)))
		break
	options = sorted([[V[run[0]], 0], [V[run[1]], 1]])
	for par in options:
		if par[0] > last:
			res.append('LR'[par[1]])
			run[par[1]] += -1 if par[1] else 1
			last = par[0]
			break
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
a = list(map(int, input().split()))
ans = []
cur_min = -1
(l, r) = (0, n - 1)
while l <= r and max(a[l], a[r]) > cur_min:
	if a[l] != a[r]:
		if a[l] > cur_min:
			next_step = 'L'
		else:
			next_step = 'R'
		if a[r] > cur_min and a[r] < a[l]:
			next_step = 'R'
		if next_step == 'L':
			cur_min = a[l]
			l += 1
		else:
			cur_min = a[r]
			r -= 1
		ans.append(next_step)
	else:
		(count_l, count_r) = (0, 0)
		(i_l, i_r) = (l, r)
		while i_l + 1 < n and a[i_l + 1] > a[i_l]:
			count_l += 1
			i_l += 1
		while i_r - 1 >= 0 and a[i_r - 1] > a[i_r]:
			count_r += 1
			i_r -= 1
		if count_r > count_l:
			ans.extend(['R' for _ in range(count_r + 1)])
		else:
			ans.extend(['L' for _ in range(count_l + 1)])
		break
print(len(ans))
print(''.join(ans))


import os
import sys
n = int(input())
a = input().split(' ')
for i in range(0, n):
	a[i] = int(a[i])
ans = []
f = 0
s = n - 1
m = -1
while f <= s:
	if a[f] < a[s] and m < a[f]:
		m = a[f]
		ans.append('L')
		f += 1
	elif a[f] > a[s] and m < a[s]:
		m = a[s]
		ans.append('R')
		s -= 1
	elif m < a[f]:
		m = a[f]
		ans.append('L')
		f += 1
	elif m < a[s]:
		m = a[s]
		ans.append('R')
		s -= 1
	else:
		break
print(len(ans))
for i in ans:
	print(i, sep='', end='')


length = int(input())
number = [item for item in map(int, input().split(' '))]
smallest = min(number) - 1
res = []
left = 0
right = length - 1
while left <= right:
	if smallest < number[left] and smallest < number[right]:
		if number[left] > number[right]:
			res.append('R')
			smallest = number[right]
			right -= 1
		else:
			res.append('L')
			smallest = number[left]
			left += 1
	elif smallest > min(number[left], number[right]) and smallest < max(number[left], number[right]):
		if number[left] > number[right]:
			res.append('L')
			smallest = number[left]
			left += 1
		else:
			res.append('R')
			smallest = number[right]
			right -= 1
	else:
		break
print(len(res), ''.join(res), sep='\n')


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
c = []
z = []
if len(a) == 1:
	print('1')
	print('L')
	exit()
while True:
	if len(a) == 0:
		break
	if a[0] < a[-1] and len(c) == 0:
		c.append('L')
		z.append(a[0])
		a.popleft()
	elif a[0] > a[-1] and len(c) == 0:
		c.append('R')
		z.append(a[-1])
		a.pop()
	elif a[0] > z[-1] and a[0] < a[-1]:
		c.append('L')
		z.append(a[0])
		a.popleft()
	elif a[-1] > z[-1] and a[-1] < a[0]:
		c.append('R')
		z.append(a[-1])
		a.pop()
	elif a[0] > z[-1]:
		c.append('L')
		z.append(a[0])
		a.popleft()
	elif a[-1] > z[-1]:
		c.append('R')
		z.append(a[-1])
		a.pop()
	else:
		break
print(len(c))
print(''.join(c))


N = int(input())
line = [int(x) for x in input().split()]
i = 0
j = len(line) - 1
seq = []
ret = []
while i < j:
	if len(seq) != 0:
		if line[i] < line[j]:
			if seq[-1] < line[i]:
				seq.append(line[i])
				ret.append('L')
				i += 1
			elif seq[-1] < line[j]:
				seq.append(line[j])
				ret.append('R')
				j -= 1
			else:
				break
		elif seq[-1] < line[j]:
			seq.append(line[j])
			ret.append('R')
			j -= 1
		elif seq[-1] < line[i]:
			seq.append(line[i])
			ret.append('L')
			i += 1
		else:
			break
	elif line[i] < line[j]:
		seq.append(line[i])
		ret.append('L')
		i += 1
	else:
		seq.append(line[j])
		ret.append('R')
		j -= 1
if i == j:
	if len(seq) == 0:
		seq.append(line[i])
		ret.append('L')
	elif line[i] > seq[-1]:
		seq.append(line[i])
		ret.append('L')
print(len(seq))
print(''.join(ret))


from collections import deque
n = int(input())
l = deque(map(int, input().split()))

def solve(l):
	l = l.copy()
	result = []
	current = 0
	while l:
		vars = []
		if l[0] > current:
			vars.append((l[0], 'L'))
		if l[-1] > current:
			vars.append((l[-1], 'R'))
		if vars:
			(current, val) = min(vars)
			result.append(val)
			if val == 'L':
				l.popleft()
			else:
				l.pop()
		else:
			break
	return ''.join(result)
res = solve(l)
print(len(res))
print(res)

def another(n, a):
	a = a.copy()
	result = []
	L = 'L'
	R = 'R'
	l = 0
	r = n - 1
	lst = 0
	while l <= r:
		cur = []
		if lst < a[l]:
			cur.append((a[l], L))
		if lst < a[r]:
			cur.append((a[r], R))
		cur.sort()
		if len(cur) == 2:
			cur.pop()
		if len(cur) == 1:
			if cur[0][1] == L:
				result.append(L)
				lst = a[l]
				l += 1
			else:
				result.append(R)
				lst = a[r]
				r -= 1
		else:
			break
	return ''.join(result)

def stress_test():
	from random import randint, shuffle
	digits = list(range(1, 10))
	i = 0
	while True:
		n = len(digits)
		shuffle(digits)
		l = deque(digits)
		one = solve(l)
		two = another(n, l)
		if one != two:
			l_lst = ' '.join(map(str, l))
			print(f'TEST #{i} - FAILED: l - {l_lst}. One: {one}, two: {two}')
			break
		else:
			print(f'TEST #{i} - OK')
		i += 1


n = int(input())
f = list(map(int, input().split()))
l = 0
r = n - 1
output = []
memo = 0
count = 0
while l <= r:
	if f[l] < memo and f[r] < memo:
		break
	count += 1
	if f[l] > memo and f[l] < f[r] or f[r] < memo:
		memo = f[l]
		output.append('L')
		l += 1
	else:
		memo = f[r]
		output.append('R')
		r -= 1
print(count)
for i in output:
	print(i, end='')
print('')


n = int(input())
lis = list(map(int, input().split()))
i = 0
j = len(lis) - 1
lis1 = []
last = 0
while i <= j:
	if lis[i] > last and lis[i] < lis[j]:
		lis1.append('L')
		last = lis[i]
		i += 1
	elif lis[j] > last:
		lis1.append('R')
		last = lis[j]
		j -= 1
	elif lis[i] > last:
		lis1.append('L')
		last = lis[i]
		i += 1
	else:
		break
print(len(lis1))
for i in lis1:
	print(i, end='')


n = int(input())
a = list(map(int, input().split()))
start = 0
end = n - 1
count = 0
prev = 0
ans = []
while start <= end:
	if start == end:
		if a[start] > prev:
			count += 1
			ans.append('L')
		break
	if a[start] < a[end]:
		if a[start] > prev:
			count += 1
			prev = a[start]
			start += 1
			ans.append('L')
		elif a[end] > prev:
			count += 1
			prev = a[end]
			end -= 1
			ans.append('R')
		else:
			break
	elif a[end] < a[start]:
		if a[end] > prev:
			count += 1
			prev = a[end]
			end -= 1
			ans.append('R')
		elif a[start] > prev:
			count += 1
			prev = a[start]
			start += 1
			ans.append('L')
		else:
			break
	else:
		count1 = 0
		prev2 = prev
		for i in range(start, end):
			if a[i] > prev2:
				count1 += 1
				prev2 = a[i]
			else:
				break
		count2 = 0
		prev2 = prev
		for i in range(end, start, -1):
			if a[i] > prev2:
				count2 += 1
				prev2 = a[i]
			else:
				break
		count += max(count1, count2)
		if count1 >= count2:
			prev2 = prev
			for i in range(start, end):
				if a[i] > prev2:
					ans.append('L')
					prev2 = a[i]
				else:
					break
		else:
			prev2 = prev
			for i in range(end, start, -1):
				if a[i] > prev2:
					ans.append('R')
					prev2 = a[i]
				else:
					break
		break
print(count)
for c in ans:
	print(c, end='')
print()


from collections import deque
n = int(input())
nums = deque([int(i) for i in input().split()])
ans = []
seq = [0]
while nums:
	if nums[0] < seq[-1]:
		if nums[-1] > seq[-1]:
			seq.append(nums[-1])
			nums.pop()
			ans.append('R')
		else:
			break
	elif nums[-1] < seq[-1]:
		if nums[0] > seq[-1]:
			seq.append(nums[0])
			nums.popleft()
			ans.append('L')
		else:
			break
	elif nums[-1] > nums[0]:
		seq.append(nums[0])
		nums.popleft()
		ans.append('L')
	else:
		seq.append(nums[-1])
		nums.pop()
		ans.append('R')
print(len(ans))
print(''.join(ans))


length = input()
elements = input()
elements = elements.split(' ')
previous_element = 0
output = ''
left_pos = 0
right_pos = int(length) - 1
move_available = True
while move_available and left_pos != right_pos:
	left_num = int(elements[left_pos])
	right_num = int(elements[right_pos])
	if left_num < right_num and left_num > previous_element or (right_num < previous_element and previous_element < left_num):
		output += 'L'
		left_pos += 1
		previous_element = left_num
	elif right_num < left_num and right_num > previous_element or (left_num < previous_element and previous_element < right_num):
		output += 'R'
		right_pos -= 1
		previous_element = right_num
	else:
		move_available = False
if left_pos == right_pos:
	numb = int(elements[left_pos])
	if numb > previous_element:
		output += 'L'
print(len(output))
print(output)


n = int(input())
l = list(map(int, input().strip().split()))
val = []
ans = []
i = 0
j = n - 1
x = min(l[0], l[-1])
val.append(x)
if x == l[0]:
	ans.append('L')
	i = 1
else:
	ans.append('R')
	j -= 1
while True:
	if i >= n or j < 0:
		break
	if min(l[i], l[j]) > x:
		x = min(l[i], l[j])
	elif max(l[i], l[j]) > x:
		x = max(l[i], l[j])
	else:
		break
	if x == l[i]:
		val.append(l[i])
		ans.append('L')
		i += 1
	else:
		ans.append('R')
		val.append(l[j])
		j -= 1
	if i > j:
		break
print(len(ans))
print(''.join(ans))


k = int(input())
numbers = [int(x) for x in input().split()]
output = ''
possible = True
last_removed = 0
first = 0
last = k - 1
while possible and len(numbers) > 0:
	if first == last:
		if numbers[first] > last_removed:
			output += 'L'
			possible = False
		else:
			possible = False
	else:
		l = numbers[first]
		r = numbers[last]
		if l < r:
			if l > last_removed:
				output += 'L'
				first += 1
				last_removed = l
			elif r > last_removed:
				output += 'R'
				last -= 1
				last_removed = r
			else:
				possible = False
		elif r > last_removed:
			output += 'R'
			last -= 1
			last_removed = r
		elif l > last_removed:
			output += 'L'
			first += 1
			last_removed = l
		else:
			possible = False
print(len(output))
print(output)


n = int(input())
array = list(map(int, input().split()))
ceil_left = []
last = -1
ind_first = 0
count = 0
for i in range(n):
	if array[i] > last:
		last = array[i]
		count += 1
	else:
		for j in range(count, 0, -1):
			ceil_left.append(j)
		last = array[i]
		ind_first = ind_first + count
		count = 1
for j in range(1, count + 1):
	ceil_left.append(j)
ceil_right = []
last = -1
ind_first = 0
count = 0
r_array = array[::-1]
for i in range(n):
	if r_array[i] > last:
		last = r_array[i]
		count += 1
	else:
		for j in range(count, 0, -1):
			ceil_right.append(j)
		last = r_array[i]
		ind_first = ind_first + count
		count = 1
for j in range(1, count + 1):
	ceil_right.append(j)
ceil_right.reverse()
left = 0
right = n - 1
count = 0
s = ''
last = -1
while True:
	if array[left] < array[right] and array[left] > last:
		last = array[left]
		left += 1
		count += 1
		s += 'L'
	elif array[left] > array[right] and array[right] > last:
		last = array[right]
		right -= 1
		count += 1
		s += 'R'
	elif array[left] < array[right] and array[right] > last:
		last = array[right]
		right -= 1
		count += 1
		s += 'R'
	elif array[left] > array[right] and array[left] > last:
		last = array[left]
		left += 1
		count += 1
		s += 'L'
	elif array[left] == array[right] and array[right] > last:
		if left == right:
			count += 1
			left += 1
			s += 'L'
		elif ceil_right[right] >= ceil_left[left]:
			count += ceil_right[right]
			s += 'R' * ceil_right[right]
			print(count)
			print(s)
			exit(0)
		else:
			count += ceil_left[left]
			s = s + 'L' * ceil_left[left]
			print(count)
			print(s)
			exit(0)
	else:
		print(count)
		print(s)
		exit(0)
	if left > right:
		print(count)
		print(s)
		exit(0)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	ans = ''
	curr = 0
	i = 0
	j = n - 1
	while i <= j:
		if a[i] > curr and a[j] > curr:
			if a[i] == a[j]:
				l = ''
				r = ''
				curr1 = curr
				st = i
				while i <= j and a[i] > curr:
					curr = a[i]
					l += 'L'
					i += 1
				while st <= j and a[j] > curr1:
					curr1 = a[j]
					r += 'R'
					j -= 1
				if len(l) >= len(r):
					final = ans + l
				else:
					final = ans + r
				print(len(final))
				print(''.join(final))
				return
			elif a[i] < a[j]:
				curr = a[i]
				ans += 'L'
				i += 1
			else:
				curr = a[j]
				ans += 'R'
				j -= 1
		elif a[i] > curr:
			curr = a[i]
			ans += 'L'
			i += 1
		elif a[j] > curr:
			curr = a[j]
			ans += 'R'
			j -= 1
		else:
			break
	print(len(ans))
	print(''.join(ans))
testcase(1)


n = int(input())
arr = list(map(int, input().split()))
l = 0
r = n - 1
ans = []
res = []
pos = 1
if arr[l] < arr[r]:
	ans.append(arr[l])
	l += 1
	res.append('L')
else:
	ans.append(arr[r])
	r -= 1
	res.append('R')
while pos:
	if l == r:
		if ans[len(ans) - 1] < arr[l]:
			ans.append(arr[l])
			res.append('R')
		pos = 0
	elif arr[l] < arr[r]:
		if arr[l] > ans[len(ans) - 1]:
			ans.append(arr[l])
			l += 1
			res.append('L')
		elif arr[r] > ans[len(ans) - 1]:
			ans.append(arr[r])
			r -= 1
			res.append('R')
		else:
			pos = 0
	elif arr[r] > ans[len(ans) - 1]:
		ans.append(arr[r])
		r -= 1
		res.append('R')
	elif arr[l] > ans[len(ans) - 1]:
		ans.append(arr[l])
		l += 1
		res.append('L')
	else:
		pos = 0
print(len(res))
for el in res:
	print(el, end='')


n = int(input())
a = list(map(int, input().split()))
last = 0
left = 0
right = n - 1
ans = ''
while left <= right:
	if last < a[left] and last < a[right]:
		if a[left] < a[right]:
			ans += 'L'
			last = a[left]
			left += 1
		else:
			ans += 'R'
			last = a[right]
			right -= 1
	elif last < a[left]:
		ans += 'L'
		last = a[left]
		left += 1
	elif last < a[right]:
		ans += 'R'
		last = a[right]
		right -= 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
A = [int(x) for x in input().split()]
l = ''
i = 0
j = len(A) - 1
last = -1
out = []
while i <= j:
	if A[i] > last and (A[i] <= A[j] or A[j] < last):
		out.append('L')
		last = A[i]
		i += 1
	elif A[j] > last and (A[j] <= A[i] or A[i] < last):
		out.append('R')
		last = A[j]
		j -= 1
	else:
		break
print(len(out))
print(''.join(out))


from collections import *
n = int(input())
M = deque(list(map(int, input().split())))
ans = []
last = None
while len(M) > 0:
	if ans == []:
		if M[-1] <= M[0]:
			ans += ['R']
			last = M[-1]
			M.pop()
		else:
			ans += ['L']
			last = M[0]
			M.popleft()
	else:
		if M[-1] <= last and M[0] <= last:
			break
		if M[-1] <= last:
			ans += ['L']
			last = M[0]
			M.popleft()
			continue
		if M[0] <= last:
			ans += ['R']
			last = M[-1]
			M.pop()
			continue
		if M[0] <= M[-1]:
			ans += ['L']
			last = M[0]
			M.popleft()
		elif M[-1] <= M[0]:
			ans += ['R']
			last = M[-1]
			M.pop()
print(len(ans))
print(''.join(ans))


def solve(n, ls):
	start = 0
	end = len(ls) - 1
	answers = []
	last = -1
	while start <= end:
		if start == end:
			if last <= ls[start]:
				answers.append('L')
				break
		if last < ls[start] and (ls[start] < ls[end] or last > ls[end]):
			last = ls[start]
			answers.append('L')
			start += 1
		elif last < ls[end]:
			last = ls[end]
			answers.append('R')
			end -= 1
		else:
			break
	return answers
n = input()
ls = [*map(int, input().split(' '))]
ans = solve(n, ls)
print(len(ans))
print(''.join(ans))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
ans = []
l = 0
r = n - 1
last = -1
while l <= r:
	if a[l] > last and a[r] > last:
		if a[l] < a[r]:
			ans.append('L')
			last = a[l]
			l += 1
		elif a[r] < a[l]:
			ans.append('R')
			last = a[r]
			r -= 1
		else:
			break
	elif a[l] > last:
		last = a[l]
		ans.append('L')
		l += 1
	elif a[r] > last:
		last = a[r]
		ans.append('R')
		r -= 1
	else:
		break
ol = last
Llen = 0
i = l
while i <= r and a[i] > last:
	Llen += 1
	last = a[i]
	i += 1
Rlen = 0
last = ol
i = r
while i >= l and a[i] > last:
	Rlen += 1
	last = a[i]
	i -= 1
if Rlen >= Llen:
	temp = ['R'] * Rlen
else:
	temp = ['L'] * Llen
print(len(ans) + len(temp))
print(*ans, *temp, sep='')


from collections import deque
n = int(input())
a = (int(x) for x in input().split())
q = deque(a)
last = -1
ans = []
while len(q) > 0:
	if q[0] < last and q[-1] < last:
		break
	if q[0] < q[-1] and q[0] > last or q[-1] < last:
		ans.append('L')
		last = q.popleft()
	else:
		ans.append('R')
		last = q.pop()
print(len(ans))
print(*ans, sep='')


n = int(input())
a = [int(i) for i in input().split()]
new = [0]
s = ''
i = 0
j = -1
while True:
	if n - i < -j:
		break
	if a[i] > new[-1] and a[j] > new[-1]:
		if a[i] < a[j]:
			new.append(a[i])
			s += 'L'
			i += 1
		else:
			new.append(a[j])
			s += 'R'
			j -= 1
	elif a[i] > new[-1] or a[j] > new[-1]:
		if a[i] > new[-1]:
			new.append(a[i])
			s += 'L'
			i += 1
		else:
			new.append(a[j])
			s += 'R'
			j -= 1
	else:
		break
print(len(new) - 1)
print(s)


n = int(input())
a = list(map(int, input().split()))
c = 0
l = 0
r = n - 1
ans = []
while len(ans) != n:
	if l < n and (a[r] >= a[l] or a[r] < c) and (a[l] > c):
		ans.append('L')
		c = max(a[l], c)
		l += 1
	elif r > -1 and a[r] > c:
		ans.append('R')
		c = max(a[r], c)
		r -= 1
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = [int(i) for i in input().split()]
b = 0
c = 0
z = 0
k = 0
y = []
while b + c < n:
	d = a[b]
	e = a[n - c - 1]
	if d < e:
		if d > z:
			z = d
			y.append('L')
			b += 1
		elif e > z:
			z = e
			y.append('R')
			c += 1
		else:
			break
	elif e > z:
		z = e
		y.append('R')
		c += 1
	elif d > z:
		z = d
		y.append('L')
		b += 1
	else:
		break
	k += 1
print(k)
print(''.join((str(i) for i in y)))


n = int(input())
al = list((int(x) for x in input().split()))
s = 'L'
l = 1
na = []
r = n - 1
no = al[0]
if al[0] > al[n - 1]:
	s = 'R'
	l = 0
	r = n - 2
	no = al[n - 1]
c = 1
while l <= r:
	if al[l] > no and al[r] > no:
		if al[l] > al[r]:
			s = s + 'R'
			no = al[r]
			r -= 1
			c += 1
		else:
			s = s + 'L'
			no = al[l]
			l += 1
			c += 1
	elif al[l] > no:
		s = s + 'L'
		no = al[l]
		l += 1
		c += 1
	elif al[r] > no:
		s = s + 'R'
		no = al[r]
		r -= 1
		c += 1
	else:
		break
print(c)
print(s)


N = int(input())
a = [int(x) for x in input().split(' ')]
seq = []
ultimo = len(a) - 1
primeiro = 0
maior = 0
flag = True
while flag:
	if primeiro == ultimo:
		if a[primeiro] > maior:
			seq.append('L')
			flag = False
		else:
			flag = False
	elif primeiro < ultimo:
		if a[primeiro] < a[ultimo]:
			if a[primeiro] > maior:
				maior = a[primeiro]
				primeiro += 1
				seq.append('L')
			elif a[ultimo] > maior:
				maior = a[ultimo]
				ultimo -= 1
				seq.append('R')
			else:
				flag = False
		elif a[ultimo] > maior:
			maior = a[ultimo]
			ultimo -= 1
			seq.append('R')
		elif a[primeiro] > maior:
			maior = a[primeiro]
			primeiro += 1
			seq.append('L')
		else:
			flag = False
	else:
		flag = False
print(len(seq))
print(*seq, sep='')


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
cnt = 0
ans = []
last = 0
while cnt < n and max(a[0], a[-1]) > last:
	cnt += 1
	if a[0] > last and (a[0] < a[-1] or a[-1] <= last):
		ans.append('L')
		last = a.popleft()
	else:
		ans.append('R')
		last = a.pop()
print(cnt)
print(''.join(ans))


n = int(input())
a = list(map(int, input().split()))
s = []
(left, right, last) = (0, -1, 0)
while left <= len(a) + right:
	if last < a[left] and (a[left] <= a[right] or a[right] < last):
		s.append('L')
		last = a[left]
		left += 1
	elif last < a[right] and (a[right] <= a[left] or a[left] < last):
		s.append('R')
		last = a[right]
		right -= 1
	else:
		break
print(left - right - 1)
print(''.join(s))


n = int(input())
a = list(map(int, input().split()))
count = 0
res = []
left = 0
right = n - 1
last = 0
i = 0
while 1:
	if a[left] > last and a[right] > last:
		if a[left] < a[right]:
			count += 1
			res.append('L')
			last = a[left]
			left += 1
		else:
			count += 1
			res.append('R')
			last = a[right]
			right -= 1
	elif a[left] > last:
		count += 1
		res.append('L')
		last = a[left]
		left += 1
	elif a[right] > last:
		count += 1
		res.append('R')
		last = a[right]
		right -= 1
	else:
		break
	i += 1
	if i == n:
		break
print(count)
print(''.join(res))


N = int(input())
a = list(map(int, input().split()))
pre = -1
(L, R) = (0, N - 1)
d = []
while L < N and R >= 0 and (L <= R):
	l = a[L]
	r = a[R]
	if pre < l and pre < r:
		if l > r:
			d.append('R')
			pre = a[R]
			R -= 1
		elif r > l:
			d.append('L')
			pre = a[L]
			L += 1
		else:
			d1 = []
			d2 = []
			R1 = R
			L1 = L
			pre1 = pre
			pre2 = pre
			while L <= R1:
				if pre1 < a[R1]:
					d1.append('R')
					pre1 = a[R1]
					R1 -= 1
				else:
					break
			while L1 <= R:
				if pre2 < a[L1]:
					d2.append('L')
					pre2 = a[L1]
					L1 += 1
				else:
					break
			if len(d1) > len(d2):
				d += d1
				break
			else:
				d += d2
				break
	elif pre < l:
		d.append('L')
		pre = a[L]
		L += 1
	elif pre < r:
		d.append('R')
		pre = a[R]
		R -= 1
	else:
		break
print(len(d))
print(''.join(d))


import sys
input = sys.stdin.buffer.readline
n = int(input())
A = list(map(int, input().split()))
from collections import deque
A = deque(A)
ans = []
B = [-1]
import copy
while True:
	if len(A) >= 2:
		if A:
			x = A.popleft()
		if A:
			y = A.pop()
		if x < y:
			if B[-1] < x:
				B.append(x)
				ans.append('L')
				A.append(y)
			elif B[-1] < y:
				B.append(y)
				ans.append('R')
				A.appendleft(x)
			else:
				break
		elif x == y:
			if B[-1] >= x:
				break
			temp1 = copy.copy(ans)
			cur1 = x
			temp1.append('L')
			for i in range(len(A)):
				if A[i] > cur1:
					temp1.append('L')
					cur1 = A[i]
				else:
					break
			temp2 = copy.copy(ans)
			cur2 = y
			temp2.append('R')
			for i in range(len(A)):
				if A[len(A) - 1 - i] > cur2:
					temp2.append('R')
					cur2 = A[len(A) - 1 - i]
				else:
					break
			if len(temp1) >= len(temp2):
				ans = temp1
				break
			else:
				ans = temp2
				break
		elif B[-1] < y:
			B.append(y)
			ans.append('R')
			A.appendleft(x)
		elif B[-1] < x:
			B.append(x)
			ans.append('L')
			A.append(y)
		else:
			break
	elif len(A) == 1:
		x = A.pop()
		if B[-1] < x:
			B.append(x)
			ans.append('L')
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
ai = list(map(int, input().split()))
ans = [0]
p = 0
i = 0
j = n - 1
anss = []
flag = 0
while i <= j:
	if ai[i] < ai[j]:
		if ai[i] > ans[-1]:
			ans.append(ai[i])
			anss.append('L')
			i += 1
		elif ai[j] > ans[-1]:
			ans.append(ai[j])
			anss.append('R')
			j -= 1
		else:
			break
	elif ai[i] > ai[j]:
		if ai[j] > ans[-1]:
			ans.append(ai[j])
			anss.append('R')
			j -= 1
		elif ai[i] > ans[-1]:
			ans.append(ai[i])
			anss.append('L')
			i += 1
		else:
			break
	else:
		p = i
		flag = 1
		break
if flag == 1:
	left = [ans[-1]]
	leftt = []
	right = [ans[-1]]
	rightt = []
	while i <= j:
		if ai[i] > left[-1]:
			left.append(ai[i])
			leftt.append('L')
			i += 1
		else:
			break
	i = p
	while j >= i:
		if ai[j] > right[-1]:
			right.append(ai[j])
			rightt.append('R')
			j -= 1
		else:
			break
	if len(left) > len(right):
		anss += leftt
	else:
		anss += rightt
print(len(anss))
print(''.join(anss))


def main():
	input()
	a = [int(x) for x in input().split(' ')]
	n = len(a)
	(l, r) = (0, n - 1)
	res = []
	last = 0
	picked = True
	while l <= r and picked:
		picked = False
		if last < a[l] and last < a[r]:
			if a[l] < a[r]:
				last = a[l]
				res.append('L')
				l += 1
			else:
				last = a[r]
				res.append('R')
				r -= 1
			picked = True
			continue
		if last < a[l]:
			last = a[l]
			res.append('L')
			l += 1
			picked = True
			continue
		if last < a[r]:
			last = a[r]
			res.append('R')
			r -= 1
			picked = True
			continue
	print(len(res))
	print(''.join(res))
main()


import collections
n = int(input())
lf = list(map(int, input().split()))
c = collections.deque(lf, n)
rez = []
j = 0
i = 0
while i < n:
	i += 1
	if (c[0] < c[-1]) & (c[0] > j):
		rez.append('L')
		j = c.popleft()
	elif (c[-1] < c[0]) & (c[-1] > j):
		rez.append('R')
		j = c.pop()
	elif c[0] > j:
		rez.append('L')
		j = c.popleft()
	elif c[-1] > j:
		rez.append('R')
		j = c.pop()
	else:
		i -= 1
		break
print(i)
print(''.join(map(str, rez)))


from collections import deque
n = int(input())
a = deque([int(x) for x in input().split()])
cur = -1
ans = ''
while cur < a[0] or cur < a[-1]:
	if a[0] < a[-1]:
		if cur < a[0]:
			ans += 'L'
			cur = a[0]
			a.popleft()
		else:
			ans += 'R'
			cur = a[-1]
			a.pop()
	elif a[0] > a[-1]:
		if cur < a[-1]:
			ans += 'R'
			cur = a[-1]
			a.pop()
		else:
			ans += 'L'
			cur = a[0]
			a.popleft()
	elif len(a) == 1:
		ans += 'R'
		cur = a[-1]
		a.pop()
	elif a[0] == a[-1]:
		cur1 = cur
		cur2 = cur
		b = a.copy()
		c = a.copy()
		count1 = 0
		count2 = 0
		while cur1 < b[0]:
			count1 += 1
			cur1 = b[0]
			b.popleft()
		while cur2 < c[-1]:
			count2 += 1
			cur2 = c[-1]
			c.pop()
		if count1 > count2:
			for i in range(count1):
				ans += 'L'
			break
		else:
			for i in range(count2):
				ans += 'R'
			break
	if len(a) == 0:
		break
print(len(ans))
print(ans)


n = int(input())
sp = list(map(int, input().split()))
pr = 0
posl = ''
l = 0
r = n - 1
while True:
	fl = True
	if sp[l] < sp[r]:
		if sp[l] > pr:
			pr = sp[l]
			l += 1
			posl += 'L'
		elif sp[r] > pr:
			pr = sp[r]
			r -= 1
			posl += 'R'
		else:
			fl = False
	elif sp[r] > pr:
		pr = sp[r]
		r -= 1
		posl += 'R'
	elif sp[l] > pr:
		pr = sp[l]
		l += 1
		posl += 'L'
	else:
		fl = False
	if not fl:
		break
print(len(posl))
print(posl)


import collections
import sys
n = int(input())
if n == 1:
	print(1)
	print('R')
	sys.exit()
de = collections.deque(list(map(int, input().split(' '))))
l = de.popleft()
r = de.pop()
cur = -1
answer = []
for i in range(n - 2):
	if l < r:
		if l > cur:
			cur = l
			answer.append('L')
			l = de.popleft()
		elif r > cur:
			cur = r
			answer.append('R')
			r = de.pop()
		else:
			break
	elif r > cur:
		cur = r
		answer.append('R')
		r = de.pop()
	elif l > cur:
		cur = l
		answer.append('L')
		l = de.popleft()
	else:
		break
if l < r:
	if l > cur:
		answer.append('L')
		answer.append('R')
	elif r > cur:
		answer.append('R')
elif r > cur:
	answer.append('R')
	answer.append('L')
elif l > cur:
	answer.append('L')
print(len(answer))
for char in answer:
	print(char, end='')


n = int(input())
l = list(map(int, input().split()))
ans = []
j = 0
k = n - 1
seq = [0]
if n == 1:
	print(1)
	print('L')
else:
	while n:
		if l[j] > seq[-1] and l[k] > seq[-1]:
			if l[j] > l[k]:
				ans.append('R')
				seq.append(l[k])
				k -= 1
				n -= 1
			else:
				ans.append('L')
				seq.append(l[j])
				j += 1
				n -= 1
		elif l[j] > seq[-1]:
			ans.append('L')
			seq.append(l[j])
			j += 1
			n -= 1
		elif l[k] > seq[-1]:
			ans.append('R')
			seq.append(l[k])
			k -= 1
			n -= 1
		else:
			break
	print(len(ans))
	print(*ans, sep='')


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
cond = True
output = []
lastWritten = -1
while j - i + 1 >= 1:
	if lastWritten < a[i] and lastWritten < a[j]:
		if a[i] < a[j]:
			output.append('L')
			lastWritten = a[i]
			i += 1
		else:
			lastWritten = a[j]
			output.append('R')
			j -= 1
	elif lastWritten < a[i]:
		output.append('L')
		lastWritten = a[i]
		i += 1
	elif lastWritten < a[j]:
		lastWritten = a[j]
		output.append('R')
		j -= 1
	else:
		break
print(len(output))
print(''.join(output))


s = int(input())
a = [int(z) for z in input().split()]
s -= 1
last = 0
n = 0
seq = ''
i = 0
j = s
while s > -1:
	if a[i] > last and a[j] > last:
		if a[i] <= a[j]:
			last = a[i]
			n += 1
			seq += 'L'
			i += 1
		else:
			last = a[j]
			n += 1
			seq += 'R'
			j -= 1
	elif a[i] > last:
		last = a[i]
		n += 1
		seq += 'L'
		i += 1
	elif a[j] > last:
		last = a[j]
		n += 1
		seq += 'R'
		j -= 1
	else:
		break
	s -= 1
print(n)
print(seq)


n = int(input())
a = list(map(int, input().split()))
start = 0
end = n - 1
prev = 0
ans = ''
while start <= end:
	if start != end and a[start] == a[end]:
		c1 = 1
		temp = a[start]
		p = start + 1
		q = end
		while p < q:
			if a[p] > temp:
				c1 += 1
				temp = a[p]
				p = p + 1
			else:
				break
		c2 = 1
		temp = a[end]
		p = start
		q = end - 1
		while p < q:
			if a[q] > temp:
				c2 += 1
				temp = a[q]
				q = q - 1
			else:
				break
		if c1 >= c2:
			for k in range(c1):
				ans = ans + 'L'
		else:
			for k in range(c2):
				ans = ans + 'R'
		break
	elif a[start] > prev and a[end] > prev:
		if a[start] < a[end]:
			ans = ans + 'L'
			prev = a[start]
			start = start + 1
		else:
			ans = ans + 'R'
			prev = a[end]
			end = end - 1
	elif a[start] > prev:
		ans = ans + 'L'
		prev = a[start]
		start = start + 1
	elif a[end] > prev:
		ans = ans + 'R'
		prev = a[end]
		end = end - 1
	else:
		break
print(len(ans))
print(ans)


from math import *
n = int(input())
a = list(map(int, input().split(' ')))
i = 0
j = n - 1
l = []
a1 = []
a2 = []
curr = 0
while i <= j:
	if a[i] > a[j]:
		if a[j] > curr:
			curr = a[j]
			l.append('R')
			j -= 1
		elif a[i] > curr:
			curr = a[i]
			l.append('L')
			i += 1
		else:
			break
	elif a[j] > a[i]:
		if a[i] > curr:
			curr = a[i]
			l.append('L')
			i += 1
		elif a[j] > curr:
			curr = a[j]
			l.append('R')
			j -= 1
		else:
			break
	elif i == j:
		if a[i] > curr:
			l.append('L')
			i += 1
			j -= 1
		break
	elif a[i] == a[j]:
		curra = curr
		currb = curr
		k = i
		while k < j:
			if a[k] > curra:
				curra = a[k]
				a1.append('L')
			else:
				break
			k += 1
		k = j
		while k > i:
			if a[k] > currb:
				currb = a[k]
				a2.append('R')
			else:
				break
			k -= 1
		break
	else:
		break
print(len(l) + max(len(a1), len(a2)))
if len(a1) > len(a2):
	l = l + a1
else:
	l = l + a2
for i in l:
	print(i, end='')
print()


n = int(input())
x = list(map(int, input().strip().split()))
i = 0
j = n - 1
v = -1
steps = ''
while i != j:
	if x[i] > x[j]:
		if x[j] > v:
			steps += 'R'
			v = x[j]
			j -= 1
		elif x[i] > v:
			steps += 'L'
			v = x[i]
			i += 1
		else:
			break
	elif x[j] > x[i]:
		if x[i] > v:
			steps += 'L'
			v = x[i]
			i += 1
		elif x[j] > v:
			steps += 'R'
			v = x[j]
			j -= 1
		else:
			break
if x[i] > v:
	steps += 'R'
print(len(steps))
print(steps)


def solve():
	N = int(input())
	A = list(map(int, input().split()))
	ans = ''
	l = 0
	r = N - 1
	old = 0
	while l <= r:
		if A[l] < A[r]:
			if old < A[l]:
				old = A[l]
				ans += 'L'
				l += 1
			elif old < A[r]:
				old = A[r]
				ans += 'R'
				r -= 1
			else:
				break
		elif old < A[r]:
			old = A[r]
			ans += 'R'
			r -= 1
		elif old < A[l]:
			old = A[l]
			ans += 'L'
			l += 1
		else:
			break
	print(len(ans))
	print(ans)
solve()


from sys import stdin
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
last = 0
ans_str = ''
(l, r) = (0, n - 1)
while True:
	if r == l:
		if last < a[l]:
			ans_str += 'L'
			last = a[l]
		break
	elif r - l == 1:
		if a[l] < a[r]:
			if a[l] > last:
				ans_str += 'L'
				ans_str += 'R'
			elif a[r] > last:
				ans_str += 'R'
		elif a[r] < a[l]:
			if a[r] > last:
				ans_str += 'R'
				ans_str += 'L'
			elif a[l] > last:
				ans_str += 'L'
		elif a[l] > last:
			ans_str += 'L'
		break
	if a[l] > a[r]:
		if a[r] > last:
			ans_str += 'R'
			last = a[r]
			r -= 1
		elif a[l] > last:
			ans_str += 'L'
			last = a[l]
			l += 1
		else:
			break
	elif a[r] > a[l]:
		if a[l] > last:
			ans_str += 'L'
			last = a[l]
			l += 1
		elif a[r] > last:
			if a[r] > last:
				ans_str += 'R'
				last = a[r]
				r -= 1
		else:
			break
	elif a[l] < last:
		if a[l + 1] <= a[r - 1]:
			last = a[l]
			l += 1
		else:
			last = a[r]
			r -= 1
	else:
		break
print(len(ans_str))
print(ans_str)


n = int(input())
s = list(map(int, input().split()))
res = []
prev = -1
left = 0
right = len(s) - 1
while right - left >= 0:
	a = s[left]
	b = s[right]
	if max(a, b) <= prev:
		break
	if prev < a <= b or b < prev:
		prev = a
		left += 1
		res.append('L')
	else:
		prev = b
		right -= 1
		res.append('R')
print(len(res))
print(''.join(res))


n = int(input())
a = list(map(int, input().split()))

def from_left(at, prv):
	res = []
	while at < n and a[at] > prv:
		res.append('L')
		prv = a[at]
		at += 1
	return res

def from_rigt(at, prv):
	res = []
	while at >= 0 and a[at] > prv:
		res.append('R')
		prv = a[at]
		at -= 1
	return res
ans = []
prv = -1
(L, R) = (0, n - 1)
while L <= R:
	if a[L] <= prv and a[R] <= prv:
		break
	if a[L] == a[R]:
		left = from_left(L, prv)
		right = from_rigt(R, prv)
		ans += left if len(left) > len(right) else right
		break
	if a[R] > a[L] > prv:
		ans.append('L')
		prv = a[L]
		L += 1
	elif a[L] > a[R] > prv:
		ans.append('R')
		prv = a[R]
		R -= 1
	elif a[L] > prv:
		ans.append('L')
		prv = a[L]
		L += 1
	elif a[R] > prv:
		ans.append('R')
		prv = a[R]
		R -= 1
print(len(ans))
print(''.join(ans))


def vozrastanie(n, lst):
	(maximum, result) = (0, '')
	(left, right) = (0, n - 1)
	while left <= right:
		if lst[left] > maximum and lst[right] > maximum:
			if lst[left] <= lst[right]:
				maximum = lst[left]
				result += 'L'
				left += 1
			else:
				maximum = lst[right]
				result += 'R'
				right -= 1
		elif lst[left] > maximum:
			maximum = lst[left]
			result += 'L'
			left += 1
		elif lst[right] > maximum:
			maximum = lst[right]
			result += 'R'
			right -= 1
		else:
			break
	return (len(result), result)
m = int(input())
arr = [int(i) for i in input().split()]
for elem in vozrastanie(m, arr):
	print(elem)


n = int(input())
a = list(map(int, input().split()))
end = n - 1
start = 0
out = ''
mylist = []
while True:
	if len(out) == 0:
		if a[start] < a[end]:
			out += 'L'
			mylist.append(a[start])
			start += 1
		else:
			out += 'R'
			mylist.append(a[end])
			end -= 1
	elif a[start] < a[end] and a[start] > mylist[len(mylist) - 1] or (a[start] > a[end] and a[end] < mylist[len(mylist) - 1] and (a[start] > mylist[len(mylist) - 1])):
		mylist.append(a[start])
		out += 'L'
		start += 1
	elif a[start] < a[end] and a[end] > mylist[len(mylist) - 1] or (a[start] > a[end] and a[end] > mylist[len(mylist) - 1]):
		mylist.append(a[end])
		out += 'R'
		end -= 1
	elif start == end and a[start] > mylist[len(mylist) - 1]:
		out += 'L'
		break
	else:
		break
print(len(out))
print(out)


qtd = int(input())
entry = list(map(int, input().split()))
maxSeq = 0
actionsOrder = []
seq = []
first = 0
last = len(entry) - 1
if entry[first] < entry[last]:
	seq.append(entry[first])
	first += 1
	actionsOrder.append('L')
else:
	seq.append(entry[last])
	last -= 1
	actionsOrder.append('R')
maxSeq += 1
cont = True
while cont:
	if maxSeq == len(entry):
		cont = False
		continue
	if seq[len(seq) - 1] > entry[first] and seq[len(seq) - 1] > entry[last]:
		cont = False
		continue
	if entry[first] < entry[last] and entry[first] > seq[len(seq) - 1]:
		seq.append(entry[first])
		first += 1
		actionsOrder.append('L')
	elif entry[last] < entry[first] and entry[last] > seq[len(seq) - 1]:
		seq.append(entry[last])
		last -= 1
		actionsOrder.append('R')
	elif entry[first] > entry[last] and entry[first] > seq[len(seq) - 1]:
		seq.append(entry[first])
		first += 1
		actionsOrder.append('L')
	else:
		seq.append(entry[last])
		last -= 1
		actionsOrder.append('R')
	maxSeq += 1
print(maxSeq)
print(''.join(actionsOrder))


n = int(input())
a = [int(x) for x in input().split()]
m = 0
sol = ''
while len(a) > 0:
	if a[0] > m and a[-1] > m and (a[0] != a[-1]):
		if a[0] < a[-1]:
			sol += 'L'
			m = a[0]
			a.pop(0)
		else:
			sol += 'R'
			m = a[-1]
			a.pop(-1)
	elif a[0] > m and a[-1] > m and (a[0] == a[-1]):
		k1 = 1
		k2 = 1
		s2 = sol + 'L'
		s3 = sol + 'R'
		for i in range(1, len(a)):
			if a[i] > a[i - 1]:
				s2 += 'L'
			else:
				break
		i = len(a) - 2
		while i >= 0:
			if a[i] > a[i + 1]:
				s3 += 'R'
			else:
				break
			i -= 1
		if len(s2) > len(s3):
			print(len(s2))
			print(s2)
			exit()
		else:
			print(len(s3))
			print(s3)
			exit()
	elif a[0] > m:
		sol += 'L'
		m = a[0]
		a.pop(0)
	elif a[-1] > m:
		sol += 'R'
		m = a[-1]
		a.pop(-1)
	else:
		break
print(len(sol))
print(sol)


n = int(input())
a = list(map(int, input().split()))
low = 0
high = n - 1
last = 0
count = 1
ans = ''
if a[low] < a[high]:
	last = a[low]
	ans += 'L'
	low += 1
else:
	last = a[high]
	ans += 'R'
	high -= 1
while low <= high:
	if last < a[low] < a[high]:
		last = a[low]
		ans += 'L'
		count += 1
		low += 1
	elif last < a[high] < a[low]:
		last = a[high]
		ans += 'R'
		count += 1
		high -= 1
	elif last < a[low]:
		last = a[low]
		ans += 'L'
		count += 1
		low += 1
	elif last < a[high]:
		last = a[high]
		ans += 'R'
		count += 1
		high -= 1
	else:
		break
print(count)
print(ans)


n = int(input())
a = list(map(int, input().split()))
(l, ans) = ([], [])
(left, right, cnt, cnta) = (0, n - 1, 0, n)
while True:
	if cnta == 0:
		break
	if cnt == 0:
		if a[left] > a[right]:
			cnt += 1
			last = a[right]
			ans.append('R')
			cnta -= 1
			right -= 1
		else:
			cnt += 1
			last = a[left]
			ans.append('L')
			cnta -= 1
			left += 1
	elif a[left] <= a[right] and a[left] > last:
		cnt += 1
		last = a[left]
		ans.append('L')
		cnta -= 1
		left += 1
	elif a[left] <= a[right] and a[left] < last:
		if a[right] > last:
			cnt += 1
			last = a[right]
			ans.append('R')
			cnta -= 1
			right -= 1
		else:
			break
	elif a[right] <= a[left] and a[right] > last:
		cnt += 1
		last = a[right]
		ans.append('R')
		cnta -= 1
		right -= 1
	elif a[right] <= a[left] and a[right] < last:
		if a[left] > last:
			cnt += 1
			last = a[left]
			ans.append('L')
			cnta -= 1
			left += 1
		else:
			break
print(cnt)
print(''.join(ans))


import collections
n = int(input())
lf = list(map(int, input().split()))
c = collections.deque(lf, n)
rez = []
j = 0
i = 0
b = False
while i < n:
	if b:
		break
	i += 1
	if (c[0] < c[-1]) & (c[0] > j):
		rez.append('L')
		j = c.popleft()
	elif (c[-1] < c[0]) & (c[-1] > j):
		rez.append('R')
		j = c.pop()
	elif (c[0] == c[-1]) & (c[0] > j) & (len(c) > 1):
		b = True
		rez1 = [s for s in rez]
		c1 = collections.deque(c, n - len(rez))
		j1 = j
		while c1[-1] > j1:
			rez1.append('R')
			j1 = c1.pop()
		while c[0] > j:
			rez.append('L')
			j = c.popleft()
		if len(rez1) > len(rez):
			print(len(rez1))
			print(''.join(map(str, rez1)))
		else:
			print(len(rez))
			print(''.join(map(str, rez)))
	elif c[0] > j:
		rez.append('L')
		j = c.popleft()
	elif c[-1] > j:
		rez.append('R')
		j = c.pop()
	else:
		i -= 1
		break
if not b:
	print(i)
	print(''.join(map(str, rez)))


num = int(input().strip())
n = [int(i) for i in input().strip().split()]
first = 0
last = num - 1
ans = []
an = []
ctr = 1
if n[first] < n[last]:
	ans.append('L')
	an.append(n[first])
	first += 1
else:
	ans.append('R')
	an.append(n[last])
	last -= 1
while first <= last:
	if n[first] < n[last] and n[first] > an[-1]:
		an.append(n[first])
		ans.append('L')
		ctr += 1
		first += 1
	elif n[last] < n[first] and n[last] > an[-1]:
		an.append(n[last])
		ans.append('R')
		ctr += 1
		last -= 1
	elif n[first] > an[-1]:
		an.append(n[first])
		ans.append('L')
		ctr += 1
		first += 1
	elif n[last] > an[-1]:
		an.append(n[last])
		ans.append('R')
		ctr += 1
		last -= 1
	else:
		break
print(ctr)
print(''.join(ans))


n = int(input())
a = list(map(int, input().split(' ')))
res = 0
s = ''
i = 0
j = n - 1
last = min(a[i], a[j])
if a[i] < a[j]:
	i += 1
	res += 1
	s += 'L'
else:
	j -= 1
	res += 1
	s += 'R'
while i < j:
	if a[i] < a[j]:
		if a[i] > last:
			last = a[i]
			res += 1
			s += 'L'
			i += 1
		elif a[j] > last:
			last = a[j]
			res += 1
			s += 'R'
			j -= 1
		else:
			break
	elif a[j] < a[i]:
		if a[j] > last:
			last = a[j]
			res += 1
			s += 'R'
			j -= 1
		elif a[i] > last:
			last = a[i]
			res += 1
			s += 'L'
			i += 1
		else:
			break
if i == j and a[i] > last:
	res += 1
	s += 'L'
print(res)
print(s)


from math import inf
(delete_me, data) = (input(), list(map(int, input().split())))
del delete_me
main = 0
path = ''
(left, right) = (0, -1)
while left != len(data) + right + 1:
	minn = min(data[left], data[right], key=lambda a: abs(a - main) if main < a else inf)
	if minn < main:
		break
	if minn == data[left]:
		path += 'L'
		left += 1
	else:
		path += 'R'
		right -= 1
	main = minn
print(len(path))
print(path)


n = int(input())
A = list(map(int, input().split()))
from collections import deque
A = deque(A)
ans = []
B = [-1]
while True:
	if len(A) >= 2:
		if A:
			x = A.popleft()
		if A:
			y = A.pop()
		if x < y:
			if B[-1] < x:
				B.append(x)
				ans.append('L')
				A.append(y)
			elif B[-1] < y:
				B.append(y)
				ans.append('R')
				A.appendleft(x)
			else:
				break
		elif B[-1] < y:
			B.append(y)
			ans.append('R')
			A.appendleft(x)
		elif B[-1] < x:
			B.append(x)
			ans.append('L')
			A.append(y)
		else:
			break
	elif len(A) == 1:
		x = A.pop()
		if B[-1] < x:
			B.append(x)
			ans.append('L')
	else:
		break
print(len(ans))
print(''.join(ans))


from collections import deque
n = int(input())
a = deque([int(x) for x in input().split()])
cur = -1
ans = ''
while cur < a[0] or cur < a[-1]:
	if a[0] < a[-1]:
		if cur < a[0]:
			ans += 'L'
			cur = a[0]
			a.popleft()
		else:
			ans += 'R'
			cur = a[-1]
			a.pop()
	elif a[0] > a[-1]:
		if cur < a[-1]:
			ans += 'R'
			cur = a[-1]
			a.pop()
		else:
			ans += 'L'
			cur = a[0]
			a.popleft()
	else:
		ans += 'R'
		cur = a[-1]
		a.pop()
	if len(a) == 0:
		break
print(len(ans))
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
new = [0]
s = ''
i = 0
j = -1

def rec(a, i, j):
	c = func(a, i + 1, j, new + [a[i]], s)
	d = func(a, i, j - 1, new + [a[j]], s)
	if c[0] < d[0]:
		return True
	else:
		return False

def func(a, i, j, new, s):
	while True:
		if n - i < -j:
			return (len(new) - 1, s)
			break
		if a[i] > new[-1] and a[j] > new[-1]:
			if a[i] == a[j]:
				if rec(a, i, j):
					new.append(a[j])
					j -= 1
					s += 'R'
				else:
					s += 'L'
					new.append(a[i])
					i += 1
			elif a[i] < a[j]:
				new.append(a[i])
				s += 'L'
				i += 1
			else:
				new.append(a[j])
				s += 'R'
				j -= 1
		elif a[i] > new[-1] or a[j] > new[-1]:
			if a[i] > new[-1]:
				new.append(a[i])
				s += 'L'
				i += 1
			else:
				new.append(a[j])
				s += 'R'
				j -= 1
		else:
			return (len(new) - 1, s)
			break
for j in func(a, i, j, new, s):
	print(j)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
n = input()
n = int(n)
l = [int(x) for x in input().split()]
k = []
ans = 0
i = 0
j = n - 1
temp = 0
while i <= j:
	if max(l[i], l[j]) < temp:
		break
	else:
		if i == j and l[i] > temp:
			k.append('L')
			ans += 1
			break
		if l[i] < l[j] and l[i] > temp:
			k.append('L')
			temp = l[i]
			i += 1
		elif l[i] > l[j] and l[j] > temp:
			k.append('R')
			temp = l[j]
			j -= 1
		elif l[i] > l[j] and l[i] > temp:
			k.append('L')
			temp = l[i]
			i += 1
		elif l[i] < l[j] and l[j] > temp:
			k.append('R')
			temp = l[j]
			j -= 1
		else:
			break
		ans += 1
print(ans)
for i in k:
	print(i, end='')
print('')


R = lambda : map(int, input().split())

def isL():
	k1 = 1
	while i + k1 <= j and a[i + k1] > a[i + k1 - 1]:
		k1 += 1
	k2 = 1
	while j - k2 >= i and a[j - k2] > a[j - k2 + 1]:
		k2 += 1
	return k1 >= k2
(n, a) = (int(input()), list(R()))
res = []
(i, j) = (0, n - 1)
v = 0
while i <= j:
	if a[i] <= v and a[j] <= v:
		break
	elif a[i] > v >= a[j]:
		res.append('L')
		v = a[i]
		i += 1
	elif a[j] > v >= a[i]:
		res.append('R')
		v = a[j]
		j -= 1
	elif a[i] < a[j]:
		res.append('L')
		v = a[i]
		i += 1
	elif a[j] < a[i]:
		res.append('R')
		v = a[j]
		j -= 1
	elif i == j:
		res.append('L')
		v = a[i]
		i += 1
	elif isL():
		res.append('L')
		v = a[i]
		i += 1
	else:
		res.append('R')
		v = a[j]
		j -= 1
res = ''.join(res)
print(len(res))
print(res)


a = int(input())
b = list(map(int, input().split()))
p = 0
i = 0
j = a - 1
k = ''
while i <= j:
	if b[i] > p and b[j] > p:
		if b[i] <= b[j]:
			p = b[i]
			k += 'L'
			i += 1
		else:
			p = b[j]
			k += 'R'
			j -= 1
	elif b[i] > p:
		k += 'L'
		p = b[i]
		i += 1
	elif b[j] > p:
		k += 'R'
		p = b[j]
		j -= 1
	else:
		break
print(len(k), k)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
s = ''
BackNumber = 0
cnt = 0
while l <= r:
	if max(max(a[l], a[r]), BackNumber) > BackNumber:
		cnt += 1
		if min(a[l], a[r]) > BackNumber:
			if a[l] == min(a[l], a[r]):
				s += 'L'
				BackNumber = a[l]
				l += 1
			else:
				s += 'R'
				BackNumber = a[r]
				r -= 1
		elif a[l] == max(a[l], a[r]):
			s += 'L'
			BackNumber = a[l]
			l += 1
		else:
			s += 'R'
			BackNumber = a[r]
			r -= 1
	else:
		break
print(cnt)
print(s)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
ans = [0]
ans1 = ''
while i < j:
	c = 0
	if arr[i] < arr[j] and ans[-1] < arr[i]:
		ans1 += 'L'
		c = 1
		ans.append(arr[i])
		i += 1
	elif arr[i] < arr[j] and ans[-1] < arr[j]:
		ans1 += 'R'
		c = 1
		ans.append(arr[j])
		j -= 1
	if arr[i] > arr[j] and ans[-1] < arr[j]:
		ans1 += 'R'
		c = 1
		ans.append(arr[j])
		j -= 1
	elif arr[i] > arr[j] and ans[-1] < arr[i]:
		ans1 += 'L'
		c = 1
		ans.append(arr[i])
		i += 1
	if c == 0:
		break
if i == j and ans[-1] < arr[i]:
	ans1 += 'L'
print(len(ans1))
print(ans1)


from collections import deque
a = int(input())
a = [int(ai) for ai in input().split()]
res = deque([])
out = deque([])
i = 0
j = len(a) - 1
while True:
	if len(res) >= 1:
		if res[0] < a[i] and res[0] < a[j]:
			if a[i] < a[j]:
				res.appendleft(a[i])
				out.append('L')
				i += 1
			else:
				res.appendleft(a[j])
				out.append('R')
				j -= 1
		elif res[0] < a[i]:
			res.appendleft(a[i])
			out.append('L')
			i += 1
		elif res[0] < a[j]:
			res.appendleft(a[j])
			out.append('R')
			j -= 1
		else:
			break
	elif a[i] < a[j]:
		res.appendleft(a[i])
		out.append('L')
		i += 1
	else:
		res.appendleft(a[j])
		out.append('R')
		j -= 1
res.reverse()
print(len(res))
print(''.join(out))


n = int(input())
a = [int(i) for i in input().split(' ')]
(t, l, r, p) = (0, 0, n - 1, '')
while 1:
	if l > r or t > max(a[l], a[r]):
		break
	elif a[l] > a[r] > t or a[r] > t > a[l]:
		t = a[r]
		r -= 1
		p += 'R'
	else:
		t = a[l]
		l += 1
		p += 'L'
print(len(p))
print(p)


def main():
	n = int(input())
	array = list(map(int, input().split()))
	left = 0
	right = n - 1
	ans = ''
	vals = []
	if array[left] < array[right]:
		vals.append(array[left])
		ans += 'L'
		left += 1
	else:
		vals.append(array[right])
		ans += 'R'
		right -= 1
	while left < right:
		if array[left] < array[right]:
			if array[left] > vals[-1]:
				vals.append(array[left])
				ans += 'L'
				left += 1
			elif array[right] > vals[-1]:
				vals.append(array[right])
				ans += 'R'
				right -= 1
			else:
				break
		elif array[right] > vals[-1]:
			vals.append(array[right])
			ans += 'R'
			right -= 1
		elif array[left] > vals[-1]:
			vals.append(array[left])
			ans += 'L'
			left += 1
		else:
			break
	if left == right:
		if array[left] > vals[-1]:
			vals.append(array[left])
			ans += 'L'
	print(len(ans))
	print(ans)
main()


n = int(input())
a = [int(i) for i in input().split()]
k = 0
l = 0
r = n - 1
ans = ''
p = 0
while k == 0:
	if a[l] < a[r]:
		if a[l] > p:
			ans += 'L'
			p = a[l]
			l += 1
		elif a[r] > p:
			ans += 'R'
			p = a[r]
			r -= 1
		else:
			k = 1
	elif a[r] > p:
		ans += 'R'
		p = a[r]
		r -= 1
	elif a[l] > p:
		ans += 'L'
		p = a[l]
		l += 1
	else:
		k = 1
print(len(ans))
print(ans)


def f(r1):
	global r, lastNum, lPos, rPos
	r.append(r1)
	if r1 == 'L':
		lastNum = a[lPos]
		lPos += 1
	else:
		lastNum = a[rPos]
		rPos -= 1

def onlyLeft(begin):
	global a
	pos = begin
	while a[pos] < a[pos + 1]:
		pos += 1
	return pos - begin + 1

def onlyRight(begin):
	global a
	pos = begin
	while a[pos] < a[pos - 1]:
		pos -= 1
	return begin - pos + 1
n = int(input())
a = list(map(int, input().split()))
r = []
lastNum = -1
lPos = 0
rPos = n - 1
while lPos <= rPos:
	if a[lPos] <= lastNum and a[rPos] <= lastNum:
		break
	if lPos == rPos:
		if a[lPos] > lastNum:
			f('L')
		break
	if a[lPos] == a[rPos]:
		r1 = onlyLeft(lPos)
		r2 = onlyRight(rPos)
		if r1 > r2:
			for i in range(r1):
				r.append('L')
		else:
			for i in range(r2):
				r.append('R')
		break
	if a[lPos] < a[rPos]:
		if a[lPos] > lastNum:
			f('L')
		elif a[rPos] > lastNum:
			f('R')
	if a[lPos] > a[rPos]:
		if a[rPos] > lastNum:
			f('R')
		elif a[lPos] > lastNum:
			f('L')
print(len(r))
print(*r, sep='')


n = int(input())
a = list(map(int, input().split()))
ans = []
cur_min = -1
(l, r) = (0, n - 1)
while l <= r and max(a[l], a[r]) > cur_min:
	if a[l] > cur_min:
		next_step = 'L'
	else:
		next_step = 'R'
	if a[r] > cur_min and a[r] < a[l]:
		next_step = 'R'
	if next_step == 'L':
		cur_min = a[l]
		l += 1
	else:
		cur_min = a[r]
		r -= 1
	ans.append(next_step)
print(len(ans))
print(''.join(ans))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	n = inin()
	a = ain()
	j = 0
	k = n - 1
	f = 0
	s = ''
	while k >= j:
		if a[j] > f and a[k] > f:
			if a[j] < a[k]:
				s += 'L'
				f = a[j]
				j += 1
			else:
				s += 'R'
				f = a[k]
				k -= 1
		elif a[j] > f:
			s += 'L'
			f = a[j]
			j += 1
		elif a[k] > f:
			s += 'R'
			f = a[k]
			k -= 1
		else:
			break
	print(len(s))
	print(s)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


import sys
n = 0
seq = None
for line in sys.stdin:
	if n == 0:
		n = int(line)
	else:
		seq = list(map(int, line.split()))
		break
i = 0
j = n - 1
k = 0
last = 0
ans = ''
while i <= j:
	if seq[i] < seq[j]:
		if last < seq[i]:
			last = seq[i]
			i += 1
			k += 1
			ans += 'L'
		elif last < seq[j]:
			last = seq[j]
			j -= 1
			k += 1
			ans += 'R'
		else:
			break
	elif seq[i] > seq[j]:
		if last < seq[j]:
			last = seq[j]
			j -= 1
			k += 1
			ans += 'R'
		elif last < seq[i]:
			last = seq[i]
			i += 1
			k += 1
			ans += 'L'
		else:
			break
	else:
		if last < seq[i]:
			ti = 0
			l = last
			while i < n and l < seq[i]:
				ti += 1
				l = seq[i]
				i += 1
			tj = 0
			l = last
			while 0 <= j and l < seq[j]:
				tj += 1
				l = seq[j]
				j -= 1
			if ti > tj:
				k += ti
				ans += ti * 'L'
			else:
				k += tj
				ans += tj * 'R'
		break
print(k)
print(ans)


rint = lambda : int(input())
rmint = lambda : map(int, input().split())
rlist = lambda : list(rmint())
n = rint()
a = rlist()
l = 0
r = n - 1
pr = 0
ans = ''

def ex():
	print(len(ans))
	print(ans)
	exit(0)
while l <= r:
	x = a[l]
	y = a[r]
	if x <= pr and y <= pr:
		ex()
	if l == r:
		ans += 'R'
		break
	if x > pr and y > pr:
		if x < y:
			ans += 'L'
			l += 1
			pr = x
		if x > y:
			ans += 'R'
			r -= 1
			pr = y
		if x == y:
			i = l
			while i < r and a[i + 1] > a[i]:
				i += 1
			L = i - l + 1
			i = r
			while i > l and a[i - 1] > a[i]:
				i -= 1
			R = r - i + 1
			if L > R:
				for o in range(L):
					ans += 'L'
			else:
				for o in range(R):
					ans += 'R'
			ex()
	else:
		if x > pr:
			ans += 'L'
			l += 1
			pr = x
		if y > pr:
			ans += 'R'
			r -= 1
			pr = y
ex()


def getLens(arr, low, high, last):
	l1 = 1
	last1 = last
	for i in range(low + 1, high):
		if arr[i] > last:
			last = arr[i]
			l1 += 1
		else:
			break
	l2 = 1
	last = last1
	for i in range(high - 1, low, -1):
		if arr[i] > last:
			last = arr[i]
			l2 += 1
		else:
			break
	return (l1, l2)

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	low = 0
	high = n - 1
	k = 0
	ans = []
	last = 0
	while low < high:
		if arr[low] < arr[high]:
			if arr[low] > last:
				ans.append('L')
				last = arr[low]
				low += 1
			elif arr[high] > last:
				ans.append('R')
				last = arr[high]
				high -= 1
			else:
				break
		elif arr[high] < arr[low]:
			if arr[high] > last:
				ans.append('R')
				last = arr[high]
				high -= 1
			elif arr[low] > last:
				ans.append('L')
				last = arr[low]
				low += 1
			else:
				break
		else:
			if arr[low] <= last:
				break
			last = arr[low]
			(l1, l2) = getLens(arr, low, high, last)
			if l1 >= l2:
				for i in range(l1):
					ans.append('L')
			else:
				for i in range(l2):
					ans.append('R')
			break
	if low == high:
		if arr[low] > last:
			ans.append('L')
	print(len(ans))
	for i in ans:
		print(i, end='')
main()


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		x = [self.next_int() for _ in range(0, n)]
		d = 0
		l = 0
		r = n - 1
		rs = []
		while l <= r:
			if x[l] <= d and x[r] <= d:
				break
			if x[l] <= d:
				rs.append('R')
				d = x[r]
				r -= 1
			elif x[r] <= d:
				rs.append('L')
				d = x[l]
				l += 1
			elif x[r] < x[l] or l == r:
				rs.append('R')
				d = x[r]
				r -= 1
			elif x[l] < x[r]:
				rs.append('L')
				d = x[l]
				l += 1
			else:
				ll = l + 1
				while x[ll] > x[ll - 1]:
					ll += 1
				rr = r - 1
				while x[rr] > x[rr + 1]:
					rr -= 1
				if ll - l > r - rr:
					rs.append('L')
					d = x[l]
					l += 1
				else:
					rs.append('R')
					d = x[r]
					r -= 1
		print(len(rs))
		print(''.join(rs))
Main().solve()


n = int(input())
nums = list(map(int, input().split()))
res = []
left = 0
right = n - 1
cur = -1
for i in range(n):
	l = nums[left]
	r = nums[right]
	if l > cur and r > cur:
		if r > l:
			res.append('L')
			left += 1
			cur = l
		elif r < l:
			res.append('R')
			right -= 1
			cur = r
		else:
			rMax = 0
			lMax = 0
			nCur = cur
			for i in range(left, right + 1):
				if nCur >= nums[i]:
					break
				lMax += 1
				nCur = nums[i]
			nCur = cur
			for i in range(right, left - 1, -1):
				if nCur >= nums[i]:
					break
				rMax += 1
				nCur = nums[i]
			if lMax > rMax:
				while cur < nums[left] and left <= right:
					res.append('L')
					cur = nums[left]
					left += 1
			else:
				while cur < nums[right] and left <= right:
					res.append('R')
					cur = nums[right]
					right -= 1
			break
	elif l > cur:
		res.append('L')
		left += 1
		cur = l
	elif r > cur:
		res.append('R')
		right -= 1
		cur = r
	else:
		break
print(len(res))
for x in res:
	print(x, end='')


def fun(array):
	ans = ''
	count = 0
	(l, r) = (0, n - 1)
	last = -1
	while l <= r:
		if min(array[l], array[r]) <= last:
			break
		if array[l] < array[r]:
			last = array[l]
			ans += 'L'
			l += 1
			count += 1
		elif array[l] > array[r]:
			last = array[r]
			ans += 'R'
			r -= 1
			count += 1
		else:
			break
	ans_1 = ans
	last_1 = last
	l_1 = l
	while l_1 <= r and array[l_1] > last_1:
		ans_1 += 'L'
		last_1 = array[l_1]
		l_1 += 1
	ans_2 = ans
	last_2 = last
	r_2 = r
	while r_2 >= l and array[r_2] > last_2:
		ans_2 += 'R'
		last_2 = array[r_2]
		r_2 -= 1
	if len(ans_1) > len(ans_2):
		ans = ans_1
	else:
		ans = ans_2
	print(len(ans))
	print(ans)
n = int(input())
array = list(map(int, input().split()))
fun(array)


from sys import stdin, stdout
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
P = lambda x: stdout.write(x)
hg = lambda x, y: (y + x - 1) // x * x
N = 10 ** 9 + 7
n = I()
a = list(R())
l = 0
r = n - 1
lst = cnt = 0
s = []
while l <= r:
	if a[l] < lst > a[r]:
		break
	elif a[l] > lst < a[r]:
		if a[l] < a[r]:
			s += ('L',)
			lst = a[l]
			l += 1
		else:
			s += ('R',)
			lst = a[r]
			r -= 1
	elif a[l] > lst:
		s += ('L',)
		lst = a[l]
		l += 1
	else:
		s += ('R',)
		lst = a[r]
		r -= 1
	cnt += 1
print(cnt)
print(*s, sep='')


n = int(input())
l = [int(i) for i in input().split()]
i = 0
j = n - 1
prev = -1
ans = []
s = ''
while i <= j:
	if l[i] < prev and l[j] < prev:
		break
	elif l[i] > prev and l[j] < prev:
		ans.append(l[i])
		prev = l[i]
		i += 1
		s += 'L'
	elif l[j] > prev and l[i] < prev:
		ans.append(l[j])
		prev = l[j]
		j -= 1
		s += 'R'
	else:
		prev = min(l[i], l[j])
		ans.append(min(l[i], l[j]))
		if l[i] < l[j]:
			i += 1
			s += 'L'
		else:
			j -= 1
			s += 'R'
print(len(ans))
print(s)


a = int(input())
z = list(map(int, input().split()))
l = 0
ans = []
r = len(z) - 1
temp = [0]
while l <= r:
	te = min(z[l], z[r])
	if te > temp[-1]:
		if z[l] == te:
			ans.append('L')
			l += 1
		else:
			ans.append('R')
			r -= 1
		temp.append(te)
	elif max(z[l], z[r]) > temp[-1]:
		te = max(z[l], z[r])
		if te > temp[-1]:
			if z[l] == te:
				ans.append('L')
				l += 1
			else:
				ans.append('R')
				r -= 1
		temp.append(te)
	else:
		break
print(len(ans))
print(''.join(map(str, ans)))


n = int(input())
sequencia = [int(i) for i in input().split()]
res = []
lastValue = 0
l = 0
r = len(sequencia) - 1
decide = 0
while l <= r:
	if sequencia[l] < sequencia[r] or decide == 1:
		if lastValue < sequencia[l]:
			res.append('L')
			lastValue = sequencia[l]
			l += 1
		elif lastValue < sequencia[r]:
			res.append('R')
			lastValue = sequencia[r]
			r -= 1
		else:
			break
	elif sequencia[r] < sequencia[l] or decide == 2:
		if lastValue < sequencia[r]:
			res.append('R')
			lastValue = sequencia[r]
			r -= 1
		elif lastValue < sequencia[l]:
			res.append('L')
			lastValue = sequencia[l]
			l += 1
		else:
			break
	else:
		qtdL = 0
		indL = l
		nValue = lastValue
		while indL < len(sequencia) and nValue < sequencia[indL]:
			nValue = sequencia[indL]
			indL += 1
			qtdL += 1
		qtdR = 0
		indR = r
		nValue = lastValue
		while indR >= 0 and nValue < sequencia[indR]:
			nValue = sequencia[indR]
			indR -= 1
			qtdR += 1
		if qtdL > qtdR:
			decide = 1
		else:
			decide = 2
print(len(res))
print(''.join(res))


import sys, math
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
i = 0
j = n - 1
ans = ''
if a[i] == a[j]:
	x1 = 1
	x2 = 1
	last = a[i]
	t = last
	for k in range(i + 1, n):
		if a[k] > t:
			x1 += 1
			t = a[k]
		else:
			break
	t = last
	for k in range(j - 1, -1, -1):
		if a[k] > t:
			x2 += 1
			t = a[k]
		else:
			break
	if x1 >= x2:
		ans += 'L' * x1
	else:
		ans += 'R' * x2
	print(len(ans))
	print(ans)
else:
	if a[i] < a[j]:
		ans += 'L'
		last = a[i]
		i += 1
	else:
		ans += 'R'
		last = a[j]
		j -= 1
	while i <= j:
		if a[i] == a[j] and j - i > 1 and (a[i] > last):
			x1 = 1
			x2 = 1
			last = a[i]
			t = last
			for k in range(i + 1, n):
				if a[k] > t:
					x1 += 1
					t = a[k]
				else:
					break
			t = last
			for k in range(j - 1, -1, -1):
				if a[k] > t:
					x2 += 1
					t = a[k]
				else:
					break
			if x1 >= x2:
				ans += 'L' * x1
			else:
				ans += 'R' * x2
			break
		elif a[i] < a[j]:
			if a[i] > last:
				last = a[i]
				i += 1
				ans += 'L'
			elif a[j] > last:
				last = a[j]
				j -= 1
				ans += 'R'
			else:
				break
		elif a[j] < a[i]:
			if a[j] > last:
				last = a[j]
				j -= 1
				ans += 'R'
			elif a[i] > last:
				last = a[i]
				i += 1
				ans += 'L'
			else:
				break
		else:
			break
	if (i == j or j - i == 1) and a[i] > last:
		ans += 'L'
	print(len(ans))
	print(ans)


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	new = [-1]
	ans = []
	i = 0
	j = n - 1
	while i <= j:
		if num[i] <= num[j]:
			if new[-1] < num[i]:
				ans.append('L')
				new.append(num[i])
				i += 1
			elif new[-1] < num[j]:
				ans.append('R')
				new.append(num[j])
				j -= 1
			else:
				break
		elif new[-1] <= num[j]:
			ans.append('R')
			new.append(num[j])
			j -= 1
		elif new[-1] < num[i]:
			ans.append('L')
			new.append(num[i])
			i += 1
		else:
			break
	print(len(ans))
	print(*ans, sep='')


import sys

def solve(n, res, lsn, count):
	l = 0
	r = len(n) - 1
	while l != r:
		k = min(n[l], n[r])
		if lsn > 0:
			if k < lsn:
				k = max(n[l], n[r])
			if k < lsn:
				break
		lsn = k
		count = count + 1
		if k == n[l]:
			res = res + 'L'
			l = l + 1
		elif k == n[r]:
			res = res + 'R'
			r = r - 1
	if l == r:
		if count != len(n):
			k = n[l]
			if k > lsn:
				lsn = k
				count = count + 1
				res = res + 'L'
	print(count)
	print(res)
sys.stdin.readline().strip()
n = sys.stdin.readline().strip().split()
n = list(map(int, n))
lsn = 0
count = 0
res = ''
solve(n, res, lsn, count)


N = int(input())
a = list(map(int, input().split()))
pre = -1
(L, R) = (0, N - 1)
num = 0
d = []
while L < N and R >= 0 and (L <= R):
	l = a[L]
	r = a[R]
	if pre < l and pre < r:
		if l > r:
			d.append('R')
			pre = a[R]
			R -= 1
		else:
			d.append('L')
			pre = a[L]
			L += 1
	elif pre < l:
		d.append('L')
		pre = a[L]
		L += 1
	elif pre < r:
		d.append('R')
		pre = a[R]
		R -= 1
	else:
		break
	num += 1
print(num)
print(''.join(d))


def subseq(a):
	(i, j) = (0, len(a) - 1)
	seq = []
	moves = []
	last_val = 0
	while i <= j:
		if a[i] < a[j]:
			if a[i] > last_val:
				last_val = a[i]
				moves.append('L')
				i += 1
			elif a[j] > last_val:
				last_val = a[j]
				moves.append('R')
				j -= 1
			else:
				break
		elif a[j] > last_val:
			last_val = a[j]
			moves.append('R')
			j -= 1
		elif a[i] > last_val:
			last_val = a[i]
			moves.append('L')
			i += 1
		else:
			break
	print(len(moves))
	print(''.join(moves))
n = int(input())
ar = list(map(lambda x: int(x), input().strip(' ').split(' ')))
subseq(ar)


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	n = int(input())
	arr = inar()
	counter = 0
	i = 0
	j = n - 1
	res = [(0, 'X')]
	while True:
		if i == j:
			el = arr[i]
			if el > res[-1][0]:
				res.append((el, 'R'))
			break
		tup = [(arr[i], i), (arr[j], j)]
		tup.sort()
		if tup[0][0] > res[-1][0]:
			if tup[0][1] == i:
				res.append((tup[0][0], 'L'))
				i += 1
			else:
				res.append((tup[0][0], 'R'))
				j -= 1
			continue
		if tup[1][0] > res[-1][0]:
			if tup[1][1] == i:
				res.append((tup[1][0], 'L'))
				i += 1
			else:
				res.append((tup[1][0], 'R'))
				j -= 1
			continue
		else:
			break
	print(len(res) - 1)
	for i in range(1, len(res)):
		print(res[i][1], end='')
	print()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
d = list(map(int, input().split()))
s = []
t = 0
i = 0
j = n - 1
back = 0
while i <= j and max(d[i], d[j]) > back:
	if d[i] <= d[j] and d[i] > back or d[j] < back:
		t += 1
		back = d[i]
		s.append('L')
		i += 1
		continue
	elif d[j] > back or d[i] < back:
		t += 1
		back = d[j]
		s.append('R')
		j -= 1
		continue
	break
print(t)
[print(i, end='') for i in s]


import collections
n = int(input())
l = list(map(int, input().split()))
l = collections.deque(l)
c = -1
m = -1
s = ''
flag = 0
while len(l) > 0:
	f = 0
	a = l[0]
	b = l[len(l) - 1]
	g = [a, b]
	g.sort()
	if g[0] > c:
		c = g[0]
		f = 1
	elif g[1] > c:
		c = g[1]
		f = 1
	if f == 0:
		print(len(s))
		print(s)
		flag = 1
		break
	if c == a:
		l.popleft()
		s = s + 'L'
	else:
		l.pop()
		s = s + 'R'
if flag == 0:
	print(len(s))
	print(s)


def f1(lst):
	count = 0
	old = 0
	for i in lst:
		if not i <= old:
			count += 1
			old = i
		else:
			return count
	return count

def f2(lst):
	count = 0
	old = 0
	for i in range(len(lst)):
		if not lst[-i - 1] <= old:
			count += 1
			old = lst[-i - 1]
		else:
			return count
	return count

def makelist(n, e):
	result = []
	for i in range(n):
		result.append(e)
	return result
n = int(input())

def convert(string):
	return string.split(sep=None, maxsplit=-1)

def toint(lst):
	result = []
	for i in lst:
		result.append(int(i))
	return result

def printeach(lst):
	for i in lst:
		print(i, end='')
lst = toint(convert(input()))

def answer(lst):
	done = True
	val = []
	a = 0
	b = len(lst) - 1
	last = 0
	while done:
		try:
			A = lst[a]
			B = lst[b]
		except:
			A = 0
		if a > b + len(lst):
			done = False
		elif A <= last and B <= last:
			done = False
		elif A <= last and B > last:
			val.append('R')
			last = B
			b -= 1
		elif B <= last and A > last:
			val.append('L')
			last = A
			a += 1
		elif A > B:
			val.append('R')
			last = B
			b -= 1
		elif B == A and a != b + len(lst):
			a1 = f1(lst[a:b + 1])
			a2 = f2(lst[a:b + 1])
			if a1 > a2:
				val = val + makelist(a1, 'L')
			else:
				val = val + makelist(a2, 'R')
			done = False
		else:
			val.append('L')
			last = A
			a += 1
	return val
result = answer(lst)
print(len(result))
printeach(result)


from collections import deque
n = int(input())
a = [int(x) for x in input().split()]
q = deque(a)
last = -1
left = [1] * n
right = [1] * n
for i in range(1, n):
	if a[i] < a[i - 1]:
		left[i] = left[i - 1] + 1
for i in range(n - 2, -1, -1):
	if a[i] < a[i + 1]:
		right[i] = right[i + 1] + 1
ans = []
le = 0
ri = n - 1
while len(q) > 0:
	if q[0] <= last and q[-1] <= last:
		break
	if (q[0] < q[-1] or (q[0] == q[-1] and right[le] > left[ri])) and q[0] > last or q[-1] <= last:
		ans.append('L')
		le += 1
		last = q.popleft()
	else:
		ans.append('R')
		ri -= 1
		last = q.pop()
print(len(ans))
print(*ans, sep='')


n = int(input())
nums = []
[nums.append(int(k)) for k in input().split()]
result = ''
k = 0
last = -1
i = 0
j = len(nums) - 1
while len(nums) != 0:
	if nums[i] == nums[j]:
		if nums[i] > last:
			result += 'L'
			k += 1
		break
	elif nums[i] < nums[j] and nums[i] > last:
		last = nums[i]
		k += 1
		result += 'L'
		i += 1
	elif nums[j] > last:
		last = nums[j]
		k += 1
		result += 'R'
		j -= 1
	elif nums[i] > last:
		last = nums[i]
		k += 1
		result += 'L'
		i += 1
	else:
		break
print(k)
print(result)


import math
import collections
import bisect

def cint():
	return list(map(int, input().split()))

def cstr():
	return list(map(str, input().split(' ')))

def solve():
	n = int(input())
	lst = cint()
	start = 0
	end = n - 1
	ans = ''
	slen = 0
	prev = -1
	while start <= end:
		if start == end:
			if lst[start] > prev:
				start += 1
				ans += 'L'
				slen += 1
				print(slen)
				print(ans)
				return
			else:
				start += 1
		if lst[start] == lst[end]:
			fcount = 0
			fstring = ''
			findx = start
			bcount = 0
			bindx = end
			bstring = ''
			prevval = prev
			while findx < end:
				if lst[findx] > prevval:
					prevval = lst[findx]
					fcount += 1
					fstring += 'L'
					findx += 1
				else:
					break
			prevval = prev
			while bindx > start:
				if lst[bindx] > prevval:
					prevval = lst[bindx]
					bcount += 1
					bstring += 'R'
					bindx -= 1
				else:
					break
			if fcount > bcount:
				slen += fcount
				ans += fstring
				print(slen)
				print(ans)
				return
			else:
				slen += bcount
				ans += bstring
				print(slen)
				print(ans)
				return
		if prev == -1:
			if lst[start] < lst[end]:
				prev = lst[start]
				start += 1
				ans += 'L'
			elif lst[start] > lst[end]:
				prev = lst[end]
				end -= 1
				ans += 'R'
			slen += 1
		elif lst[start] < lst[end]:
			if lst[start] > prev:
				prev = lst[start]
				start += 1
				ans += 'L'
				slen += 1
			elif lst[end] > prev:
				prev = lst[end]
				end -= 1
				ans += 'R'
				slen += 1
			else:
				print(slen)
				print(ans)
				return
		elif lst[start] > lst[end]:
			if lst[end] > prev:
				prev = lst[end]
				end -= 1
				ans += 'R'
				slen += 1
			elif lst[start] > prev:
				prev = lst[start]
				start += 1
				ans += 'L'
				slen += 1
			else:
				print(slen)
				print(ans)
				return
	print(slen)
	print(ans)
t = 1
while t != 0:
	solve()
	t -= 1


import collections
n = int(input())
seq = collections.deque(list(map(int, input().split())))
incSeq = []
moves = ''
if seq[0] > seq[-1]:
	x = seq.pop()
	incSeq.append(x)
	moves += 'R'
else:
	x = seq.popleft()
	incSeq.append(x)
	moves += 'L'
while seq and (seq[0] > incSeq[-1] or seq[-1] > incSeq[-1]):
	if len(seq) == 1:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
	elif seq[0] > seq[-1] > incSeq[-1]:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
	elif seq[0] > seq[-1] and seq[-1] <= incSeq[-1]:
		x = seq.popleft()
		incSeq.append(x)
		moves += 'L'
	elif seq[-1] > seq[0] > incSeq[-1]:
		x = seq.popleft()
		incSeq.append(x)
		moves += 'L'
	elif seq[-1] > seq[0] and seq[0] <= incSeq[-1]:
		x = seq.pop()
		incSeq.append(x)
		moves += 'R'
print(len(moves))
print(moves)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]

def solve(p, q, r):
	ans = ''
	current = r
	i = p
	j = q
	while True:
		if j < i:
			break
		if current < num[i] < num[j] or num[j] <= current < num[i]:
			ans += 'L'
			current = num[i]
			i += 1
			continue
		if current < num[j] < num[i] or num[i] <= current < num[j]:
			ans += 'R'
			current = num[j]
			j -= 1
			continue
		if current < num[i] == num[j]:
			ans1 = solve(i, j - 1, num[i])
			ans2 = solve(i + 1, j, num[i])
			if len(ans1) > len(ans2):
				ans += 'R' + ans1
			else:
				ans += 'L' + ans2
		break
	return ans
n = int(input())
num = [*map(int, input().split())]
ans = solve(0, n - 1, -1)
print(len(ans))
print(ans)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
ret = ''
last = 0
i = 0
while i < n and max(a[0], a[-1] > last):
	if a[0] > last and (a[0] < a[-1] or a[-1] <= last):
		ret += 'L'
		last = a.popleft()
	elif a[-1] > last:
		ret += 'R'
		last = a.pop()
	i += 1
print(len(ret))
print(ret)


l = int(input())
list1 = list(map(int, input().split()))
temp = 0
zuo = 0
ans = 0
anslist = []
while True:
	if zuo > l - 1 or (list1[zuo] < temp and list1[l - 1] < temp):
		break
	if temp == 0 or (list1[l - 1] > temp and list1[zuo] > temp):
		if list1[zuo] > list1[l - 1]:
			temp = list1[l - 1]
			anslist.append('R')
			ans += 1
			l -= 1
		else:
			temp = list1[zuo]
			anslist.append('L')
			ans += 1
			zuo += 1
	elif list1[l - 1] > temp and (not list1[zuo] > temp):
		temp = list1[l - 1]
		anslist.append('R')
		ans += 1
		l -= 1
	elif not list1[l - 1] > temp and list1[zuo] > temp:
		temp = list1[zuo]
		anslist.append('L')
		ans += 1
		zuo += 1
print(ans)
print(''.join(list(map(str, anslist))))


n = int(input())
a = list(map(int, input().split()))
lst = 0
res = ''
l = 0
r = n - 1
while True:
	if l > r or lst > max(a[l], a[r]):
		break
	elif a[l] > a[r] and a[r] > lst or a[r] > lst > a[l]:
		lst = a[r]
		r -= 1
		res += 'R'
	else:
		lst = a[l]
		l += 1
		res += 'L'
print(len(res))
print(res)


n = int(input())
arr = list(map(int, input().strip().split()))
ans = ''
(l, r, last, lgth) = (0, n - 1, 0, 0)
while l <= r:
	if min(arr[r], arr[l]) > last:
		if arr[l] <= arr[r]:
			ans += 'L'
			last = arr[l]
			l += 1
		else:
			ans += 'R'
			last = arr[r]
			r -= 1
	elif max(arr[r], arr[l]) > last:
		if arr[l] > arr[r]:
			ans += 'L'
			last = arr[l]
			l += 1
		else:
			ans += 'R'
			last = arr[r]
			r -= 1
	else:
		break
	lgth += 1
print(lgth, end='\n')
print(ans)


input()
a = list(map(int, input().split(' ')))
i = 0
j = len(a) - 1
seq = ''
min_num = 0
while i <= j:
	if min_num < max(a[i], a[j]):
		if a[i] < a[j]:
			if a[i] > min_num:
				seq += 'L'
				min_num = a[i]
				i += 1
			else:
				seq += 'R'
				min_num = a[j]
				j -= 1
		elif a[j] > min_num:
			seq += 'R'
			min_num = a[j]
			j -= 1
		else:
			seq += 'L'
			min_num = a[i]
			i += 1
	else:
		break
print(len(seq))
print(seq)


n = int(input())
a = [int(i) for i in input().split()]
moves = ''
last = 0
left = 0
right = n - 1
while left <= right and max(a[left], a[right]) > last:
	if a[left] > last > a[right] or a[right] > a[left] > last:
		last = a[left]
		moves += 'L'
		left += 1
	else:
		last = a[right]
		moves += 'R'
		right -= 1
print(len(moves))
print(moves)


from collections import deque
n = int(input())
l = deque(map(int, input().split()))
ans = ''
temp = [0]
flag = 0
count = 0
while True:
	if len(l) > 0:
		if l[-1] < l[0]:
			if l[-1] > temp[-1]:
				ans += 'R'
				count += 1
				temp.append(l.pop())
				flag = 1
			elif l[0] > temp[-1]:
				ans += 'L'
				count += 1
				flag = 1
				temp.append(l.popleft())
		elif l[0] > temp[-1]:
			ans += 'L'
			count += 1
			temp.append(l.popleft())
			flag = 1
		elif l[-1] > temp[-1]:
			ans += 'R'
			count += 1
			temp.append(l.pop())
			flag = 1
		if flag == 0:
			break
		else:
			flag = 0
	else:
		break
print(count)
print(ans)


def calculate(a, choice=None, l=None, r=None):
	if l is None:
		l = 0
		r = len(a) - 1
	latest = 0
	resp = ''
	while r >= l:
		if a[l] > latest:
			if a[r] <= latest:
				resp += 'L'
				latest = a[l]
				l += 1
			elif a[l] < a[r]:
				resp += 'L'
				latest = a[l]
				l += 1
			elif a[l] == a[r]:
				if choice == 'L':
					resp += 'L'
					latest = a[l]
					l += 1
					choice = None
				elif choice == 'R':
					resp += 'R'
					latest = a[r]
					r -= 1
					choice = None
				else:
					lvar = calculate(a, 'L', l, r)
					rvar = calculate(a, 'R', l, r)
					if len(lvar) > len(rvar):
						return resp + lvar
					else:
						return resp + rvar
			else:
				resp += 'R'
				latest = a[r]
				r -= 1
		elif a[r] > latest:
			resp += 'R'
			latest = a[r]
			r -= 1
		else:
			break
	return resp
n = int(input())
a = [int(i) for i in input().split()]
res = calculate(a)
print(len(res))
print(res)


_ = input()
s = list(map(int, input().split()))
l_index = 0
r_index = len(s) - 1
res = []
prev = 0
while l_index <= r_index:
	if s[l_index] > prev and s[r_index] > prev:
		if s[l_index] <= s[r_index]:
			res.append('L')
			prev = s[l_index]
			l_index += 1
		else:
			res.append('R')
			prev = s[r_index]
			r_index -= 1
	elif s[l_index] > prev:
		res.append('L')
		prev = s[l_index]
		l_index += 1
	elif s[r_index] > prev:
		res.append('R')
		prev = s[r_index]
		r_index -= 1
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
lis = list(map(int, input().split()))
i = 0
j = n - 1
s = ''
if lis[i] > lis[j]:
	j -= 1
	s = s + 'R'
	x = lis[j + 1]
elif lis[i] < lis[j]:
	i += 1
	s = s + 'L'
	x = lis[i - 1]
else:
	c = 1
	x = lis[i]
	for k in range(i + 1, j):
		if x < lis[k]:
			c += 1
			x = lis[k]
		else:
			break
	d = 1
	x = lis[i]
	for k in range(j - 1, i, -1):
		if x < lis[k]:
			d += 1
			x = lis[k]
		else:
			break
	if c > d:
		s = s + 'L' * c
	else:
		s = s + 'R' * d
	i = n
	j = 0
f = 0
while i <= j:
	if x < lis[i] and x < lis[j]:
		if lis[i] > lis[j]:
			j -= 1
			s = s + 'R'
			x = lis[j + 1]
		elif lis[i] < lis[j]:
			i += 1
			s = s + 'L'
			x = lis[i - 1]
		else:
			f = 1
			break
	elif x < lis[j]:
		j -= 1
		s = s + 'R'
		x = lis[j + 1]
	elif x < lis[i]:
		i += 1
		s = s + 'L'
		x = lis[i - 1]
	else:
		break
if f == 1:
	c = 1
	x = lis[i]
	for k in range(i + 1, j):
		if x < lis[k]:
			c += 1
			x = lis[k]
		else:
			break
	d = 1
	x = lis[i]
	for k in range(j - 1, i, -1):
		if x < lis[k]:
			d += 1
			x = lis[k]
		else:
			break
	if c > d:
		s = s + 'L' * c
	else:
		s = s + 'R' * d
print(len(s))
print(s)


from sys import setcheckinterval, setrecursionlimit, stdout
setcheckinterval(1000)
setrecursionlimit(10 ** 6)
iin = lambda : int(input())
lin = lambda : list(map(int, input().split()))
n = iin()
a = lin()
ans = []
(l, r) = (0, n - 1)
pv = 0
while l <= r:
	x = 0
	if ans:
		x = a[pv]
	if a[r] > a[l]:
		if a[l] > x:
			ans.append('L')
			pv = l
			l += 1
		elif a[r] > x:
			ans.append('R')
			pv = r
			r -= 1
		else:
			break
	elif a[r] < a[l]:
		if a[r] > x:
			ans.append('R')
			pv = r
			r -= 1
		elif a[l] > x:
			ans.append('L')
			pv = l
			l += 1
		else:
			break
	elif r - l >= 3:
		(ch1, ch2) = (0, 0)
		if a[r - 1] > a[r]:
			ch1 += 1
		if a[l + 1] > a[l]:
			ch2 += 1
		ch3 = 0
		if ch1 and ch2:
			if a[r - 1] > a[l + 1]:
				ch3 = 1
			elif a[l + 1] < a[r - 1]:
				ch3 = 2
		elif ch1:
			ch3 = 2
		elif ch2:
			ch3 = 1
		else:
			break
		if ch3 == 1:
			ans.append('L')
			pv = l
			l += 1
		else:
			ans.append('R')
			pv = r
			r -= 1
	elif a[l] > x:
		ans.append('L')
		pv = l
		l += 1
	else:
		break
print(len(ans))
print(''.join(ans))


n = int(input())
a = [int(item) for item in input().split()]
s = []
i = 0
j = n - 1
ans = []
while i <= j:
	if a[i] < a[j]:
		if not s or s[-1] < a[i]:
			s.append(a[i])
			ans.append('L')
			i += 1
		elif not s or s[-1] < a[j]:
			s.append(a[j])
			ans.append('R')
			j -= 1
		else:
			break
	elif not s or s[-1] < a[j]:
		ans.append('R')
		s.append(a[j])
		j -= 1
	elif not s or s[-1] < a[i]:
		s.append(a[i])
		ans.append('L')
		i += 1
	else:
		break
print(len(s))
print(''.join(ans))


l = 'L'
r = 'R'
n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
ln = 0
curr = -1
st = []
while i <= j:
	if a[i] < a[j]:
		if curr < a[i]:
			st.append(l)
			curr = a[i]
			i += 1
		elif curr <= a[j]:
			st.append(r)
			curr = a[j]
			j -= 1
		else:
			break
	elif curr < a[j]:
		st.append(r)
		curr = a[j]
		j -= 1
	elif curr <= a[i]:
		st.append(l)
		curr = a[i]
		i += 1
	else:
		break
print(len(st))
print(''.join(st))


n = int(input())
a = list(map(int, input().split()))
ans = 0
Ans = [0]
ANS = []
(p, q) = (0, -1)
l = 0
for i in range(n):
	if a[p] >= a[q] and Ans[-1] < a[q]:
		Ans.append(a[q])
		q -= 1
		l += 1
		ANS.append('R')
	elif a[p] <= a[q] and Ans[-1] < a[p]:
		l += 1
		Ans.append(a[p])
		p += 1
		ANS.append('L')
	elif a[p] >= a[q] and Ans[-1] < a[p]:
		Ans.append(a[p])
		p += 1
		l += 1
		ANS.append('L')
	elif a[p] <= a[q] and Ans[-1] < a[q]:
		Ans.append(a[q])
		q -= 1
		l += 1
		ANS.append('R')
	else:
		break
print(l)
print(*ANS, sep='')


n = int(input())
permstr = input().split()
perm = [int(permstr[i]) for i in range(n)]
final = 0
sides = []
currmin = 0
flag = True
L = 0
R = n - 1
while flag and L <= R and (perm[L] >= currmin or perm[R] >= currmin):
	flag = False
	if perm[L] >= currmin:
		if perm[R] < currmin or perm[R] >= perm[L]:
			currmin = perm[L]
			final += 1
			L += 1
			sides += ['L']
			flag = True
		else:
			currmin = perm[R]
			final += 1
			R -= 1
			sides += ['R']
			flag = True
	else:
		currmin = perm[R]
		final += 1
		R -= 1
		sides += ['R']
		flag = True
print(final)
print(''.join(sides))


n = int(input())
nums = list(map(int, input().split()))
prev = 0
l = 0
r = n - 1
ans = ''
while l <= r:
	if nums[l] < prev and nums[r] < prev:
		break
	if prev < nums[l] < nums[r]:
		ans += 'L'
		prev = nums[l]
		l += 1
	elif prev < nums[r] < nums[l]:
		ans += 'R'
		prev = nums[r]
		r -= 1
	elif nums[r] > nums[l]:
		ans += 'R'
		prev = nums[r]
		r -= 1
	else:
		ans += 'L'
		prev = nums[l]
		l += 1
print(len(ans))
print(ans)


n = int(input())
l = list(map(int, input().split()))
ans = []
i = 0
flag = 0
j = n - 1
s = []
while len(ans) < n and j >= 0 and (i < n):
	if i == 0 and flag == 0:
		if l[i] >= l[j]:
			ans.append(l[j])
			j -= 1
			s.append('R')
		else:
			ans.append(l[i])
			i += 1
			s.append('L')
		flag = 1
	else:
		z = ans[-1]
		k = max(l[i], l[j])
		if z < k:
			if l[i] < l[j]:
				if l[i] > z:
					ans.append(l[i])
					i += 1
					s.append('L')
				else:
					ans.append(l[j])
					s.append('R')
					j -= 1
			elif l[j] > z:
				ans.append(l[j])
				j -= 1
				s.append('R')
			else:
				ans.append(l[i])
				s.append('L')
				i += 1
		else:
			break
print(len(s))
print(''.join(s))


n = int(input())
s = [int(x) for x in input().split()]
ptr1 = 0
ptr2 = len(s) - 1
st = ''
curr = -1
while ptr1 <= ptr2:
	if s[ptr1] < s[ptr2] and s[ptr1] >= curr:
		st += 'L'
		curr = s[ptr1]
		ptr1 += 1
	elif s[ptr2] <= s[ptr1] and s[ptr2] >= curr:
		st += 'R'
		curr = s[ptr2]
		ptr2 -= 1
	elif s[ptr1] <= s[ptr2] and s[ptr2] >= curr:
		st += 'R'
		curr = s[ptr2]
		ptr2 -= 1
	elif s[ptr2] <= s[ptr1] and s[ptr1] >= curr:
		st += 'L'
		curr = s[ptr1]
		ptr1 += 1
	else:
		break
print(len(st))
print(st)


import io
import os
import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	L = 0
	R = n - 1
	last = 0
	res = []
	suffix = ''
	while L <= R:
		if a[L] < a[R]:
			if a[L] > last:
				res.append('L')
				last = a[L]
				L += 1
			elif a[R] > last:
				res.append('R')
				last = a[R]
				R -= 1
			else:
				break
		elif a[L] > a[R]:
			if a[R] > last:
				res.append('R')
				last = a[R]
				R -= 1
			elif a[L] > last:
				res.append('L')
				last = a[L]
				L += 1
			else:
				break
		else:
			posL = L
			prevL = last
			while posL < len(a) and a[posL] > prevL:
				prevL = a[posL]
				posL += 1
			lenL = posL - L
			posR = R
			prevR = last
			while a[posR] > prevR:
				prevR = a[posR]
				posR -= 1
			lenR = R - posR
			suffix = ''
			if lenL > 0 or lenR > 0:
				if lenL >= lenR:
					suffix += 'L' * lenL
				elif lenR > lenL:
					suffix += 'R' * lenR
			break
	print(len(res) + len(suffix))
	print(''.join(res) + suffix)
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	j = n - 1
	k = 0
	mi = 0
	ans = ''
	while True:
		if a[i] < a[j]:
			if mi < a[i]:
				mi = a[i]
				i += 1
				ans += 'L'
			elif mi < a[j]:
				mi = a[j]
				j -= 1
				ans += 'R'
			else:
				break
		elif mi < a[j]:
			mi = a[j]
			j -= 1
			ans += 'R'
		elif mi < a[i]:
			mi = a[i]
			i += 1
			ans += 'L'
		else:
			break
	print(len(ans))
	print(ans)
	return 0
main()


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
ans = ''
prev = 0
while i < j:
	if arr[i] < arr[j]:
		if arr[i] > prev:
			ans += 'L'
			prev = arr[i]
			i += 1
		elif arr[j] > prev:
			ans += 'R'
			prev = arr[j]
			j -= 1
		else:
			break
	elif arr[i] > arr[j]:
		if arr[j] > prev:
			ans += 'R'
			prev = arr[j]
			j -= 1
		elif arr[i] > prev:
			ans += 'L'
			prev = arr[i]
			i += 1
		else:
			break
	elif arr[i] < prev:
		break
	else:
		count1 = 0
		count2 = 0
		temp = i
		temprev = prev
		while temp < j:
			if arr[temp] > temprev:
				temprev = arr[temp]
				count1 += 1
				temp += 1
			else:
				break
		temp = j
		temprev2 = prev
		while temp > i:
			if arr[temp] > temprev2:
				temprev2 = arr[temp]
				count2 += 1
				temp -= 1
			else:
				break
		if count1 >= count2:
			ans += 'L' * count1
			i += count1
			prev = temprev
		elif count2 > count1:
			ans += 'R' * count2
			j -= count2
			prev = temprev2
		break
if i == j and arr[i] > prev:
	ans += 'R'
	prev = arr[i]
print(len(ans))
print(ans)


def binarySearch(arr, l, r, x):
	if r >= l:
		mid = l + (r - l) / 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binarySearch(arr, l, mid - 1, x)
		else:
			return binarySearch(arr, mid + 1, r, x)
	else:
		return -1
n = int(input().strip())
arr = list(map(int, input().split()))
seq = [0]
moves = []
i = 0
j = n - 1
while i != j:
	if arr[i] >= arr[j]:
		if arr[j] > seq[-1]:
			seq.append(arr[j])
			j -= 1
			moves.append('R')
		elif arr[i] > seq[-1]:
			seq.append(arr[i])
			i += 1
			moves.append('L')
		else:
			break
	elif arr[i] > seq[-1]:
		seq.append(arr[i])
		i += 1
		moves.append('L')
	elif arr[j] > seq[-1]:
		seq.append(arr[j])
		j -= 1
		moves.append('R')
	else:
		break
if i == j:
	if arr[i] > seq[-1]:
		seq.append(arr[i])
		moves.append('R')
seq2 = [0]
moves2 = []
i = 0
j = n - 1
while i != j:
	if arr[i] > arr[j]:
		if arr[j] > seq2[-1]:
			seq2.append(arr[j])
			j -= 1
			moves2.append('R')
		elif arr[i] > seq2[-1]:
			seq2.append(arr[i])
			i += 1
			moves2.append('L')
		else:
			break
	elif arr[i] > seq2[-1]:
		seq2.append(arr[i])
		i += 1
		moves2.append('L')
	elif arr[j] > seq2[-1]:
		seq2.append(arr[j])
		j -= 1
		moves2.append('R')
	else:
		break
if i == j:
	if arr[i] > seq2[-1]:
		seq2.append(arr[i])
		moves2.append('R')
if len(seq2) > len(seq):
	print(len(seq2) - 1)
	for i in moves2:
		print(i, end='')
else:
	print(len(seq) - 1)
	for i in moves:
		print(i, end='')


n = int(input())
a = list(map(int, input().split()))
o = []
ans = []
(i, j) = (0, n - 1)
if a[i] < a[j]:
	o.append(a[i])
	ans.append('L')
	i += 1
else:
	o.append(a[j])
	ans.append('R')
	j -= 1
while i <= j:
	c = -1
	if a[i] < a[j] and a[i] >= o[-1]:
		o.append(a[i])
		ans.append('L')
		i += 1
	elif a[j] <= a[i] and a[j] >= o[-1]:
		o.append(a[j])
		ans.append('R')
		j -= 1
	elif a[i] <= a[j] and a[j] >= o[-1]:
		o.append(a[j])
		ans.append('R')
		j -= 1
	elif a[j] <= a[i] and a[i] >= o[-1]:
		o.append(a[i])
		ans.append('L')
		i += 1
	else:
		break
print(len(o))
print(''.join(ans))


def run(n, a):
	i = 0
	j = n - 1
	t = -1000000000.0
	res = []
	while j - i >= 0:
		ma = max(a[i], a[j])
		mi = min(a[i], a[j])
		if t > ma:
			break
		elif t > mi and t < ma:
			if a[i] == ma:
				res.append('L')
				i += 1
			else:
				res.append('R')
				j -= 1
			t = ma
		else:
			if a[i] == mi:
				res.append('L')
				i += 1
			else:
				res.append('R')
				j -= 1
			t = mi
	return res
n = int(input())
a = list(map(int, input().split()))
res = run(n, a)
print(len(res))
for i in res:
	print(i, end='')


N = int(input())
nums = [int(i) for i in input().split()]
(left, right) = (0, N - 1)
moves = ''
last = 0
while left != right:
	(L, R) = (nums[left], nums[right])
	(left_check, right_check) = (L > last, R > last)
	if left_check and right_check:
		if L > R:
			moves += 'R'
			right -= 1
			last = R
		else:
			moves += 'L'
			left += 1
			last = L
	elif left_check:
		moves += 'L'
		left += 1
		last = L
	elif right_check:
		moves += 'R'
		right -= 1
		last = R
	else:
		break
if left == right:
	if nums[right] > last:
		moves += 'R'
print(len(moves))
print(moves)


m = int(input())
n = m - 1
a = list(map(int, input().split(' ')))
t = 0
l_s = []
i = 0
while i <= n and (a[i] > t or a[n] > t):
	if a[i] > t >= a[n] or a[n] >= a[i] > t:
		l_s.append('L')
		t = a[i]
		i += 1
	elif a[n] > t >= a[i] or a[i] >= a[n] > t:
		l_s.append('R')
		t = a[n]
		n -= 1
print(len(l_s))
print(''.join(l_s))


n = int(input())
a = [int(x) for x in input().split()]
ans = ''
left = 0
right = len(a) - 1
prev = 0
while left <= right:
	if min(a[left], a[right]) <= prev:
		break
	if a[left] < a[right]:
		ans = ans + 'L'
		prev = a[left]
		left += 1
	elif a[right] < a[left]:
		ans = ans + 'R'
		prev = a[right]
		right -= 1
	else:
		break
ans2 = ans
new_left = left
new_prev = prev
while new_left <= right and a[new_left] > new_prev:
	ans2 = ans2 + 'L'
	new_prev = a[new_left]
	new_left += 1
ans3 = ans
new_right = right
new_prev = prev
while new_right >= left and a[new_right] > new_prev:
	ans3 = ans3 + 'R'
	new_prev = a[new_right]
	new_right -= 1
ans = ans2 if len(ans2) > len(ans3) else ans3
print(len(ans))
print(ans)


from collections import deque
n = int(input())
A = list(map(int, input().split()))
A = deque(A)
ans = ''
last = 0
while len(A) and (A[0] > last or A[-1] > last):
	if A[0] > last and A[-1] > last:
		if A[0] < A[-1]:
			last = A[0]
			A.popleft()
			ans += 'L'
		else:
			last = A[-1]
			A.pop()
			ans += 'R'
	elif A[0] > last:
		last = A[0]
		A.popleft()
		ans += 'L'
	else:
		last = A[-1]
		A.pop()
		ans += 'R'
print(len(ans))
print(ans)


from collections import deque
n = int(input())
a = list(map(int, input().split()))
a = deque(a)
p = 0
b = []
for i in range(n):
	if a[0] >= a[-1] and a[-1] > p:
		p = a.pop()
		b.append('R')
	elif a[0] >= a[-1] and a[0] > p:
		p = a.popleft()
		b.append('L')
	elif a[-1] >= a[0] and a[0] > p:
		p = a.popleft()
		b.append('L')
	elif a[-1] >= a[0] and a[-1] > p:
		p = a.pop()
		b.append('R')
	else:
		break
print(len(b))
print(''.join(b))


n = int(input())
arr = list(map(int, input().split()))
lb = 0
rb = n - 1
last = -1
ans = []

def prev(i):
	if i > 0:
		return arr[i - 1]
	else:
		return arr[0] - 1

def next(i):
	if i < n - 1:
		return arr[i + 1]
	else:
		return arr[n - 1] - 1
while lb <= rb:
	if arr[lb] < arr[rb]:
		last = arr[lb]
		ans.append('L')
		lb += 1
		if prev(lb) >= arr[lb]:
			while lb < rb and arr[rb] > next(rb):
				last = arr[rb]
				ans.append('R')
				rb -= 1
			break
	elif arr[rb] < arr[lb]:
		last = arr[rb]
		ans.append('R')
		rb -= 1
		if next(rb) >= arr[rb]:
			while lb < rb and arr[lb] > prev(lb):
				last = arr[lb]
				ans.append('L')
				lb += 1
			break
	else:
		break
if arr[lb] > last:
	if lb == rb:
		ans.append('R')
	if arr[lb] == arr[rb] and rb > lb:
		szleft = 0
		while arr[lb + szleft] < arr[lb + szleft + 1]:
			szleft += 1
		szright = 0
		while arr[rb - szright] < arr[rb - szright - 1]:
			szright += 1
		if szleft > szright:
			ans.extend(['L'] * (szleft + 1))
		else:
			ans.extend(['R'] * (szright + 1))
print(len(ans))
print(''.join(ans))


n = int(input())
li = list(map(int, input().split()))
i = 0
j = n - 1
c = 0
ans = []
w = []
while i <= j:
	x = li[i]
	y = li[j]
	if len(ans) == 0:
		if x > y:
			ans.append(y)
			w.append('R')
			j -= 1
		else:
			ans.append(x)
			w.append('L')
			i += 1
	elif x > y:
		if ans[-1] < y:
			j -= 1
			ans.append(y)
			w.append('R')
		elif ans[-1] < x:
			i += 1
			ans.append(x)
			w.append('L')
		else:
			break
	elif ans[-1] < x:
		i += 1
		ans.append(x)
		w.append('L')
	elif ans[-1] < y:
		j -= 1
		ans.append(y)
		w.append('R')
	else:
		break
print(len(ans))
print(''.join([ele for ele in w]))


n = int(input())
a = [int(x) for x in input().split()]
(l, r) = (0, n - 1)
cur = []
ans = ''
while 1:
	if cur == []:
		if a[l] < a[r]:
			cur.append(a[l])
			l += 1
			ans += 'L'
		else:
			cur.append(a[r])
			r -= 1
			ans += 'R'
	if l > r or (a[l] < cur[-1] and a[r] < cur[-1]):
		break
	elif a[l] > cur[-1] and a[r] > cur[-1]:
		if a[l] < a[r]:
			cur.append(a[l])
			l += 1
			ans += 'L'
		else:
			cur.append(a[r])
			r -= 1
			ans += 'R'
	elif a[l] > cur[-1]:
		cur.append(a[l])
		l += 1
		ans += 'L'
	elif a[r] > cur[-1]:
		cur.append(a[r])
		r -= 1
		ans += 'R'
	if l > r or (a[l] < cur[-1] and a[r] < cur[-1]):
		break
print(len(ans))
print(ans)


from collections import deque
n = int(input())
nums = deque(map(int, input().split()))
mx_len = 0
decision = deque()
(i, j) = (0, len(nums) - 1)
last = 0
if nums[0] > nums[-1]:
	decision.append('R')
	last = nums[-1]
	j -= 1
else:
	decision.append('L')
	last = nums[0]
	i += 1
mx_len += 1
while i <= j:
	(min_ind, mn, max_ind, mx) = (0, 0, 0, 0)
	if nums[i] < nums[j]:
		(min_ind, mn) = (i, nums[i])
		(max_ind, mx) = (j, nums[j])
	else:
		(min_ind, mn) = (j, nums[j])
		(max_ind, mx) = (i, nums[i])
	if mn > last:
		if min_ind == i:
			decision.append('L')
			mx_len += 1
			last = nums[i]
			i += 1
		else:
			decision.append('R')
			mx_len += 1
			last = nums[j]
			j -= 1
	elif mx > last:
		if max_ind == i:
			decision.append('L')
			mx_len += 1
			last = nums[i]
			i += 1
		else:
			decision.append('R')
			mx_len += 1
			last = nums[j]
			j -= 1
	else:
		break
print(mx_len)
print(''.join(decision))


n = int(input())
a = [int(item) for item in input().split()]
s = []
i = 0
j = n - 1
ans = []
while i <= j:
	if a[i] < a[j]:
		if not s or s[-1] < a[i]:
			s.append(a[i])
			ans.append('L')
			i += 1
		elif not s or s[-1] < a[j]:
			s.append(a[j])
			ans.append('R')
			j -= 1
		else:
			break
	elif a[i] > a[j]:
		if not s or s[-1] < a[j]:
			ans.append('R')
			s.append(a[j])
			j -= 1
		elif not s or s[-1] < a[i]:
			s.append(a[i])
			ans.append('L')
			i += 1
		else:
			break
	else:
		p1 = 0
		p2 = 0
		cur_last = s[-1] if s else None
		or_i = i
		while i <= j and (cur_last is None or a[i] > cur_last):
			cur_last = a[i]
			i += 1
			p1 += 1
		cur_last = s[-1] if s else None
		while or_i <= j and (cur_last is None or a[j] > cur_last):
			cur_last = a[j]
			j -= 1
			p2 += 1
		if p1 > p2:
			ans += list('L' * p1)
		else:
			ans += list('R' * p2)
		break
print(len(ans))
print(''.join((str(x) for x in ans)))


n = int(input())
a = list(map(int, input().split()))
maxElem = 0
L = 0
R = len(a) - 1
ans = []
last = -1
while L <= R:
	if last == -1:
		if a[L] < a[R]:
			last = a[L]
			L += 1
			ans.append('L')
		else:
			last = a[R]
			R -= 1
			ans.append('R')
	elif (a[L] < a[R] or a[R] < last) and a[L] > last:
		last = a[L]
		L += 1
		ans.append('L')
	elif a[R] > last:
		last = a[R]
		R -= 1
		ans.append('R')
	else:
		break
print(len(ans))
print(''.join(ans))


t = int(input())
n = list(map(int, input().strip().split()))
st = ''
prev = -1
lc = 0
rc = t - 1
pst = len(st)
while 1:
	if lc > rc:
		break
	if prev <= n[lc] or prev <= n[rc]:
		val1 = min(n[lc], n[rc])
		val2 = max(n[lc], n[rc])
		if prev <= val1:
			if val1 == n[lc]:
				st += 'L'
				prev = n[lc]
				lc += 1
			else:
				st += 'R'
				prev = n[rc]
				rc -= 1
		elif prev <= val2:
			if val2 == n[lc]:
				st += 'L'
				prev = n[lc]
				lc += 1
			else:
				st += 'R'
				prev = n[rc]
				rc -= 1
	if pst != len(st):
		pst = len(st)
	else:
		break
print(len(st))
print(st)


from copy import copy as cp
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(1)
	print('L')
else:
	(L, R) = (0, n - 1)
	ele = -1
	st = ''
	flag = None
	while L <= R:
		if arr[L] < arr[R] and arr[L] > ele:
			ele = arr[L]
			L += 1
			st += 'L'
		elif arr[R] < arr[L] and arr[R] > ele:
			ele = arr[R]
			R -= 1
			st += 'R'
		elif arr[R] == arr[L] and arr[R] > ele:
			flag = 'eq'
			break
		else:
			m = max(arr[L], arr[R])
			if m > ele:
				ele = m
				if m == arr[L]:
					L += 1
					st += 'L'
				else:
					R -= 1
					st += 'R'
			else:
				break
	if flag == 'eq':
		(left, right) = (st, st)
		old_ele = ele
		for i in range(R, L - 1, -1):
			if arr[i] > ele:
				right += 'R'
				ele = arr[i]
			else:
				break
		for i in range(L, R + 1):
			if arr[i] > old_ele:
				left += 'L'
				old_ele = arr[i]
			else:
				break
		if len(left) > len(st):
			st = left
		if len(right) > len(st):
			st = right
	print(len(st))
	print(st)


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
ret = ''
last = 0
i = 0
while i < n and max(a[0], a[-1] > last):
	if a[0] == a[-1] and a[0] > last:
		prevFromLeft = prevFromRight = a[0]
		size = len(a)
		fromLeft = 'L'
		for i in range(1, size):
			if a[i] > prevFromLeft:
				fromLeft += 'L'
				prevFromLeft = a[i]
			else:
				break
		fromRight = 'R'
		for i in range(size - 2, -1, -1):
			if a[i] > prevFromRight:
				fromRight += 'R'
				prevFromRight = a[i]
			else:
				break
		ret += fromRight if len(fromRight) >= len(fromLeft) else fromLeft
		break
	if a[0] > last and (a[0] < a[-1] or a[-1] <= last):
		ret += 'L'
		last = a.popleft()
	elif a[-1] > last:
		ret += 'R'
		last = a.pop()
	i += 1
print(len(ret))
print(ret)


n = int(input())
tab = [int(x) for x in input().split()]
sequence = ''
current = 0
l = 0
r = n - 1
res_len = 0
while l <= r:
	if tab[l] > current and tab[r] > current:
		if tab[l] < tab[r]:
			current = tab[l]
			sequence += 'L'
			l += 1
			res_len += 1
		else:
			current = tab[r]
			sequence += 'R'
			r -= 1
			res_len += 1
	elif tab[l] > current:
		current = tab[l]
		sequence += 'L'
		l += 1
		res_len += 1
	elif tab[r] > current:
		current = tab[r]
		sequence += 'R'
		r -= 1
		res_len += 1
	else:
		break
print(res_len)
print(sequence)


n = int(input())
nums = list(map(int, input().split()))

def foo(l, r, prev=0):
	ans = ''
	while l <= r:
		if nums[l] <= prev and nums[r] <= prev:
			break
		if prev < nums[l] < nums[r]:
			ans += 'L'
			prev = nums[l]
			l += 1
		elif prev < nums[r] < nums[l]:
			ans += 'R'
			prev = nums[r]
			r -= 1
		elif nums[r] > nums[l]:
			ans += 'R'
			prev = nums[r]
			r -= 1
		elif nums[r] < nums[l]:
			ans += 'L'
			prev = nums[l]
			l += 1
		elif l == r:
			ans += 'R'
			break
		else:
			a1 = 'L' + foo(l + 1, r, nums[l])
			a2 = 'R' + foo(l, r - 1, nums[l])
			ans += a1 if len(a1) > len(a2) else a2
			break
	return ans
ans = foo(0, n - 1)
print(len(ans))
print(ans)


import sys
from bisect import bisect_left, bisect_right
from collections import deque
inf = float('inf')
mod = 1000000007

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())
n = int(input())
origin = get_array()
array = [(e, idx) for (idx, e) in enumerate(origin)]

def get_first(e):
	return e[0]
array.sort(key=get_first)
(l, r) = (0, n - 1)
cnt = 0
output = ''
for each in array:
	(v, idx) = (each[0], each[1])
	if idx == r:
		cnt += 1
		output += 'R'
		r -= 1
	elif idx == l:
		cnt += 1
		output += 'L'
		l += 1
print(cnt)
print(output)


import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
l = list(map(int, input().split()))
f = 0
e = n - 1
cur = 0
s = []
ans = ''
ex = 0
curr = 0
w = ''
while e >= f:
	if l[e] > cur and e == f:
		s.append(l[f])
		f += 1
		ans += 'L'
		break
	elif l[e] > cur and l[f] > cur:
		if l[e] < l[f]:
			s.append(l[e])
			e -= 1
			ans += 'R'
		elif l[f] < l[e]:
			s.append(l[f])
			f += 1
			ans += 'L'
		else:
			prev = cur
			for i in range(f, e + 1):
				if l[i] > prev:
					curr += 1
					prev = l[i]
				else:
					break
			ex = max(curr, ex)
			curr = 0
			prev = cur
			for i in range(e, f - 1, -1):
				if l[i] > prev:
					curr += 1
					prev = l[i]
				else:
					break
			ex = max(curr, ex)
			if curr == ex:
				w = 'R'
			else:
				w = 'L'
			break
	elif l[e] > cur:
		s.append(l[e])
		e -= 1
		ans += 'R'
	elif l[f] > cur:
		s.append(l[f])
		f += 1
		ans += 'L'
	else:
		break
	cur = s[-1]
print(len(s) + ex)
print(ans + ex * w)


N = int(input())
a_list = list(map(int, input().split()))
from collections import deque
deq = deque(a_list)
ans = ''
left = 0
right = 0
min_num = -1
cnt = 0
f = False
while len(deq) >= 2:
	left = deq.popleft()
	right = deq.pop()
	max_num = max(left, right)
	if max_num > min_num:
		cnt += 1
		if right > left > min_num:
			ans += 'L'
			deq.append(right)
			min_num = left
		elif left > right > min_num:
			ans += 'R'
			deq.appendleft(left)
			min_num = right
		elif left > min_num:
			ans += 'L'
			deq.append(right)
			min_num = left
		else:
			ans += 'R'
			deq.appendleft(left)
			min_num = right
	else:
		f = True
		break
if f:
	print(cnt)
	print(ans)
else:
	tmp = deq.pop()
	if tmp > min_num:
		cnt += 1
		print(cnt)
		print(ans + 'R')
	else:
		print(cnt)
		print(ans)


n = int(input())
m = list(map(int, input().split()))
ans = []
(l, r) = (0, n - 1)
x = 0
while l <= r:
	(a, b) = (m[l], m[r])
	fl = False
	if a > b:
		(a, b) = (b, a)
		fl = True
	if a > x:
		x = a
		if not fl:
			ans.append('L')
			l += 1
		else:
			ans.append('R')
			r -= 1
	elif b > x:
		x = b
		if not fl:
			ans.append('R')
			r -= 1
		else:
			ans.append('L')
			l += 1
	else:
		break
print(len(ans))
print(''.join(ans))


def search(l, r, pr):
	posl = ''
	fl = True
	while l <= r:
		if sp[l] < sp[r]:
			if sp[l] > pr:
				pr = sp[l]
				l += 1
				posl += 'L'
			elif sp[r] > pr:
				pr = sp[r]
				r -= 1
				posl += 'R'
			else:
				fl = False
		elif sp[l] > sp[r]:
			if sp[r] > pr:
				pr = sp[r]
				r -= 1
				posl += 'R'
			elif sp[l] > pr:
				pr = sp[l]
				l += 1
				posl += 'L'
			else:
				fl = False
		else:
			if sp[l] > pr:
				fst = search(l + 1, r, sp[l]) + 'L'
				sec = search(l, r - 1, sp[r]) + 'R'
				if len(sec) > len(fst):
					posl += sec
				else:
					posl += fst
			fl = False
		if not fl:
			break
	return posl
n = int(input())
sp = list(map(int, input().split()))
pr = 0
posl = ''
l = 0
r = n - 1
new = search(l, r, 0)
print(len(new))
print(new)


n = int(input())
a = list(map(int, input().split()))
start = -1
end = len(a)
last_n = 0
length = 0
seq = ''
while start < end - 1:
	first = a[start + 1]
	last = a[end - 1]
	if first <= last:
		if first > last_n:
			start += 1
			last_n = first
			length += 1
			seq += 'L'
		elif last > last_n:
			end -= 1
			last_n = last
			length += 1
			seq += 'R'
		else:
			break
	elif last > last_n:
		end -= 1
		last_n = last
		length += 1
		seq += 'R'
	elif first > last_n:
		start += 1
		last_n = first
		length += 1
		seq += 'L'
	else:
		break
print(length)
print(seq)


n = int(input())
arr = list(map(int, input().split()))
head = 0
tail = len(arr) - 1
seq = []
h = arr[head]
t = arr[tail]
mini = min(h, t)
if mini == h:
	ans = ''.join('L')
	head += 1
else:
	ans = ''.join('R')
	tail -= 1
seq.append(mini)
seqt = seq[len(seq) - 1]
while head < tail:
	h = arr[head]
	t = arr[tail]
	seqt = seq[len(seq) - 1]
	if h > seqt:
		if t > seqt:
			mini = min(h, t)
			if mini == h:
				ans = ans + 'L'
				head += 1
			else:
				ans = ans + 'R'
				tail -= 1
		else:
			mini = h
			ans = ans + 'L'
			head += 1
	elif t > seqt:
		mini = t
		ans = ans + 'R'
		tail -= 1
	else:
		break
	seq.append(mini)
if head == tail:
	if arr[head] > len(seq) - 1:
		seq.append(arr[head])
		ans += 'L'
print(str(len(seq)))
print(ans)


from collections import deque
import random
n = int(input())
A_l = list(map(int, input().rstrip().split()))
A = deque()
moves = []
last = None
for a in A_l:
	A.append(a)
while len(A) > 0:
	l = A.popleft()
	r_exists = True
	if len(A) != 0:
		r = A.pop()
	else:
		r_exists = False
	if last:
		if l > last and (not r_exists or (r_exists and (l <= r or r < last))):
			moves.append('L')
			last = l
			if r_exists:
				A.append(r)
		elif r_exists and r > last and (r <= l or l < last):
			if r_exists:
				moves.append('R')
				last = r
			A.appendleft(l)
		else:
			break
	elif not r_exists or (r_exists and l <= r):
		moves.append('L')
		last = l
		if r_exists:
			A.append(r)
	elif r_exists and r <= l:
		moves.append('R')
		last = r
		A.appendleft(l)
	else:
		break
print(len(moves))
print(''.join(moves))


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n
primes = []

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return int(input())
n = f()
cl = f(2)
(l, r) = (0, n - 1)
res = ''
last = 0
for i in range(n):
	a = cl[l]
	b = cl[r]
	if a > b:
		mx = a
		mn = b
	else:
		mx = b
		mn = a
	if mn > last:
		if a == mn:
			last = a
			res += 'L'
			l += 1
		else:
			last = b
			res += 'R'
			r -= 1
	elif mx > last:
		if a == mx:
			last = a
			res += 'L'
			l += 1
		else:
			last = b
			res += 'R'
			r -= 1
	else:
		break
print(len(res))
print(res)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
pre = 0
inc = True
res = []
while l <= r:
	if max(a[l], a[r]) <= pre:
		break
	if a[r] < a[l] and a[r] > pre or (a[r] > a[l] and a[l] <= pre):
		pre = a[r]
		r -= 1
		res.append('R')
	else:
		pre = a[l]
		l += 1
		res.append('L')
print(len(res))
for i in res:
	print(i, end='')


from collections import deque
n = int(input())
A = list(map(int, input().split()))
A = deque(A)
ans = ''
last = 0
while len(A) and (A[0] > last or A[-1] > last):
	if len(A) == 1:
		ans += 'R'
		break
	if A[0] > last and A[-1] > last:
		if A[0] < A[-1]:
			last = A[0]
			A.popleft()
			ans += 'L'
		elif A[-1] < A[0]:
			last = A[-1]
			A.pop()
			ans += 'R'
		else:
			lal = last
			cnt1 = -1
			for i in A:
				cnt1 += 1
				if i > lal:
					lal = i
				else:
					break
			lol = last
			cnt2 = -1
			for i in range(len(A) - 1, -1, -1):
				cnt2 += 1
				if A[i] > lol:
					lol = A[i]
				else:
					break
			if cnt1 > cnt2:
				ans += 'L' * cnt1
			else:
				ans += 'R' * cnt2
			break
	elif A[0] > last:
		last = A[0]
		A.popleft()
		ans += 'L'
	else:
		last = A[-1]
		A.pop()
		ans += 'R'
print(len(ans))
print(ans)


from collections import deque
n = int(input())
m = deque(map(int, input().split()))
s = ''
tmp = -1
while len(m) > 1 and max(m[0], m[-1]) > tmp:
	if m[0] > tmp:
		if m[0] < m[-1] or m[-1] < tmp:
			tmp = m[0]
			m.popleft()
			s += 'L'
		else:
			tmp = m[-1]
			m.pop()
			s += 'R'
	else:
		tmp = m[-1]
		m.pop()
		s += 'R'
if m[0] > tmp:
	s += 'R'
print(len(s))
print(s)


n = int(input())
ans = []
a = list(map(int, input().split()))
l = -0
r = n - 1
now = 0
while l <= r:
	if a[l] < a[r] and a[l] > now:
		now = a[l]
		l += 1
		ans.append('L')
	elif a[r] < a[l] and a[r] > now:
		now = a[r]
		r -= 1
		ans.append('R')
	elif a[r] < a[l] and a[l] > now:
		now = a[l]
		l += 1
		ans.append('L')
	elif a[l] < a[r] and a[r] > now:
		now = a[r]
		r -= 1
		ans.append('R')
	elif a[l] == a[r]:
		if a[l] <= now:
			break
		nowl = now
		nowr = now
		pos = l
		cnt1 = 0
		cnt2 = 0
		while pos <= r and a[pos] > nowl:
			nowl = a[pos]
			pos += 1
			cnt1 += 1
		pos = r
		while l <= pos and a[pos] > nowr:
			nowr = a[pos]
			pos -= 1
			cnt2 += 1
		if cnt1 > cnt2:
			for i in range(0, cnt1):
				ans.append('L')
		else:
			for i in range(0, cnt2):
				ans.append('R')
		break
	else:
		break
print(len(ans))
for i in ans:
	print(i, end='')


def left_right(l, r, a):
	if a == l:
		return 'L'
	else:
		return 'R'

def process(A, n, l, r):
	B = []
	C = []
	B.append(min(A[l], A[r], min(A[l], A[r])))
	C.append(left_right(A[l], A[r], min(A[l], A[r])))
	if C[-1] == 'L':
		l = l + 1
	else:
		r = r - 1
	while l <= r:
		a = max(A[l], A[r])
		b = min(A[l], A[r])
		if b >= B[-1]:
			B.append(b)
			k = left_right(A[l], A[r], b)
			C.append(k)
			if k == 'L':
				l = l + 1
			else:
				r = r - 1
		elif a >= B[-1]:
			B.append(a)
			k = left_right(A[l], A[r], a)
			C.append(k)
			if k == 'L':
				l = l + 1
			else:
				r = r - 1
		else:
			break
	print(len(B))
	for i in C:
		print(i, end='')
n = int(input())
A = []
for x in input().split():
	A.append(int(x))
process(A, n, 0, n - 1)


n = int(input())
A = list(map(int, input().split()))
(l, r) = (0, n - 1)
if A[l] < A[r]:
	tmp = A[l]
	l += 1
	ans = 'L'
else:
	tmp = A[r]
	r -= 1
	ans = 'R'
cnt = 1
while l <= r:
	(left, right) = (A[l], A[r])
	if max(left, right) < tmp:
		break
	cnt += 1
	if left < right:
		if tmp > left:
			tmp = right
			r -= 1
			ans += 'R'
		else:
			tmp = left
			l += 1
			ans += 'L'
	elif tmp > right:
		tmp = left
		l += 1
		ans += 'L'
	else:
		tmp = right
		r -= 1
		ans += 'R'
print(cnt)
print(ans)


n = int(input())
s = list(map(int, input().split()))
lod = [0]
loc = []
l = 0
r = len(s) - 1
while l <= r and s[l] > lod[-1] and (s[r] > lod[-1]):
	if s[l] > s[r]:
		loc += [-1]
		lod += [s[r]]
		r -= 1
	else:
		loc += [0]
		lod += [s[l]]
		l += 1
while l <= r and s[l] > lod[-1]:
	loc += [0]
	lod += [s[l]]
	l += 1
while l <= r and s[r] > lod[-1]:
	loc += [-1]
	lod += [s[r]]
	r -= 1
print(len(loc))
print(*['L' if t == 0 else 'R' for t in loc], sep='')


n = input()
a = input()
a_list = [int(i) for i in a.split(' ')]
l = 0
r = -1
last = 0
s = ''
while l - r <= int(n):
	if last < a_list[l] == a_list[r]:
		ls = s + 'L'
		rs = s + 'R'
		for i in range(int(n) - l + r):
			if a_list[l + i] < a_list[l + i + 1]:
				ls = ls + 'L'
			else:
				break
		for i in range(int(n) - l + r):
			if a_list[r - i] < a_list[r - i - 1]:
				rs = rs + 'R'
			else:
				break
		if len(ls) > len(rs):
			s = ls
			break
		else:
			s = rs
			break
	if last < a_list[l] < a_list[r] or a_list[r] <= last < a_list[l]:
		s = s + 'L'
		last = a_list[l]
		l = l + 1
	elif last < a_list[r] < a_list[l] or a_list[l] <= last < a_list[r]:
		s = s + 'R'
		last = a_list[r]
		r = r - 1
	else:
		break
print(len(s))
print(s)


n = int(input())
a = list(map(int, input().split()))
k = 0
ops = []
last = 0
left = 0
right = n - 1
while left <= right:
	if a[left] <= last and a[right] <= last:
		break
	if a[right] <= last or (a[left] <= a[right] and a[left] > last):
		ops.append('L')
		last = a[left]
		left += 1
		k += 1
	elif a[right] > last:
		ops.append('R')
		last = a[right]
		right -= 1
		k += 1
print(k)
print(''.join(ops))


N = int(input())
a_list = list(map(int, input().split()))
from collections import deque
import bisect
deq = deque(a_list)
ans = ''
left = 0
right = 0
min_num = -1
cnt = 0
f = False
lr = False
while len(deq) >= 2:
	left = deq.popleft()
	right = deq.pop()
	max_num = max(left, right)
	if max_num > min_num:
		if left == right:
			deq.appendleft(left)
			deq.append(right)
			lr = True
			break
		cnt += 1
		if right > left > min_num:
			ans += 'L'
			deq.append(right)
			min_num = left
		elif left > right > min_num:
			ans += 'R'
			deq.appendleft(left)
			min_num = right
		elif left > min_num:
			ans += 'L'
			deq.append(right)
			min_num = left
		else:
			ans += 'R'
			deq.appendleft(left)
			min_num = right
	else:
		f = True
		break
if lr:
	l = 0
	r = 0
	tmp = deq.copy()
	prv = -1
	for t in tmp:
		if t > prv:
			l += 1
		else:
			break
		prv = t
	tmp = list(reversed(tmp))
	prv = -1
	for t in tmp:
		if t > prv:
			r += 1
		else:
			break
		prv = t
	if l > r:
		print(cnt + l)
		print(ans + 'L' * l)
	else:
		print(cnt + r)
		print(ans + 'R' * r)
	exit()
if f:
	print(cnt)
	print(ans)
else:
	tmp = deq.pop()
	if tmp > min_num:
		cnt += 1
		print(cnt)
		print(ans + 'R')
	else:
		print(cnt)
		print(ans)


from collections import deque
input()
val = deque(map(int, input().split()))
res = []
now = 0
while len(val):
	(l, r) = (val[0], val[-1])
	if now < l and (not now < r < l):
		res.append('L')
		now = val.popleft()
	elif now < r and (not now < l < r):
		res.append('R')
		now = val.pop()
	else:
		break
print(len(res))
print(''.join(res))


n = int(input())
ar = list(map(int, input().split()))
if n == 1:
	print(1)
	print('L')
else:
	l = 0
	x = 0
	y = n - 1
	ans = []
	while x <= y:
		if x == y and ar[x] > l:
			x += 1
			y -= 1
			ans.append('L')
		elif ar[x] > l and ar[y] > l:
			if ar[x] < ar[y]:
				ans.append('L')
				l = ar[x]
				x += 1
			else:
				ans.append('R')
				l = ar[y]
				y -= 1
		elif ar[x] > l:
			ans.append('L')
			l = ar[x]
			x += 1
		elif ar[y] > l:
			ans.append('R')
			l = ar[y]
			y -= 1
		else:
			break
	print(len(ans))
	print(''.join(ans))


def solve(p, q, r):
	ans = ''
	current = r
	i = p
	j = q
	while True:
		if j < i:
			break
		if current < num[i] < num[j] or num[j] <= current < num[i]:
			ans += 'L'
			current = num[i]
			i += 1
			continue
		if current < num[j] < num[i] or num[i] <= current < num[j]:
			ans += 'R'
			current = num[j]
			j -= 1
			continue
		if current < num[i] == num[j]:
			ans1 = solve(i, j - 1, num[i])
			ans2 = solve(i + 1, j, num[i])
			if len(ans1) > len(ans2):
				ans += 'R' + ans1
			else:
				ans += 'L' + ans2
		break
	return ans
n = int(input())
num = [*map(int, input().split())]
ans = solve(0, n - 1, -1)
print(len(ans))
print(ans)


n = int(input())
lis = list(map(int, input().split()))
l = 0
r = len(lis) - 1
s = ''
li = [0] * 1
while l <= r:
	if (lis[l] < lis[r] or lis[r] <= li[-1]) and lis[l] > li[-1]:
		s += 'L'
		li.append(lis[l])
		l += 1
	elif lis[l] == lis[r] and l != r:
		q = t = ''
		l1 = l
		r1 = r
		lii = []
		lii.append(li[-1])
		while l1 < r1:
			if lis[l1] > lii[-1]:
				q += 'L'
				lii.append(lis[l1])
				l1 += 1
			else:
				break
		l1 = l
		r1 = r
		lii2 = []
		lii2.append(li[-1])
		while l1 < r1:
			if lis[r1] > lii2[-1]:
				t += 'R'
				lii2.append(lis[r1])
				r1 -= 1
			else:
				break
		if len(q) > len(t):
			s += q
		else:
			s += t
		break
	elif lis[r] > li[-1]:
		s += 'R'
		li.append(lis[r])
		r -= 1
	else:
		break
print(len(s))
print(s)


n = int(input())
lista = list(map(int, input().split()))
last = -1
l = 0
r = n - 1
out = []
total = 0
while last < lista[l] or last < lista[r]:
	if last < lista[l] and last < lista[r]:
		if lista[l] < lista[r]:
			last = lista[l]
			out.append('L')
			l += 1
			total += 1
			n -= 1
		elif lista[l] > lista[r]:
			last = lista[r]
			out.append('R')
			r -= 1
			total += 1
			n -= 1
		else:
			out.append('L')
			total += 1
			break
	elif last < lista[l] and last >= lista[r]:
		last = lista[l]
		out.append('L')
		l += 1
		total += 1
		n -= 1
	elif last >= lista[l] and last < lista[r]:
		last = lista[r]
		out.append('R')
		r -= 1
		total += 1
		n -= 1
	else:
		break
print(total)
print(*out, sep='')


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
last = 0
ans = ''
while i <= j:
	fL = a[i] > last and a[j] > last and (a[i] <= a[j]) or a[i] > last > a[j]
	fR = a[i] > last and a[j] > last and (a[j] <= a[i]) or a[j] > last > a[i]
	if fL:
		ans += 'L'
		last = a[i]
		i += 1
	elif fR:
		ans += 'R'
		last = a[j]
		j -= 1
	else:
		break
print(len(ans))
print(ans)


n = int(input())
c = [int(x) for x in input().split(' ')]
s = ''
p = 0
i = 0
j = n - 1
while i <= j:
	if c[i] > p and c[j] > p:
		if c[i] > c[j]:
			p = c[j]
			s += 'R'
			j -= 1
		else:
			p = c[i]
			s += 'L'
			i += 1
	elif c[i] > p and c[j] < p:
		p = c[i]
		s += 'L'
		i += 1
	elif c[i] < p and c[j] > p:
		p = c[j]
		s += 'R'
		j -= 1
	else:
		break
print(len(s))
print(s)


n = int(input())
num = [*map(int, input().split())]
ans = ''
current = -1
i = 0
j = n - 1
while True:
	if j < i:
		break
	if current < num[i] <= num[j] or num[j] <= current < num[i]:
		ans += 'L'
		current = num[i]
		i += 1
		continue
	if current < num[j] <= num[i] or num[i] <= current < num[j]:
		ans += 'R'
		current = num[j]
		j -= 1
		continue
	break
print(len(ans))
print(ans)


n = int(input())
l = list(map(int, input().split()))
uk1 = 0
uk2 = n - 1
ans = []
ban1 = 0
ban2 = 0
while uk2 - uk1 >= 1:
	if l[uk2] > l[uk1]:
		if len(ans) == 0:
			ans.append([l[uk1], 'L'])
			uk1 += 1
		elif l[uk1] <= ans[-1][0]:
			ban1 = 1
			break
		else:
			ans.append([l[uk1], 'L'])
			uk1 += 1
	elif l[uk2] < l[uk1]:
		if len(ans) == 0:
			ans.append([l[uk2], 'R'])
			uk2 -= 1
		elif l[uk2] <= ans[-1][0]:
			ban2 = 1
			break
		else:
			ans.append([l[uk2], 'R'])
			uk2 -= 1
	elif l[uk2] == l[uk1]:
		break
cnt1 = 0
cnt2 = 0
if uk2 - uk1 == 0:
	if len(ans) == 0 or l[uk1] > ans[-1][0]:
		ans.append([l[uk1], 'L'])
if not ban1 and (len(ans) == 0 or l[uk1] > ans[-1][0]):
	cnt1 = 1
	for i in range(uk1 + 1, uk2):
		if l[i] > l[i - 1]:
			cnt1 += 1
		else:
			break
if not ban2 and (len(ans) == 0 or l[uk2] > ans[-1][0]):
	cnt2 = 1
	for i in range(uk2 - 1, uk1, -1):
		if l[i] > l[i + 1]:
			cnt2 += 1
		else:
			break
if cnt1 >= cnt2:
	for i in range(uk1, uk1 + cnt1):
		ans.append([l[i], 'L'])
else:
	for i in range(uk2, uk2 - cnt2, -1):
		ans.append([l[i], 'R'])
print(len(ans))
for i in range(len(ans)):
	print(ans[i][1], end='')


import math
import collections
read = lambda : map(int, input().split())
n = int(input())
a = collections.deque(read())
ans = ''
pre = 0
while len(a) > 0 and max(a[0], a[-1]) > pre:
	if a[0] > pre and (a[0] < a[-1] or a[-1] < pre):
		ans += 'L'
		pre = a.popleft()
	elif a[-1] > pre and (a[0] > a[-1] or a[0] < pre):
		ans += 'R'
		pre = a.pop()
	elif a[0] == a[-1] and a[0] > pre:
		ans += 'L'
		break
	else:
		break
print(len(ans))
print(ans)


import sys
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
a = intInp()
ans = ''
last = -1
li = 0
ri = n - 1
left = 'L'
right = 'R'
while last < max(a[li], a[ri]) and li <= ri:
	if last < a[li] and last < a[ri]:
		if a[li] < a[ri]:
			ans += left
			last = a[li]
			li += 1
		else:
			ans += right
			last = a[ri]
			ri -= 1
	elif last < a[li]:
		ans += left
		last = a[li]
		li += 1
	else:
		ans += right
		last = a[ri]
		ri -= 1
print(len(ans))
print(ans)


n = int(input())
i = 0
j = n - 1
ch = input()
L = [int(i) for i in ch.split()]
s = ''
x = 0
while i <= j:
	if max(L[i], L[j]) < x:
		break
	elif L[i] < L[j] and L[i] > x:
		x = L[i]
		i += 1
		s += 'L'
	elif L[i] < L[j] and L[i] < x:
		x = L[j]
		j -= 1
		s += 'R'
	elif L[j] < L[i] and L[j] > x:
		x = L[j]
		j -= 1
		s += 'R'
	else:
		x = L[i]
		i += 1
		s += 'L'
print(len(s))
print(s)


def getHighAns(a, low, high):
	count = 1
	ans = ''
	ans += 'R'
	last = a[high]
	high -= 1
	while low <= high:
		if last < a[high]:
			count += 1
			ans += 'R'
			last = a[high]
			high -= 1
		else:
			break
	return (count, ans)

def getLowAns(a, low, high):
	count = 1
	ans = ''
	ans += 'L'
	last = a[low]
	low += 1
	while low <= high:
		if last < a[low]:
			count += 1
			ans += 'L'
			last = a[low]
			low += 1
		else:
			break
	return (count, ans)
n = int(input())
a = list(map(int, input().split()))
low = 0
high = n - 1
last = 0
count = 1
ans = ''
if a[low] < a[high]:
	last = a[low]
	ans += 'L'
	low += 1
else:
	last = a[high]
	ans += 'R'
	high -= 1
while low <= high:
	if a[high] == a[low] and last < a[low]:
		(ch, ah) = getHighAns(a, low, high)
		(cl, al) = getLowAns(a, low, high)
		if ch > cl:
			count += ch
			ans += ah
			break
		else:
			count += cl
			ans += al
			break
	elif last < a[low] < a[high]:
		last = a[low]
		ans += 'L'
		count += 1
		low += 1
	elif last < a[high] < a[low]:
		last = a[high]
		ans += 'R'
		count += 1
		high -= 1
	elif last < a[low]:
		last = a[low]
		ans += 'L'
		count += 1
		low += 1
	elif last < a[high]:
		last = a[high]
		ans += 'R'
		count += 1
		high -= 1
	else:
		break
print(count)
print(ans)


n = int(input())
l = [*map(int, input().split())]
prev = 0
res = []
while l:
	if l[0] == l[-1]:
		if prev >= l[0]:
			break
		if len(l) <= 2:
			res.append('L')
			break
		(c0, c1) = ([], [])
		p = prev
		for e in l:
			if p < e:
				c0.append('L')
				p = e
			else:
				break
		p = prev
		for e in l[::-1]:
			if p < e:
				c1.append('R')
				p = e
			else:
				break
		if len(c0) <= len(c1):
			res += c1
		else:
			res += c0
		break
	elif prev < l[0] and (l[0] < l[-1] or prev >= l[-1]):
		i = 0
		res.append('L')
	elif prev < l[-1]:
		i = -1
		res.append('R')
	else:
		break
	prev = l[i]
	del l[i]
print(len(res))
print(''.join(res))


input()
posled = list(map(int, input().split()))
last = 0
res = ''
first_ind = 0
last_ind = -1
len_posled = len(posled)
first_suit = False
last_suit = False
while len_posled > first_ind - last_ind - 1:
	if posled[first_ind] > last:
		first_suit = True
	if posled[last_ind] > last:
		last_suit = True
	if posled[first_ind] <= posled[last_ind]:
		if first_suit:
			last = posled[first_ind]
			res += 'L'
			first_ind += 1
		elif last_suit:
			last = posled[last_ind]
			res += 'R'
			last_ind -= 1
	elif last_suit:
		last = posled[last_ind]
		res += 'R'
		last_ind -= 1
	elif first_suit:
		last = posled[first_ind]
		res += 'L'
		first_ind += 1
	if not first_suit and (not last_suit):
		break
	first_suit = False
	last_suit = False
print(len(res))
print(res)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
ans = ''
prev = 0
while i < j:
	if arr[i] < arr[j]:
		if arr[i] > prev:
			ans += 'L'
			prev = arr[i]
			i += 1
		elif arr[j] > prev:
			ans += 'R'
			prev = arr[j]
			j -= 1
		else:
			break
	elif arr[i] > arr[j]:
		if arr[j] > prev:
			ans += 'R'
			prev = arr[j]
			j -= 1
		elif arr[i] > prev:
			ans += 'L'
			prev = arr[i]
			i += 1
		else:
			break
if i == j and arr[i] > prev:
	ans += 'R'
	prev = arr[i]
print(len(ans))
print(ans)


x = int(input())
z = list(map(int, input().split()))
left = []
right = []
for i in range(x):
	if i == x - 1 or z[i] < z[i + 1]:
		continue
	else:
		break
left = z[:i + 1]
for i in range(x - 1, 0, -1):
	if z[i] < z[i - 1]:
		continue
	else:
		break
right = z[i:x]
l = 0
r = len(right) - 1
if len(left) + len(right) == x + 1:
	right = right[1:]
print(len(left) + len(right))
r = len(right) - 1
while l < len(left) and r >= 0:
	try:
		while left[l] > right[r] and r >= 0:
			r -= 1
			print('R', end='')
		while left[l] < right[r] and l < len(left):
			l += 1
			print('L', end='')
	except Exception:
		break
print('R' * (r + 1), end='')
print('L' * (len(left) - l), end='')


n = int(input())
pos = list(map(int, input().split()))
ans = ''
c = sorted(pos)
NG = 0
VG = n - 1
for i in range(len(pos)):
	if pos[NG] == c[i]:
		ans += 'L'
		NG += 1
	elif pos[VG] == c[i]:
		ans += 'R'
		VG -= 1
print(len(ans), ans, sep='\n')


n = int(input())
x = list(map(int, input().strip().split()))
i = 0
j = n - 1
v = -1
steps = ''
while i != j:
	if x[i] > x[j]:
		if x[j] > v:
			steps += 'R'
			v = x[j]
			j -= 1
		elif x[i] > v:
			steps += 'L'
			v = x[i]
			i += 1
		else:
			break
	elif x[j] > x[i]:
		if x[i] > v:
			steps += 'L'
			v = x[i]
			i += 1
		elif x[j] > v:
			steps += 'R'
			v = x[j]
			j -= 1
		else:
			break
	else:
		if x[i] > v:
			vk = v
			k = i
			stepsL = ''
			while x[k] > vk and j != k:
				stepsL += 'L'
				vk = x[k]
				k += 1
			vk = v
			k = j
			stepsR = ''
			while x[k] > vk and i != k:
				stepsR += 'R'
				vk = x[k]
				k -= 1
			if len(stepsL) > len(stepsR):
				steps += stepsL
			else:
				steps += stepsR
		print(len(steps))
		print(steps)
		exit()
if x[i] > v:
	steps += 'R'
print(len(steps))
print(steps)


n = int(input())
a = list(map(int, input().split()))
s = ''
l = 0
cur = 0
r = n - 1
while l <= r and max(a[l], a[r]) > cur:
	if a[l] > cur > a[r] or a[r] >= a[l] > cur:
		s += 'L'
		cur = a[l]
		l += 1
	else:
		s += 'R'
		cur = a[r]
		r -= 1
print(len(s), s)


import sys
if len(sys.argv) >= 2:
	if sys.argv[1] == 'LOCAL':
		sys.stdin = open('input.in', 'r')
n = int(input())
l = [int(i) for i in input().split()]
ans = ''
i = 0
n = n - 1
lasttaken = 0
if l[0] < l[-1]:
	lasttaken = l[0]
	ans = 'L'
	i = 1
else:
	lasttaken = l[-1]
	ans = 'R'
	n = n - 1
it = 1
while i <= n:
	c = ''
	dif1 = l[n] - lasttaken
	dif2 = l[i] - lasttaken
	if dif1 > 0 and dif2 > 0:
		if l[i] < l[n]:
			c = 'L'
			lasttaken = l[i]
			i += 1
		else:
			lasttaken = l[n]
			c = 'R'
			n -= 1
		it += 1
	elif dif2 > 0:
		lasttaken = l[i]
		c = 'L'
		i += 1
		it += 1
	elif dif1 > 0:
		lasttaken = l[n]
		c = 'R'
		n -= 1
		it += 1
	else:
		break
	ans += c
print(it)
print(ans)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
n = int(input())
a = deque(map(int, input().split()))
z = []
length = 0
seq = ''
last = 0
while a and last < max(a[0], a[-1]):
	if min(a[0], a[-1]) > last:
		if min(a[0], a[-1]) == a[0]:
			last = a.popleft()
			seq += 'L'
		else:
			last = a.pop()
			seq += 'R'
	elif max(a[0], a[-1]) == a[0]:
		last = a.popleft()
		seq += 'L'
	else:
		last = a.pop()
		seq += 'R'
	length += 1
print(length)
print(seq)


n = int(input())
ai = list(map(int, input().split()))
ans = 0
ans2 = ''
num = 0
left = 0
right = n - 1
flag = 0
for i in range(n):
	if ai[left] <= num:
		if ai[right] <= num:
			break
		num = ai[right]
		ans += 1
		right -= 1
		ans2 += 'R'
		continue
	if ai[right] <= num:
		if ai[left] <= num:
			break
		num = ai[left]
		ans += 1
		left += 1
		ans2 += 'L'
		continue
	if ai[left] > ai[right]:
		num = ai[right]
		ans += 1
		right -= 1
		ans2 += 'R'
	elif ai[left] == ai[right]:
		if left == right:
			ans += 1
			ans2 += 'L'
			break
		flag = 1
		break
	else:
		num = ai[left]
		ans += 1
		left += 1
		ans2 += 'L'
if flag == 1:
	left2 = left
	temp = 0
	num2 = num
	while left2 < right:
		if ai[left2] > num2:
			temp += 1
			num2 = ai[left2]
		else:
			break
		left2 += 1
	temp2 = 0
	right2 = right
	num2 = num
	while right2 > left:
		if ai[right2] > num2:
			temp2 += 1
			num2 = ai[right2]
		else:
			break
		right2 -= 1
	if temp >= temp2:
		ans += temp
		ans2 += 'L' * temp
	else:
		ans += temp2
		ans2 += 'R' * temp2
print(ans)
print(ans2)


N = int(input())
nums = list(map(int, input().split(' ')))
res = []
curr = -1
left = 0
right = N - 1
if nums[left] < nums[right]:
	res.append('L')
	curr = nums[left]
	left += 1
else:
	res.append('R')
	curr = nums[right]
	right -= 1
while True:
	if left == right:
		if nums[left] > curr:
			res.append('L')
		break
	if nums[left] > curr and (nums[left] < nums[right] or (nums[right] < nums[left] and nums[right] <= curr)):
		res.append('L')
		curr = nums[left]
		left += 1
	elif nums[right] > curr and (nums[right] < nums[left] or (nums[left] < nums[right] and nums[left] <= curr)):
		res.append('R')
		curr = nums[right]
		right -= 1
	else:
		break
print(len(res))
print(''.join(res))


import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

def sain():
	return input().split()

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007

def readTree(n, m):
	adj = [deque([]) for _ in range(n + 1)]
	for _ in range(m):
		(u, v) = ain()
		adj[u].append(v)
		adj[v].append(u)
	return adj

def solve(d):
	xy = [MIN, MAX]
	for rt in d:
		if xy[0] > rt[1]:
			return -1
		if xy[1] < rt[0]:
			return -1
		xy[0] = max(xy[0], rt[0])
		xy[1] = min(xy[1], rt[1])
	return xy

def main():
	n = iin()
	a = ain()
	i = 0
	j = n - 1
	x = -1
	d = deque([])
	c = 0
	while i <= j:
		if a[i] - x < 0 and a[j] - x < 0:
			break
		elif a[i] - x > 0 and a[j] - x < 0:
			x = a[i]
			i += 1
			d.append('L')
		elif a[i] - x < 0 and a[j] - x > 0:
			x = a[j]
			j -= 1
			d.append('R')
		elif a[i] > a[j]:
			x = a[j]
			j -= 1
			d.append('R')
		else:
			x = a[i]
			i += 1
			d.append('L')
		c += 1
	print(c)
	print(''.join(d))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	r = len(a) - 1
	res = []
	last = -1
	while l <= r and max(a[l], a[r]) >= last:
		if a[l] < a[r] and a[l] >= last or a[r] < last:
			res.append('L')
			last = a[l]
			l += 1
		else:
			res.append('R')
			last = a[r]
			r -= 1
	print(len(res))
	print(''.join(res))
main()


n = int(input())
M = list(map(int, input().split()))
L = [1] * n
R = [1] * n
for i in range(1, len(M)):
	if M[i] < M[i - 1]:
		R[i] = R[i - 1] + 1
	if M[n - 1 - i] < M[n - i]:
		L[n - 1 - i] = L[n - i] + 1
ans = []
last = -1
(l, r) = (0, n - 1)
while r >= l:
	if M[r] <= last and M[l] <= last:
		break
	if M[r] == M[l]:
		if L[l] > R[r]:
			ans += ['L']
			last = M[l]
			l += 1
		else:
			ans += ['R']
			last = M[r]
			r -= 1
	elif M[r] <= last:
		last = M[l]
		ans += ['L']
		l += 1
	elif M[l] <= last:
		last = M[r]
		ans += ['R']
		r -= 1
	elif M[l] < M[r]:
		last = M[l]
		ans += ['L']
		l += 1
	else:
		last = M[r]
		ans += ['R']
		r -= 1
print(len(ans))
print(''.join(ans))


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
lens = RI()
elem = RMI()
left = 0
rite = lens - 1
last = -1
seq = ''
while left <= rite:
	if elem[left] > last and (elem[rite] >= elem[left] or elem[rite] <= last):
		last = elem[left]
		seq += 'L'
		left += 1
	elif elem[rite] > last and (elem[left] >= elem[rite] or elem[left] <= last):
		last = elem[rite]
		seq += 'R'
		rite -= 1
	else:
		break
print(len(seq))
print(seq)


__version__ = '1.0'
__date__ = '2019-04-26'
import sys

def rec_solve(a, l, r, last):
	choices = []
	while l <= r:
		if a[l] == a[r] and a[l] > last:
			sub_ans_1 = rec_solve(a, l + 1, r, a[l])
			sub_ans_2 = rec_solve(a, l, r - 1, a[l])
			if len(sub_ans_1) > len(sub_ans_2):
				choices.append('L')
				choices += sub_ans_1
				return choices
			else:
				choices.append('R')
				choices += sub_ans_2
				return choices
		elif a[l] < a[r] and a[l] > last:
			last = a[l]
			choices.append('L')
			l += 1
		elif a[r] > last:
			last = a[r]
			choices.append('R')
			r -= 1
		elif a[l] > last:
			last = a[l]
			choices.append('L')
			l += 1
		else:
			return choices
	return choices

def solve(n, a):
	return rec_solve(a, 0, n - 1, 0)

def main(argv=None):
	n = int(input())
	a = list(map(int, input().split()))
	choice = solve(n, a)
	print(len(choice))
	print(''.join(choice))
	return 0
STATUS = main()
sys.exit(STATUS)


n = int(input())
l1 = list(map(int, input().split()))
x = 0
y = n - 1
l2 = []
f = 0
while x < y:
	if l1[x] < f and l1[y] < f:
		break
	elif l1[x] < l1[y]:
		if l1[x] > f:
			f = l1[x]
			x += 1
			l2.append('L')
		else:
			f = l1[y]
			y -= 1
			l2.append('R')
	elif l1[y] > f:
		f = l1[y]
		y -= 1
		l2.append('R')
	else:
		f = l1[x]
		x += 1
		l2.append('L')
if x == y:
	if l1[x] > f:
		l2.append('L')
print(len(l2))
print(''.join(l2))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
out = ''
m = min(a[l], a[r]) - 1
while l != r:
	if a[l] < a[r] and a[l] > m:
		out += 'L'
		m = a[l]
		l += 1
	elif a[l] > a[r] and a[r] > m:
		out += 'R'
		m = a[r]
		r -= 1
	elif a[l] > m:
		out += 'L'
		m = a[l]
		l += 1
	elif a[r] > m:
		out += 'R'
		m = a[r]
		r -= 1
	else:
		break
if l == r:
	if a[l] < a[r] and a[l] >= m:
		out += 'L'
	elif a[l] > a[r] and a[r] >= m:
		out += 'R'
	elif a[l] >= m:
		out += 'L'
	elif a[r] >= m:
		out += 'R'
print(str(len(out)))
print(out)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
s = ''
p = min(a[0], a[-1]) - 1
while i < j:
	if a[i] > a[j] and a[j] > p:
		p = a[j]
		j -= 1
		s += 'R'
	elif a[i] > a[j] and a[i] > p:
		p = a[i]
		i += 1
		s += 'L'
	elif a[i] < a[j] and a[i] > p:
		p = a[i]
		i += 1
		s += 'L'
	elif a[i] < a[j] and a[j] > p:
		p = a[j]
		j -= 1
		s += 'R'
	else:
		break
if a[i] > p:
	s += 'R'
print(len(s))
print(s)