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.

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 $[1, 2, 4, 3, 2]$ the answer is $4$ (you take $1$ and the sequence becomes $[2, 4, 3, 2]$, then you take the rightmost element $2$ and the sequence becomes $[2, 4, 3]$, then you take $3$ and the sequence becomes $[2, 4]$ and then you take $4$ and the sequence becomes $[2]$, the obtained increasing sequence is $[1, 2, 3, 4]$).


-----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 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$.


-----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
1 2 4 3 2

Output
4
LRRR

Input
7
1 3 5 6 5 4 2

Output
6
LRLRRR

Input
3
2 2 2

Output
1
R

Input
4
1 2 4 3

Output
4
LLRR



-----Note-----

The first example is described in the problem statement.

Source: codeforces | Difficulty: MEDIUM_HARD
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)


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])))


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)


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 = [*list(map(int, input().split()))]
ans = solve(0, n - 1, -1)
print(len(ans))
print(ans)


__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

def __starting_point():
	STATUS = main()
	return STATUS
__starting_point()


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()


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)


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))


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()))
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)


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))


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


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))


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)


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)


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 = 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] != a[r]:
		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'
	else:
		i = l
		j = r
		y = 1
		z = 1
		if l != r:
			while a[i] < a[i + 1]:
				y += 1
				i += 1
			while a[j] < a[j - 1]:
				z += 1
				j -= 1
			if y > z:
				s += 'L' * y
				break
			else:
				s += 'R' * z
				break
		elif a[r] > x:
			s += 'R'
			r -= 1
print(len(s))
print(s)


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
	elif p1 == p2:
		s += 'R'
		p1 += 1
	elif a[p1] == a[p2] and a[p1] > m:
		sp2 = 'R'
		p22 = p2
		while p22 > p1 and a[p22 - 1] > a[p22]:
			sp2 += 'R'
			p22 -= 1
		sp1 = 'L'
		p11 = p1
		while p11 < p2 and a[p11 + 1] > a[p11]:
			sp1 += 'L'
			p11 += 1
		if len(sp2) > len(sp1):
			s += sp2
		else:
			s += sp1
		break
	else:
		break
print(len(s))
print(s)


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='')


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())
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)))


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()


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)


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)


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 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='')


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='')


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(next(self))

	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))

def __starting_point():
	Main().solve()
__starting_point()


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))


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))


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(X) for X in input().split()]
if n == 1:
	print(1)
	print('L')
else:
	for m in range(1, n):
		if a[m] <= a[m - 1]:
			break
	for p in range(n - 2, -1, -1):
		if a[p] <= a[p + 1]:
			break
	p = n - 1 - p
	if True:
		(i, j) = (0, n - 1)
		an = []
		x = [-1]
		while i < j and i < n and (j > -1):
			if a[i] > a[j] and a[j] > x[-1]:
				an.append('R')
				x.append(a[j])
				p -= 1
				j -= 1
			elif a[j] > a[i] and a[i] > x[-1]:
				an.append('L')
				x.append(a[i])
				m -= 1
				i += 1
			elif False:
				pass
			elif a[i] > a[j] and a[i] > x[-1]:
				an.append('L')
				x.append(a[i])
				m -= 1
				i += 1
			elif False:
				pass
			elif a[j] > a[i] and a[j] > x[-1]:
				an.append('R')
				x.append(a[j])
				p -= 1
				j -= 1
			elif False:
				pass
			elif a[j] == a[i] and x[-1] < a[j]:
				if p > m:
					an.append('R')
					x.append(a[j])
					p -= 1
					j -= 1
				else:
					an.append('L')
					x.append(a[i])
					m -= 1
					i += 1
			else:
				break
		if i == j and a[i] > x[-1]:
			an.append('L')
		print(len(an))
		print(''.join(an))


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()))
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)


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))


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 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())
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]:
		start = i
		k = 0
		last = a[i]
		i += 1
		while i <= j:
			if a[i] <= last:
				break
			else:
				last = a[i]
				k += 1
				i += 1
		last = a[j]
		k2 = 0
		i = start
		j -= 1
		while i <= j:
			if a[j] <= last:
				break
			else:
				last = a[j]
				k2 += 1
				j -= 1
		if k > k2:
			ans += 'L' * (k + 1)
		else:
			ans += 'R' * (k2 + 1)
		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)


