Problem: 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 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 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.

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		Reader in = new Reader();
		int n = in.nextInt();
		int[] a = in.na(n);
		int l = 0;
		int r = n - 1;
		char[] ans = new char[n+1];
		int[] ansV = new int[n+1];
		int idx = 0;
		boolean done = false;
		while (l <= r && !done) {
			if (a[l] == a[r]) {
				if(l==r&&(idx == 0 || a[l] > ansV[idx - 1])) {
					ans[idx++] = 'L';
				}else if (idx == 0 || a[l] > ansV[idx - 1]) {
					int rightSub = 0;
					for (int i = l + 1; i < r; i++) {
						if (a[i] > a[i - 1]) {
							rightSub++;
						} else
							break;
					}
					int leftSub = 0;
					for (int i = r - 1; i > l; i--) {
						if (a[i] > a[i + 1]) {
							leftSub++;
						} else
							break;
					}
					if (leftSub == rightSub && leftSub == 0) {
						ans[idx++] = 'L';
					} else {
						if (rightSub > leftSub) {
							ans[idx++] = 'L';
							for (int i = 0; i < rightSub; i++) {
								ans[idx++] = 'L';
							}
						} else {
							ans[idx++] = 'R';
							for (int i = 0; i < leftSub; i++) {
								ans[idx++] = 'R';
							}
						}
					}
				}
				done = true;
			} else if (a[l] < a[r]) {
				if (idx == 0 || a[l] > ansV[idx - 1]) {
					ans[idx++] = 'L';
					ansV[idx - 1] = a[l];
					l++;
				} else if (a[r] > ansV[idx - 1]) {
					ans[idx++] = 'R';
					ansV[idx - 1] = a[r];
					r--;
				} else
					done = true;
			} else {
				if (idx == 0 || a[r] > ansV[idx - 1]) {
					ans[idx++] = 'R';
					ansV[idx - 1] = a[r];
					r--;
				} else if (a[l] > ansV[idx - 1]) {
					ans[idx++] = 'L';
					ansV[idx - 1] = a[l];
					l++;
				} else
					done = true;
			}
		}
		System.out.println(idx);
		for (int i = 0; i < idx; i++)
			System.out.print(ans[i]);
	}

	public static class Util {
		static boolean isPrime(int n) {
			if (n <= 1)
				return false;
			if (n <= 3)
				return true;
			if (n % 2 == 0 || n % 3 == 0)
				return false;
			for (int i = 5; i * i <= n; i = i + 6)
				if (n % i == 0 || n % (i + 2) == 0)
					return false;
			return true;
		}

		public static int upperBound(int[] a, int v) {
			if (a[0] > v)
				return -1;
			int l = 0, h = a.length - 1;
			while (l < h) {
				int mid = (l + h) / 2;
				if (v >= a[mid])
					l = mid + 1;
				else
					h = mid - 1;
			}
			if (v < a[l])
				return l - 1;
			return l;
		}

		public static int lowerBound(int[] a, int v) {
			if (a[a.length - 1] < v)
				return -1;
			int l = 0, h = a.length - 1;
			while (l < h) {
				int mid = (l + h) / 2;
				if (v <= a[mid])
					h = mid - 1;
				else
					l = mid + 1;
			}
			if (v > a[l])
				return l + 1;
			return l;
		}

		public static boolean[] getSieve(int n) {
			boolean[] isPrime = new boolean[n + 1];
			for (int i = 2; i <= n; i++)
				isPrime[i] = true;
			for (int i = 2; i * i <= n; i++)
				if (isPrime[i])
					for (int j = i; i * j <= n; j++)
						isPrime[i * j] = false;
			return isPrime;
		}

		public static int gcd(int a, int b) {
			if (a == 0)
				return b;
			return gcd(b % a, a);
		}

		public static long modAdd(long a, long b, long mod) {
			return (a % mod + b % mod) % mod;
		}

		public static long modMul(long a, long b, long mod) {
			return ((a % mod) * (b % mod)) % mod;
		}
	}

	static class Pair implements Comparable<Pair> {
		int idx, value;

		public Pair(int idx, int value) {
			this.idx = idx;
			this.value = value;
		}

		@Override
		public int compareTo(Pair o) {
			return this.value - o.value;
		}
	}

	static class Graph {
		private ArrayList<Integer> con[];
		private boolean[] visited;

		public Graph(int n) {
			con = new ArrayList[n];
			for (int i = 0; i < n; ++i)
				con[i] = new ArrayList();
			visited = new boolean[n];
		}

		public void reset() {
			Arrays.fill(visited, false);
		}

		public void addEdge(int v, int w) {
			con[v].add(w);
		}

		public void dfs(int cur) {
			visited[cur] = true;
			for (Integer v : con[cur]) {
				if (!visited[v]) {
					dfs(v);
				}
			}
		}

		public void bfs(int cur) {
			Queue<Integer> q = new LinkedList<>();
			q.add(cur);
			visited[cur] = true;
			while (!q.isEmpty()) {
				cur = q.poll();
				for (Integer v : con[cur]) {
					if (!visited[v]) {
						visited[v] = true;
						q.add(v);
					}
				}
			}
		}
	}

	static class Reader {
		static BufferedReader br;
		static StringTokenizer st;

		public Reader() {
			this.br = new BufferedReader(new InputStreamReader(System.in));
		}

		public int[] na(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nl(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public String[] nS(int n) {
			String[] a = new String[n];
			for (int i = 0; i < n; i++)
				a[i] = next();
			return a;
		}

		public int nextInt() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Integer.parseInt(st.nextToken());
		}

		public double nextDouble() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Double.parseDouble(st.nextToken());
		}

		public Long nextLong() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return Long.parseLong(st.nextToken());
		}

		public String next() {
			if (st == null || !st.hasMoreTokens())
				try {
					readLine();
				} catch (Exception e) {
				}
			return st.nextToken();
		}

		public static void readLine() {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
			}
		}
	}
}