#include <bits/stdc++.h>
using namespace std;
int n, a[200005], l = 1, r;
string ans;
int main() {
  cin >> n;
  r = n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int las = 0;
  while (l <= r) {
    if (a[l] > las && a[r] <= las) {
      las = a[l];
      l++;
      ans += "L";
    } else if (a[r] > las && a[l] <= las) {
      las = a[r];
      r--;
      ans += "R";
    } else if (a[l] <= las && a[r] <= las) {
      break;
    } else if (a[l] < a[r]) {
      ans += "L";
      las = a[l];
      l++;
    } else if (a[l] > a[r]) {
      ans += "R";
      las = a[r];
      r--;
    } else if (a[l] == a[r]) {
      int len1 = 1, len2 = 1;
      for (int i = l; i <= r; i++) {
        if (a[i] < a[i + 1])
          len1++;
        else
          break;
      }
      for (int i = r; i >= l; i--) {
        if (a[i] < a[i - 1])
          len2++;
        else
          break;
      }
      if (len1 > len2) {
        for (int i = 1; i <= len1; i++) {
          ans += "L";
        }
      } else {
        for (int i = 1; i <= len2; i++) {
          ans += "R";
        }
      }
      break;
    }
  }
  cout << ans.length() << endl;
  cout << ans;
  return 0;
}
