#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int p1 = 0, p2 = n - 1, last = -1;
  string ans = "", s1, s2;
  while (p2 >= p1) {
    if (a[p1] <= last && a[p2] <= last)
      break;
    else if (a[p1] == a[p2]) {
      s1 = s2 = ans;
      int t = last;
      for (int i = p1; i < p2; i++) {
        if (a[i] > last) {
          last = a[i];
          s1 += "L";
        } else
          break;
      }
      last = t;
      for (int i = p2; i >= p1; i--) {
        if (a[i] > last) {
          last = a[i];
          s2 += "R";
        } else
          break;
      }
      if (s1.length() > s2.length())
        ans = s1;
      else
        ans = s2;
      break;
    } else if (a[p1] > last && a[p2] > last) {
      if (a[p1] > a[p2]) {
        last = a[p2];
        p2--;
        ans += "R";
      } else {
        last = a[p1];
        p1++;
        ans += "L";
      }
    } else if (a[p1] > last) {
      last = a[p1];
      p1++;
      ans += "L";
    } else {
      last = a[p2];
      p2--;
      ans += "R";
    }
  }
  cout << ans.length() << '\n';
  cout << ans << '\n';
}
