#include <bits/stdc++.h>
std::string myRec(long left_pos, long right_pos, long previousElement,
                  std::vector<long>& elements) {
  if (left_pos > right_pos) {
    return "";
  }
  if ((elements[left_pos] < elements[right_pos] &&
       elements[left_pos] > previousElement) ||
      (elements[right_pos] <= previousElement &&
       previousElement < elements[left_pos])) {
    previousElement = elements[left_pos++];
    return 'L' + myRec(left_pos, right_pos, previousElement, elements);
  } else if ((elements[right_pos] < elements[left_pos] &&
              elements[right_pos] > previousElement) ||
             (elements[left_pos] <= previousElement &&
              previousElement < elements[right_pos])) {
    previousElement = elements[right_pos--];
    return 'R' + myRec(left_pos, right_pos, previousElement, elements);
  } else if ((elements[right_pos] == elements[left_pos]) &&
             (elements[right_pos] > previousElement)) {
    previousElement = elements[left_pos];
    std::string output1;
    std::string output2;
    output1 = myRec(left_pos + 1, right_pos, previousElement, elements);
    output2 = myRec(left_pos, right_pos - 1, previousElement, elements);
    if (output1.length() > output2.length()) {
      return 'L' + output1;
    } else
      return 'R' + output2;
  }
  return "";
}
int main() {
  long n;
  scanf("%ld", &n);
  std::vector<long> elements(n);
  for (long i = 0; i < n; i++) scanf("%ld", &elements[i]);
  std::string output = myRec(0, n - 1, 0, elements);
  printf("%u \n", output.length());
  printf("%s \n", output.c_str());
  return 0;
}
