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.
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.SortedSet;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

/**
 * #
 *
 * @author pttrung
 */
public class C1_Round_555_Div3 {

    public static long MOD = 998244353;
    static long[][][] dp;

    public static void main(String[] args) throws FileNotFoundException {
        // PrintWriter out = new PrintWriter(new FileOutputStream(new File(
        // "output.txt")));
        PrintWriter out = new PrintWriter(System.out);
        Scanner in = new Scanner();
        int n = in.nextInt();
        int[] data = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = in.nextInt();

        }
        int st = 0;
        int ed = n - 1;
        int last = 0;
        StringBuilder builder = new StringBuilder();
        while (st <= ed && (data[st] > last || data[ed] > last)) {
            if (data[st] < data[ed]) {
                if (data[st] > last) {
                    last = data[st++];
                    builder.append("L");
                } else {
                    last = data[ed--];
                    builder.append("R");
                }
            } else if (data[st] > data[ed]) {
                if (data[ed] > last) {
                    last = data[ed--];
                    builder.append("R");
                } else {
                    last = data[st++];
                    builder.append("L");
                }
            } else {

                int a = 0;
                int v = last;
                for (int i = st; i <= ed; i++) {
                    if (data[i] > v) {
                        a++;
                        v = data[i];
                    } else {
                        break;
                    }
                }
                int b = 0;
                v = last;
                for (int i = ed; i >= st; i--) {
                    if (data[i] > v) {
                        b++;
                        v = data[i];
                    } else {
                        break;
                    }
                }
                //System.out.println(a + " " + b);
                if (a > b) {
                    for (int i = st; i <= ed; i++) {
                        if (data[i] > last) {
                            last = data[i];
                            builder.append("L");
                        } else {
                            break;
                        }
                    }
                } else {
                    for (int i = ed; i >= st; i--) {
                        if (data[i] > last) {
                            last = data[i];
                            builder.append("R");
                        }else{
                            break;
                        }
                    }
                }
                break;
            }
        }
        out.println(builder.length());
        out.println(builder.toString());


        out.close();
    }

    static class Node {
        int l, r;
        int v, index;
        Node left, right;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }

    static void update(int v, int index, Node node) {
        if (index > node.r || index < node.l) {
            return;
        }
        if (index == node.l && index == node.r) {
            node.v = v;
            node.index = index;
            return;
        }
        int mid = (node.r + node.l) / 2;
        if (node.left == null) {
            node.left = new Node(node.l, mid);
            node.right = new Node(mid + 1, node.r);
        }
        update(v, index, node.left);
        update(v, index, node.right);
        if (node.left.v > node.right.v) {
            node.v = node.left.v;
            node.index = node.left.index;
        } else {
            node.v = node.right.v;
            node.index = node.right.index;
        }

    }

    static Point get(int index, Node node) {
        if (node.l > index) {
            return new Point(0, 0);
        }
        if (node.r <= index) {
            return new Point(node.index, node.v);
        }
        int mid = (node.r + node.l) / 2;
        if (node.left == null) {
            node.left = new Node(node.l, mid);
            node.right = new Node(mid + 1, node.r);
        }
        Point a = get(index, node.left);
        Point b = get(index, node.right);
        if (a.y > b.y) {
            return a;
        }
        return b;

    }


    public static int[] KMP(String val) {
        int i = 0;
        int j = -1;
        int[] result = new int[val.length() + 1];
        result[0] = -1;
        while (i < val.length()) {
            while (j >= 0 && val.charAt(j) != val.charAt(i)) {
                j = result[j];
            }
            j++;
            i++;
            result[i] = j;
        }
        return result;

    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static int digit(long n) {
        int result = 0;
        while (n > 0) {
            n /= 10;
            result++;
        }
        return result;
    }

    public static double dist(long a, long b, long x, long y) {
        double val = (b - a) * (b - a) + (x - y) * (x - y);
        val = Math.sqrt(val);
        double other = x * x + a * a;
        other = Math.sqrt(other);
        return val + other;

    }

    public static class Point implements Comparable<Point> {

        int x, y;

        public Point(int start, int end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = 47 * hash + this.x;
            hash = 47 * hash + this.y;
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Integer.compare(x, o.x);
        }
    }

    public static class FT {

        long[] data;

        FT(int n) {
            data = new long[n];
        }

        public void update(int index, long value) {
            while (index < data.length) {
                data[index] += value;
                index += (index & (-index));
            }
        }

        public long get(int index) {
            long result = 0;
            while (index > 0) {
                result += data[index];
                index -= (index & (-index));
            }
            return result;

        }
    }

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

    public static long pow(long a, long b, long MOD) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2, MOD);
        if (b % 2 == 0) {
            return val * val % MOD;
        } else {
            return val * (val * a % MOD) % MOD;

        }
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));
        }

        public String next() {

            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}