#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
vector<string> ans;
deque<ll> a;
string s;
void dfs(ll last = -1) {
  if (a.empty()) {
    ans.push_back(s);
    return;
  }
  if (last < a.front() and a.front() < a.back()) {
    ll tmp = a.front();
    a.pop_front();
    s.push_back('L');
    dfs(tmp);
    a.push_front(tmp);
    s.pop_back();
    return;
  }
  if (last < a.back() and a.back() < a.front()) {
    ll tmp = a.back();
    a.pop_back();
    s.push_back('R');
    dfs(tmp);
    a.push_back(tmp);
    s.pop_back();
    return;
  }
  if (last < a.back() and a.back() == a.front()) {
    ll tmp = a.back();
    a.pop_back();
    s.push_back('R');
    dfs(tmp);
    a.push_back(tmp);
    s.pop_back();
    tmp = a.front();
    a.pop_front();
    s.push_back('L');
    dfs(tmp);
    a.push_front(tmp);
    s.pop_back();
    return;
  }
  bool in{};
  if (last < a.front()) {
    ll tmp = a.front();
    a.pop_front();
    s.push_back('L');
    dfs(tmp);
    a.push_front(tmp);
    s.pop_back();
    in = true;
  }
  if (last < a.back()) {
    ll tmp = a.back();
    a.pop_back();
    s.push_back('R');
    dfs(tmp);
    a.push_back(tmp);
    s.pop_back();
    in = true;
  }
  if (not in) {
    ans.push_back(s);
  }
}
int main() {
  cin >> n;
  for (ll i = 0; i < n; ++i) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  dfs();
  sort(ans.begin(), ans.end(),
       [](const string& a, const string& b) { return a.size() < b.size(); });
  auto& s = ans.back();
  cout << s.size() << endl << s << endl;
}
