#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long f[n], b[n];
  f[n - 1] = 1, b[0] = 1;
  for (long long i = n - 2; i >= 0; i--) {
    if (a[i] < a[i + 1]) {
      f[i] = 1 + f[i + 1];
    } else {
      f[i] = 1;
    }
  }
  for (long long i = 1; i < n; i++) {
    if (a[i] < a[i - 1]) {
      b[i] = 1 + b[i - 1];
    } else {
      b[i] = 1;
    }
  }
  long long i = 0, j = n - 1;
  string s;
  long long last = 0;
  char lastch = 'L';
  long long lastn = f[i];
  long long prev = 0;
  while (i <= j) {
    if (a[i] > a[j]) {
      if (a[j] > prev) {
        prev = a[j];
        j--;
        s += "R";
      } else if (a[i] > prev) {
        prev = a[i];
        i++;
        s += "L";
      } else {
        break;
      }
    } else if (a[i] < a[j]) {
      if (a[i] > prev) {
        prev = a[i];
        i++;
        s += "L";
      } else if (a[j] > prev) {
        prev = a[j];
        j--;
        s += "R";
      } else {
        break;
      }
    } else {
      if (a[i] > prev) {
        if ((f[i]) > (b[j])) {
          prev = a[i];
          last = 1;
          lastch = 'L';
          lastn = f[i];
          break;
        } else {
          prev = a[j];
          last = 1;
          lastch = 'R';
          lastn = b[j];
          break;
        }
      } else {
        break;
      }
    }
  }
  if (last == 1) {
    for (long long i = 0; i < lastn; i++) {
      s += lastch;
    }
  }
  cout << s.length() << '\n';
  cout << s;
  return 0;
}
