#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &a : v) cin >> a;
  int p1 = 0, p2 = n - 1;
  string ans;
  int cur = -1;
  while (true) {
    if (p2 < p1) break;
    int l = v[p1], r = v[p2];
    int mn = min(l, r);
    int mx = max(l, r);
    if (l <= cur && r <= cur) {
      break;
    } else if (mn <= cur && mx > cur) {
      if (l == mx) {
        ans += "L";
        p1++;
        cur = l;
      } else {
        ans += "R";
        p2--;
        cur = r;
      }
    } else {
      if (l != r) {
        if (l == mn) {
          ans += "L";
          p1++;
          cur = l;
        } else {
          ans += "R";
          p2--;
          cur = r;
        }
      } else {
        int lc = 0;
        for (int i = p1 + 1; i < p2; i++) {
          if (v[i] > v[i - 1]) {
            lc++;
          } else {
            break;
          }
        }
        int rc = 0;
        for (int i = p2 - 1; i > p1; i--) {
          if (v[i] > v[i + 1]) {
            rc++;
          } else {
            break;
          }
        }
        if (lc > rc) {
          for (int i = 0; i < lc + 1; i++) ans += "L";
          goto l1;
        } else {
          for (int i = 0; i < rc + 1; i++) ans += "R";
          goto l1;
        }
      }
    }
  }
l1:;
  cout << ans.size() << endl;
  cout << ans << endl;
  return 0;
}