n = int(input())
a = list(map(int, input().split()))
sp = [0]
s = ''
l = 0
r = n - 1
while r - l != -1:
	if a[l] == a[r] and l != r:
		sp1 = sp.copy()
		s1 = s
		while sp[-1] < a[l]:
			sp.append(a[l])
			l += 1
			s += 'L'
		while sp1[-1] < a[r]:
			sp1.append(a[r])
			r -= 1
			s1 += 'R'
		if len(sp) > len(sp1):
			print(len(sp) - 1)
			print(s)
		else:
			print(len(sp1) - 1)
			print(s1)
		exit(0)
	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)


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

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

def iinp():
	return int(input())

def test():
	return int(input())

def inp():
	return input()

def fun(l, curr, res):
	while l:
		if l[0] > curr and l[-1] > curr:
			if l[0] < l[-1]:
				curr = l.pop(0)
				res += 'L'
			elif l[-1] > l[0]:
				curr = l.pop()
				res += 'R'
			else:
				pass
		elif l[0] > curr:
			curr = l.pop(0)
			res += 'L'
		elif l[-1] > curr:
			curr = l.pop()
			res += 'R'
		else:
			break
	return res

def solve():
	n = iinp()
	l = linp()
	curr = -1
	res = ''
	while l:
		if l[0] > curr and l[-1] > curr:
			if l[0] < l[-1]:
				curr = l.pop(0)
				res += 'L'
				n -= 1
			elif l[0] > l[-1]:
				curr = l.pop()
				res += 'R'
				n -= 1
			else:
				flag = 'L'
				(i, j) = (0, n - 1)
				(counti, countj) = (0, 0)
				while i < n - 1 and j > 0:
					flag1 = True
					if l[i + 1] > l[i]:
						counti += 1
						i += 1
						flag1 = False
					if l[j - 1] > l[j]:
						countj += 1
						j -= 1
						flag1 = False
					if counti > countj:
						flag = 'L'
						break
					elif countj > counti:
						flag = 'R'
						break
					if flag1:
						break
				if flag == 'L':
					curr = l.pop(0)
					res += 'L'
				else:
					curr = l.pop()
					res += 'R'
		elif l[0] > curr:
			curr = l.pop(0)
			res += 'L'
			n -= 1
		elif l[-1] > curr:
			curr = l.pop()
			res += 'R'
			n -= 1
		else:
			break
	print(str(len(res)) + '\n' + res)

def main():
	solve()
main()


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)


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[l] == a[r] and a[l] > la:
		al = 1
		ar = 1
		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
	elif (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
	else:
		break
print(len(ans))
print(''.join(ans))


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())
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='')


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='')


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)


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()


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	last = 0
	s = ''
	(l, r) = (0, n - 1)
	while True:
		if last > max(arr[l], arr[r]) or l > r:
			break
		elif arr[r] < arr[l] and arr[r] > last or arr[r] > last > arr[l]:
			last = arr[r]
			r -= 1
			s += 'R'
		elif arr[l] < arr[r] and arr[l] > last or arr[l] > last > arr[r]:
			last = arr[l]
			l += 1
			s += 'L'
		else:
			(lt, rt) = (0, 0)
			if arr[l] > last:
				lt = 1
				while True:
					if l + lt > r:
						break
					if arr[l + lt] > arr[l + lt - 1]:
						pass
					else:
						break
					lt += 1
			if arr[r] > last:
				rt = 1
				while True:
					if r - rt < l:
						break
					if arr[r - rt] > arr[r - rt + 1]:
						pass
					else:
						break
					rt += 1
			if lt > rt:
				s += 'L' * lt
			else:
				s += 'R' * rt
			break
	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())
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)


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)


