#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  string s = "";
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int l = 0, r = n - 1;
  long long int f = 0;
  while (l <= r) {
    long long int maxi = max(a[l], a[r]);
    if (maxi <= f) break;
    if (a[l] > f && a[l] < a[r]) {
      f = a[l];
      l++;
      s += "L";
    } else if (f < a[r] && a[r] < a[l]) {
      f = a[r];
      r--;
      s += "R";
    } else if (a[l] == a[r]) {
      long long int a1 = 0, b1 = 0;
      for (long long int i = l + 1; i <= r; i++) {
        if (a[i] > a[i - 1])
          a1++;
        else
          break;
      }
      for (long long int j = r - 1; j >= l; j--) {
        if (a[j] > a[j + 1])
          b1++;
        else
          break;
      }
      if (a1 > b1) {
        s += "L";
        f = a[l];
        l++;
      } else {
        s += "R";
        f = a[r];
        r--;
      }
    } else if (a[l] > f) {
      f = a[l];
      l++;
      s += "L";
    } else {
      f = a[r];
      r--;
      s += "R";
    }
  }
  cout << s.size() << "\n";
  cout << s;
  return 0;
}
