#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, k;
  cin >> n;
  int arr[n];
  vector<char> vec;
  for (i = 0; i < n; i++) cin >> arr[i];
  int first = 0, last = n - 1, run = 0;
  while (first <= last) {
    bool chole = false;
    if (arr[first] > arr[last]) {
      if (arr[last] > run) {
        vec.push_back('R');
        run = arr[last];
        last--;
        chole = true;
      } else if (arr[first] > run) {
        vec.push_back('L');
        run = arr[first];
        first++;
        chole = true;
      }
    } else if (arr[last] > arr[first]) {
      if (arr[first] > run) {
        vec.push_back('L');
        run = arr[first];
        first++;
        chole = true;
      } else if (arr[last] > run) {
        vec.push_back('R');
        run = arr[last];
        last--;
        chole = true;
      }
    } else if ((arr[last] = arr[first]) && arr[first] > run) {
      int fst = 0, lst = 0;
      ;
      for (i = first + 1; i <= last; i++) {
        if (arr[i] > arr[i - 1])
          fst++;
        else
          break;
      }
      for (i = last - 1; i >= first; i--) {
        if (arr[i] > arr[i + 1])
          lst++;
        else
          break;
      }
      if (fst > lst) {
        vec.push_back('L');
        run = arr[first];
        first++;
        chole = true;
      } else {
        vec.push_back('R');
        run = arr[last];
        last--;
        chole = true;
      }
    }
    if (!chole) break;
  }
  cout << vec.size() << endl;
  for (i = 0; i < vec.size(); i++) cout << vec[i];
  return 0;
}
