#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
  int n;
  cin >> n;
  int A[n + 10];
  for (int i = 1; i <= n; i++) cin >> A[i];
  int temp = -1;
  int b = 1, e = n;
  while (b <= e) {
    if (A[b] < A[e]) {
      if (A[b] > temp) {
        temp = A[b];
        s += "L";
        b++;
      } else if (A[e] > temp) {
        temp = A[e];
        s += "R";
        e--;
      } else
        break;
    } else if (A[b] > A[e]) {
      if (A[e] > temp) {
        temp = A[e];
        s += "R";
        e--;
      } else if (A[b] > temp) {
        temp = A[b];
        s += "L";
        b++;
      } else
        break;
    } else {
      int l = 0, r = 0;
      if (A[b] <= temp) break;
      for (int i = b; i < e; i++) {
        if (A[i] < A[i + 1])
          l++;
        else
          break;
      }
      for (int i = e; i > b; i--) {
        if (A[i] < A[i - 1])
          r++;
        else
          break;
      }
      if (l > r) {
        temp = A[b];
        s += "L";
        b++;
      } else {
        temp = A[e];
        s += "R";
        e--;
      }
    }
  }
  cout << s.size() << endl;
  cout << s << endl;
  return 0;
}
