#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
long long mod = 998244353;
int vist[N] = {};
int id = 0;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  deque<int> q;
  int mn = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    q.push_back(x);
  }
  string ans;
  while (q.size()) {
    if (max(q.front(), q.back()) <= mn) break;
    if (q.front() != q.back()) {
      if (q.front() <= mn) {
        mn = max(mn, q.back());
        q.pop_back();
        ans += 'R';
      } else if (q.back() <= mn) {
        mn = max(mn, q.front());
        q.pop_front();
        ans += 'L';
      } else {
        if (q.back() < q.front()) {
          mn = max(mn, q.back());
          q.pop_back();
          ans += 'R';
        } else {
          mn = max(mn, q.front());
          q.pop_front();
          ans += 'L';
        }
      }
    } else {
      string ans1 = "L", ans2 = "R";
      for (int i = 1; i < q.size(); i++) {
        if (q[i] > q[i - 1])
          ans1 += 'L';
        else
          break;
      }
      for (int i = q.size() - 2; i >= 0; i--) {
        if (q[i] > q[i + 1])
          ans2 += 'R';
        else
          break;
      }
      if (ans1.size() > ans2.size())
        ans += ans1;
      else
        ans += ans2;
      break;
    }
  }
  cout << ans.size() << "\n";
  cout << ans;
  return 0;
}
