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.util.*;
import java.io.*;
import static java.lang.Math.*;
public class Main {
    static final long MOD = 1_000_000_007 , INF = 1_000_000_000_000_000L;
    static final int INf = 1_000_000_000;
    static FastReader reader;
    static PrintWriter writer;
    public static void main(String[] args) {
        Thread t = new Thread(null, new O(), "Integer.MAX_VALUE", 100000000);
        t.start();
    }
    static class O implements Runnable {
        public void run() {
            try {
                magic();
            }
            catch (Exception e) {
                e.printStackTrace();
                System.exit(1);
            }
        }
    }
    static class FastReader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public FastReader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public FastReader(String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException {
            byte[] buf = new byte[1000000];
            int cnt = 0, c;
            while ((c = read()) != -1) {
                if (c == '\n') break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg) return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ') c = read();
            boolean neg = (c == '-');
            if (neg) c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.') while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10);
            if (neg) return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1) buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead) fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null) return;
            din.close();
        }
    }

    static void magic() throws IOException {
        reader = new FastReader();
        writer = new PrintWriter(System.out, true);
        int n = reader.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        for(int i=0;i<n;++i) {
            list.add(reader.nextInt());
        }
        int curr = 0, cnt = 0;
        StringBuilder ans = new StringBuilder();
        while(true) {
            if(list.size()==1) {
                if(list.getFirst()>curr) {
                    curr = list.getFirst();
                    cnt++;
                    ans.append("L");
                }
                break;
            }
            if(list.getFirst()>curr && list.getLast()>curr) {
                if(list.getFirst()<list.getLast()) {
                    curr = list.pollFirst();
                    ans.append("L");
                    cnt++;
                }
                else if(list.getLast()<list.getFirst()) {
                    curr = list.pollLast();
                    ans.append("R");
                    cnt++;
                }
                else {
                    int fromright = goFromRight(list);
                    int fromleft = goFromLeft(list);
                    if(fromleft>fromright) {
                        cnt+=fromleft;
                        for(int i=0;i<fromleft;++i) {
                            ans.append("L");
                        }
                    }
                    else {
                        cnt+=fromright;
                        for(int i=0;i<fromright;++i) {
                            ans.append("R");
                        }
                    }
                    break;
                }
            }
            else if(list.getFirst()>curr) {
                curr = list.pollFirst();
                cnt++;
                ans.append("L");
            }
            else if(list.getLast()>curr) {
                curr = list.pollLast();
                cnt++;
                ans.append("R");
            }
            else {
                break;
            }
        }
        writer.println(cnt);
        writer.println(ans);
    }
    static int goFromRight(LinkedList<Integer> list) {
        LinkedList<Integer> dup = new LinkedList<>();
        for(int e : list) {
            dup.add(e);
        }
        int curr = -1, cnt = 0;
        while (!dup.isEmpty()) {
            if(dup.getLast()>curr) {
                curr = dup.pollLast();
                cnt++;
            }
            else {
                break;
            }
        }
        return cnt;
    }
    static int goFromLeft(LinkedList<Integer> list) {
        LinkedList<Integer> dup = new LinkedList<>();
        for(int e : list) {
            dup.add(e);
        }
        int curr = -1, cnt = 0;
        while (!dup.isEmpty()) {
            if(dup.getFirst()>curr) {
                curr = dup.pollFirst();
                cnt++;
            }
            else {
                break;
            }
        }
        return cnt;
    }
}