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.
//package Codeforces.Contest.Div3.R_555.C;

import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;

public class C2 {

    public void solve(int[] ar) {

        ArrayList<Integer> arrayList = new ArrayList<>();
        StringBuilder ans = new StringBuilder();

        int left = 0, right = ar.length - 1;
        while (left <= right) {

            Integer lastAdded = arrayList.size() > 0 ? arrayList.get(arrayList.size() - 1) : 0;

            if (left == right) {
                if (lastAdded < ar[left]) {
                    arrayList.add(ar[left]);
                    ans.append('L');
                    ++left;
                }
                break;
            }

            if (ar[left] < ar[right]) {
                if (lastAdded < ar[left]) {
                   arrayList.add(ar[left]);
                   ans.append('L');
                   ++left;
               }
               else if (lastAdded < ar[right]) {
                   arrayList.add(ar[right]);
                   ans.append('R');
                   --right;
               }
               else
                   break;
            }
            else if (ar[left] > ar[right]) {
                if (lastAdded < ar[right]) {
                    arrayList.add(ar[right]);
                    ans.append('R');
                    --right;
                }
                else if (lastAdded < ar[left]) {
                    arrayList.add(ar[left]);
                    ans.append('L');
                    ++left;
                }
                else
                    break;
            }
            else {
                int lc = 0, rc = 0;
                for (int i = left; i < right; i++) {
                    if (ar[i] < ar[i+1])++lc;
                    else break;
                }
                for (int i = right; i > left; i--) {
                    if (ar[i] < ar[i-1])++rc;
                    else break;
                }
                if (lc >= rc) {

                    if (lastAdded < ar[left]) {
                        arrayList.add(ar[left]);
                        ans.append('L');
                        ++left;
                    }
                    else break;
                }
                else {
                    if (lastAdded < ar[right]) {
                        arrayList.add(ar[right]);
                        ans.append('R');
                        --right;
                    }
                    else break;
                }
            }
        }

        out.println(ans.length());
        out.println(ans);
    }

    public static PrintWriter out;
    public static void main(String[] args) throws IOException {

        boolean fileInOut = C2.class.getPackage() != null;

        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(fileInOut ? C2.class.getResourceAsStream("in.txt") : System.in)));
        out = new PrintWriter(new BufferedOutputStream(fileInOut ? new FileOutputStream("out.txt") : System.out), true);

        int totalTestCase = fileInOut ? sc.nextInt() : 1;

        for (int testCaseNumber = 1; testCaseNumber <= totalTestCase; testCaseNumber++) {
            int arLength = sc.nextInt();
            int[] ar = new int[arLength];

            for (int arIndex = 0; arIndex < ar.length; arIndex++) {
                ar[arIndex] = sc.nextInt();
            }

            new C2().solve(ar);
        }

        if (fileInOut) {

            String outputFile = "out.txt";

            BufferedReader reader1 = new BufferedReader(new FileReader(C2.class.getResource("ans.txt").getFile()));
            BufferedReader reader2 = new BufferedReader(new FileReader(outputFile));

            String line1 = reader1.readLine();
            String line2 = reader2.readLine();

            boolean areEqual = true;
            int lineNum = 1;

            while (line1 != null || line2 != null) {

                if (line1 == null || line2 == null) {

                    areEqual = false;
                    break;
                } else if (!line1.equals(line2)) {

                    areEqual = false;
                    break;
                }

                line1 = reader1.readLine();
                line2 = reader2.readLine();

                lineNum++;
            }

            if (areEqual) {

                System.out.println("All Test Cases Passed !");
            } else {

                System.out.println("Output differ at line " + lineNum);
                System.out.println("ans.txt has " + line1 + " and out.txt has " + line2 + " at line " + lineNum);
            }

            reader1.close();
            reader2.close();
        }
    }
}