def __starting_point():
	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))
__starting_point()


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()


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))


from sys import stdin, stdout
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys

class merge_find:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def all_factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (20 - len(b)) + b
	return b

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True
factorial_modP = []

def warm_up_fac(MOD):
	nonlocal factorial_modP, fac_warmup
	if fac_warmup:
		return
	factorial_modP = [1 for _ in range(fac_warmup_size + 1)]
	for i in range(2, fac_warmup_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warmup = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	nonlocal fac_warmup, factorial_modP
	if not fac_warmup:
		warm_up_fac(MOD)
		fac_warmup = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def test_print(*args):
	if testingMode:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def display_2D_list(li):
	for i in li:
		print(i)

def prefix_sum(li):
	sm = 0
	res = []
	for i in li:
		sm += i
		res.append(sm)
	return res

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
import heapq, itertools
pq = []
entry_finder = {}
REMOVED = '<removed-task>'

def add_task(task, priority=0):
	if task in entry_finder:
		remove_task(task)
	count = next(counter)
	entry = [priority, count, task]
	entry_finder[task] = entry
	heapq.heappush(pq, entry)

def remove_task(task):
	entry = entry_finder.pop(task)
	entry[-1] = REMOVED

def pop_task():
	while pq:
		(priority, count, task) = heapq.heappop(pq)
		if task is not REMOVED:
			del entry_finder[task]
			return task
	raise KeyError('pop from an empty priority queue')
memory = dict()

def clear_cache():
	nonlocal memory
	memory = dict()

def cached_fn(fn, *args):
	nonlocal memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def ncr(n, r):
	return math.factorial(n) / (math.factorial(n - r) * math.factorial(r))

def binary_serach(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = False
testingMode = False
fac_warmup_size = 10 ** 5 + 100
optimiseForReccursion = True
from math import factorial

def main():
	get_int()
	li = deque(get_list())
	prev = 0
	res = []
	while len(li) > 0:
		if li[0] == li[-1] and li[0] > prev and (len(li) > 1):
			guess1 = 0
			guess2 = 0
			prev = li[0]
			p = prev
			dq = list(li)
			n = len(dq)
			for i in range(1, n):
				if dq[i] > prev:
					prev = dq[i]
				else:
					break
				if i == n - 1:
					i = n
			guess1 = i
			dq.reverse()
			prev = p
			for i in range(1, n):
				if dq[i] > prev:
					prev = dq[i]
				else:
					break
				if i == n - 1:
					i = n
			guess2 = i
			if guess1 > guess2:
				res += ['L'] * guess1
			else:
				res += ['R'] * guess2
			break
		elif li[0] < li[-1] and li[0] > prev:
			prev = li.popleft()
			res.append('L')
		elif li[-1] > prev:
			prev = li.pop()
			res.append('R')
		elif li[0] > prev:
			prev = li.popleft()
			res.append('L')
		else:
			break
	print(len(res))
	display_list(res, '')
if TestCases:
	for i in range(get_int()):
		cProfile.run('main()') if testingMode else main(i)
else:
	(cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()


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()


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())
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))


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='')


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())

