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.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import static java.lang.Math.*;
public class Main
{
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

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

        public Reader(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[64]; // line length
            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 class Pair implements Comparable<Pair> {
        int x,y,ind;

        public Pair(int x, int y,int ind) {
            this.x = x;
            this.y = y;
            this.ind=ind;
        }
        public int compareTo(Pair o) {
            if(x!=o.x)
                return x-o.x;
            return this.y - o.y;
        }
        public int hashCode() {
            return (int)(1L*1000000000*x + y)%1000000007;
        }
        public boolean equals(Object o) {
            if(o instanceof Pair) {
                Pair other = (Pair)o;
                return other.hashCode()==this.hashCode();
            }
            else return false;
        }
        public String toString(){
            return x+" "+y;
        }
    }
    static Scanner sc = new Scanner(System.in);
    //static Reader sc = new Reader();
    static StringBuilder sb = new StringBuilder();
    static PrintWriter pw = new PrintWriter(System.out,true);
    public static void main(String[] args) throws IOException {
        //Code start from here
        int n = sc.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        for(int i=0;i<n;i++)
            list.add(sc.nextInt());
        int first= list.peekFirst(),last = list.peekLast(),prev =0,cnt=0;
        while(!list.isEmpty()) {
            if(first==last) {
                if(first>prev) {
                    int val1 = left_count(list), val2 = right_count(list);
                    if (val1 > val2) {
                        add(val1, "L");
                        cnt+=val1;
                    }else {
                        add(val2, "R");
                        cnt += val2;
                    }
                }
                break;
            }
            if(first>prev && last>prev) {
                if(first<last) {
                    sb.append("L");
                    prev = list.pollFirst();
                    first = list.peekFirst();
                }
                else if(last<first) {
                    sb.append("R");
                    prev = list.pollLast();
                    last = list.peekLast();
                }
                cnt++;
            }
            else if(first>prev) {
                int val = left_count(list);
                cnt+=val;
                add(val,"L");
                break;
            } else if(last>prev) {
                int val = right_count(list);
                cnt+=val;
                add(val,"R");
                break;
            } else
                break;
        }
        System.out.println(cnt);
        pw.println(sb);
        pw.flush();
        pw.close();
    }
    static int right_count(LinkedList<Integer> l) {
        LinkedList<Integer> local = new LinkedList<>();
        for(int i : l)
            local.add(i);
        int cnt=1,x = local.pollLast();
        while(!local.isEmpty()) {
            if(local.peekLast()>x) {
                cnt++;
                x= local.pollLast();
            } else
                return cnt;
        }
        return cnt;
    }
    static int left_count(LinkedList<Integer> l) {
        LinkedList<Integer> local = new LinkedList<>();
        for(int i : l)
            local.add(i);
        int cnt=1,x = local.pollFirst();
        while(!local.isEmpty()) {
            if(local.peekFirst()>x) {
                cnt++;
                x= local.pollFirst();
            } else
                return cnt;
        }
        return cnt;
    }
    static void add(int val,String str) {
        while(val-->0)
            sb.append(str);
    }
}