#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int x = 0; x < n; x++) {
    cin >> arr[x];
  }
  int i = 0;
  int j = n - 1;
  int curr = -1;
  string ans = "";
  while (1) {
    if (i == j) {
      if (arr[i] > curr) {
        ans.append("L");
      }
      break;
    }
    if (arr[i] <= curr && arr[j] <= curr) {
      break;
    }
    if (arr[i] > curr && arr[j] > curr) {
      if (arr[i] < arr[j]) {
        ans.append("L");
        curr = arr[i];
        i += 1;
      } else if (arr[j] < arr[i]) {
        ans.append("R");
        curr = arr[j];
        j -= 1;
      } else {
        int cnt_left = 1;
        int cnt_right = 1;
        int i_temp = i;
        int j_temp = j;
        while (i_temp < j && arr[i_temp + 1] > arr[i_temp]) {
          i_temp += 1;
          cnt_left += 1;
        }
        while (i < j_temp && arr[j_temp - 1] > arr[j_temp]) {
          j_temp -= 1;
          cnt_right += 1;
        }
        if (cnt_left > cnt_right) {
          ans.append("L");
          curr = arr[i];
          i += 1;
        } else {
          ans.append("R");
          curr = arr[j];
          j -= 1;
        }
      }
    } else {
      if (arr[i] > curr) {
        ans.append("L");
        curr = arr[i];
        i += 1;
      } else if (arr[j] > curr) {
        ans.append("R");
        curr = arr[j];
        j -= 1;
      }
    }
  }
  cout << ans.length() << endl;
  cout << ans << endl;
}
