#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 4;
int n, pf[MAX], sf[MAX], a[MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  cin >> n;
  for (int i = 0, x; i < n; i++) cin >> a[i];
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] < a[i + 1])
      pf[i] = pf[i + 1] + 1;
    else
      pf[i] = 0;
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] > a[i])
      sf[i] = sf[i - 1] + 1;
    else
      sf[i] = 0;
  }
  string ans = "";
  int prv = 0, lo = 0, hi = n - 1;
  while (lo <= hi) {
    int mx = max(a[lo], a[hi]);
    int mn = min(a[lo], a[hi]);
    if (mx <= prv) break;
    if (a[lo] == a[hi]) {
      if (pf[lo] > sf[hi]) {
        ans.push_back('L');
        prv = a[lo];
        lo++;
      } else {
        ans.push_back('R');
        prv = a[hi];
        hi--;
      }
      continue;
    }
    if (a[lo] < a[hi]) {
      if (mn > prv) {
        ans.push_back('L');
        prv = a[lo];
        lo++;
      } else {
        ans.push_back('R');
        prv = a[hi];
        hi--;
      }
    } else {
      if (mn > prv) {
        ans.push_back('R');
        prv = a[hi];
        hi--;
      } else {
        ans.push_back('L');
        prv = a[lo];
        lo++;
      }
    }
  }
  cout << ans.size() << '\n';
  cout << ans << '\n';
}
