#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int a[N];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int cur = 0;
  string ans;
  int l = 0, r = n - 1;
  while (l <= r) {
    if (max(a[l], a[r]) <= cur) break;
    if (a[l] <= cur) {
      ans.push_back('R');
      cur = a[r--];
    } else if (a[r] <= cur) {
      ans.push_back('L');
      cur = a[l++];
    } else if (a[l] < a[r]) {
      ans.push_back('L');
      cur = a[l++];
    } else if (a[r] < a[l]) {
      ans.push_back('R');
      cur = a[r--];
    } else {
      string s1 = "L";
      int p = l;
      while (p <= r && a[p] < a[p + 1]) {
        s1.push_back('L');
        p++;
      }
      string s2 = "R";
      p = r;
      while (p >= l && a[p] < a[p - 1]) {
        s2.push_back('R');
        p--;
      }
      if (s1.size() > s2.size())
        ans += s1;
      else
        ans += s2;
      break;
    }
  }
  cout << ans.size() << endl;
  cout << ans << endl;
  return 0;
}
