#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) scanf("%d", arr + i);
  int i = 0, j = n - 1, min = 0, c = 0;
  char str[n + 1];
  while (i < n && arr[i] > min || j > -1 && arr[j] > min) {
    if (arr[i] < arr[j] && arr[i] > min || arr[j] <= min) {
      min = arr[i];
      i++;
      str[c] = 'L';
    } else if (arr[j] < arr[i] && arr[j] > min || arr[i] <= min) {
      min = arr[j];
      j--;
      str[c] = 'R';
    } else {
      int c1 = 0, c2 = 0;
      while (arr[i + c1] < arr[i + c1 + 1]) c1++;
      while (arr[j - c2] < arr[j - c2 - 1]) c2++;
      if (c1 > c2) {
        min = arr[i];
        i++;
        str[c] = 'L';
      } else {
        min = arr[j];
        j--;
        str[c] = 'R';
      }
    }
    c++;
  }
  str[c] = 0;
  printf("%d\n%s", c, str);
}