def solve(l, i, j):
	ans1 = 0
	for k in range(i, j):
		if l[k + 1] > l[k]:
			ans1 += 1
		else:
			break
	ans2 = 0
	for k in range(j, i, -1):
		if l[k] < l[k - 1]:
			ans2 += 1
		else:
			break
	if ans1 > ans2:
		return [1, ans1]
	else:
		return [0, ans2]
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:
			break
		if l[i] == l[j] and l[i] > temp:
			a = solve(l, i, j)
			ans += a[1]
			ans += 1
			if a[0] == 1:
				k.append('L')
				for kk in range(a[1]):
					k.append('L')
				i += a[1]
				i += 1
			else:
				k.append('R')
				for kk in range(a[1]):
					k.append('R')
				j -= a[1]
				j -= 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('')


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)
	return
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())
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='')


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)


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)


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))


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()


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
		elif arr[j] > arr[i]:
			ans += 'L'
			last = arr[i]
			i += 1
		else:
			a1 = 1
			a2 = 1
			while i + a1 <= j and arr[i + a1] > arr[i + a1 - 1]:
				a1 += 1
			while j - a2 >= i and arr[j - a2 + 1] < arr[j - a2]:
				a2 += 1
			if a1 > a2:
				ans += 'L' * a1
				break
			else:
				ans += 'R' * a2
				break
	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)


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()
		elif a[-1] == a[0]:
			le = a.copy()
			temp2 = le[0]
			le.popleft()
			while le and temp2 < le[0]:
				temp2 = le[0]
				le.popleft()
			ri = a.copy()
			temp3 = ri[0]
			ri.pop()
			while ri and temp3 < ri[-1]:
				temp3 = ri[-1]
				ri.pop()
			if len(a) - len(le) > len(a) - len(ri):
				ans.append('L')
				temp = a[0]
				a.popleft()
			else:
				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())
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)


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
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[0] > que[-1]:
		if que[-1] > cur:
			cur = que.pop()
			ans.append('R')
			continue
		elif que[0] > cur:
			cur = que.popleft()
			ans.append('L')
			continue
		else:
			break
	else:
		cnt1 = 0
		tmp = cur
		que1 = que.copy()
		while que1 and que1[0] > tmp:
			tmp = que1.popleft()
			cnt1 += 1
		cnt2 = 0
		tmp = cur
		que2 = que.copy()
		while que2 and que2[-1] > tmp:
			tmp = que2.pop()
			cnt2 += 1
		if cnt1 >= cnt2:
			ans += 'L' * cnt1
		else:
			ans += 'R' * cnt2
		break
print(len(ans))
print(''.join(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))


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 = 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()


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()))
high = n - 1
low = 0
last = 0
if a[high] == a[low] and last < a[low]:
	count = 0
	ans = ''
	(ch, ah) = getHighAns(a, low, high)
	(cl, al) = getLowAns(a, low, high)
	if ch > cl:
		count += ch
		ans += ah
		print(count)
		print(ans)
	else:
		count += cl
		ans += al
		print(count)
		print(ans)
else:
	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)


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
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())
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))


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 = [0]
	l = 0
	r = n - 1
	while l <= r:
		if arr[l] == arr[r] and l != r and (arr[l] > nums[-1]):
			u1 = [0]
			left = l
			right = r
			while left < right and u1[-1] < arr[left]:
				u1.append(arr[left])
				left += 1
			u2 = [0]
			left = l
			right = r
			while right > left and u2[-1] < arr[right]:
				u2.append(arr[right])
				right -= 1
			if len(u1) > len(u2):
				stack += ['L'] * (len(u1) - 1)
			else:
				stack += ['R'] * (len(u2) - 1)
			break
		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())
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='')


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)


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 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())
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)


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))


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))


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
(l, r, out2) = (0, sz - 1, [])
for i in range(len(lst)):
	if not i:
		if lst[l] < lst[r]:
			out2.append('L')
			prev = lst[l]
			l += 1
		else:
			out2.append('R')
			prev = lst[r]
			r -= 1
	else:
		b = False
		if l < len(lst) and lst[l] > prev and (lst[l] <= lst[r]):
			out2.append('L')
			prev = lst[l]
			l += 1
			b = True
		elif r >= 0 and lst[r] > prev:
			out2.append('R')
			prev = lst[r]
			r -= 1
			b = True
		if not b and l < len(lst) and (lst[l] > prev):
			out2.append('L')
			prev = lst[l]
			l += 1
if len(out2) > len(out):
	out = out2.copy()
