#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e18 + 7;
const long long N = 6e6 + 5;
long long a[N], b[N];
int main() {
  long long i, j, k, l = 0;
  long long n, m, t;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  i = 0;
  j = n - 1;
  t = min(a[i], a[j]) - 1;
  string s;
  while (1) {
    if (i == j) {
      if (a[i] > t) b[l++] = a[i], s += "R";
      break;
    }
    if (a[i] > a[j]) {
      if (a[j] > t)
        b[l++] = a[j], t = a[j], j--, s += 'R';
      else if (a[i] > t)
        b[l++] = a[i], t = a[i], i++, s += 'L';
      else
        break;
    } else if (a[i] < a[j]) {
      if (a[i] > t)
        b[l++] = a[i], t = a[i], i++, s += "L";
      else if (a[j] > t)
        b[l++] = a[j], t = a[j], j--, s += "R";
      else
        break;
    } else {
      if (a[i] <= t) break;
      long long ci = 0, cj = 0;
      for (k = i + 1; k < j; k++) {
        if (a[k] > a[k - 1])
          ci++;
        else
          break;
      }
      for (k = j - 1; k > i; k--) {
        if (a[k] > a[k + 1])
          cj++;
        else
          break;
      }
      if (ci >= cj) {
        for (k = i; k <= i + ci; k++) b[l++] = a[k], s += "L";
      } else {
        for (k = j; k >= j - cj; k--) b[l++] = a[k], s += "R";
      }
      break;
    }
  }
  cout << l << endl;
  for (i = 0; i < l; i++) cout << s[i];
  putchar(10);
  return 0;
}