(l, r, out3) = (0, sz - 1, [])
for i in range(len(lst)):
	if not i:
		if lst[l] <= lst[r]:
			out3.append('L')
			prev = lst[l]
			l += 1
		else:
			out3.append('R')
			prev = lst[r]
			r -= 1
	else:
		b = False
		if l < len(lst) and lst[l] > prev and (lst[l] <= lst[r]):
			out3.append('L')
			prev = lst[l]
			l += 1
			b = True
		elif r >= 0 and lst[r] > prev:
			out3.append('R')
			prev = lst[r]
			r -= 1
			b = True
		if not b and l < len(lst) and (lst[l] > prev):
			out3.append('L')
			prev = lst[l]
			l += 1
if len(out3) > len(out):
	out = out3.copy()
(l, r, out4) = (0, sz - 1, [])
for i in range(len(lst)):
	if not i:
		if lst[l] <= lst[r]:
			out4.append('L')
			prev = lst[l]
			l += 1
		else:
			out4.append('R')
			prev = lst[r]
			r -= 1
	else:
		b = False
		if l < len(lst) and lst[l] > prev and (lst[l] < lst[r]):
			out4.append('L')
			prev = lst[l]
			l += 1
			b = True
		elif r >= 0 and lst[r] > prev:
			out4.append('R')
			prev = lst[r]
			r -= 1
			b = True
		if not b and l < len(lst) and (lst[l] > prev):
			out4.append('L')
			prev = lst[l]
			l += 1
if len(out4) > len(out):
	out = out4.copy()
print(len(out))
print(*out, sep='')


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)


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')
sequence2 = [0]
moves2 = []
i = 0
j = n - 1
while i != j:
	if arr[i] > arr[j]:
		if arr[j] > sequence2[-1]:
			sequence2.append(arr[j])
			j -= 1
			moves2.append('R')
		elif arr[i] > sequence2[-1]:
			sequence2.append(arr[i])
			i += 1
			moves2.append('L')
		else:
			break
	elif arr[i] > sequence2[-1]:
		sequence2.append(arr[i])
		i += 1
		moves2.append('L')
	elif arr[j] > sequence2[-1]:
		sequence2.append(arr[j])
		j -= 1
		moves2.append('R')
	else:
		break
if i == j:
	if arr[i] > sequence2[-1]:
		sequence2.append(arr[i])
		moves2.append('R')
if len(sequence2) > len(sequence):
	print(len(sequence2) - 1)
	for i in moves2:
		print(i, end='')
else:
	print(len(sequence) - 1)
	for i in moves:
		print(i, end='')


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())
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)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
n = ii()
l = li()
k = []
d = ''
i = 0
j = n - 1
z = 0
o1 = o2 = True
while i <= j:
	if l[i] == z and l[j] == z:
		break
	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 and l[i] == l[j]:
			d += 'L'
			z = l[i]
			i += 1
			o2 = False
		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
k.append(d)
d = ''
i = 0
j = n - 1
z = 0
o1 = o2 = True
while i <= j:
	if l[i] == z and l[j] == z:
		break
	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 and l[i] == l[j]:
			d += 'R'
			z = l[j]
			j -= 1
			o1 = False
		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
k.append(d)
h = max(k, key=len)
print(len(h))
print(h)


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')


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


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)


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)


n = int(input())
a = [int(x) for x in input().split(' ')]
left = 0
right = n - 1
curr = 0
ans = ''
while left <= right:
	if curr < a[left] and curr < a[right]:
		if a[left] < a[right]:
			ans += 'L'
			curr = a[left]
			left += 1
		elif a[left] > a[right]:
			ans += 'R'
			curr = a[right]
			right -= 1
		else:
			count_left = left + 1
			while count_left <= right and a[count_left] > a[count_left - 1]:
				count_left += 1
			count_right = right - 1
			while count_right >= left and a[count_right] > a[count_right + 1]:
				count_right -= 1
			if count_left - left - 1 > right - count_right - 1:
				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)


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)


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))


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='')