#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
void solve() {
  bool ok = true;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i += 1) cin >> a[i];
  ;
  int lst, l, r;
  lst = l = 0;
  r = n - 1;
  string ans;
  while (l <= r) {
    vector<pair<int, char>> cr;
    if (a[l] == a[r] && l != r) break;
    if (a[l] > lst) cr.push_back({a[l], 'L'});
    if (a[r] > lst) cr.push_back({a[r], 'R'});
    if ((int)cr.size() == 0) {
      ok = false;
      break;
    }
    sort(cr.begin(), cr.end());
    lst = cr[0].first;
    if (cr[0].second == 'L') {
      l++;
      ans += 'L';
    } else {
      r--;
      ans += 'R';
    }
  }
  if (ok == false || l > r) {
    cout << ans.size() << "\n" << ans << "\n";
    return;
  }
  int x, f, s;
  x = lst;
  f = s = 0;
  for (int i = l; i < r; i += 1) {
    if (a[i] <= x) break;
    f++;
    x = a[i];
  }
  x = lst;
  for (int i = r; i > l; i -= 1) {
    if (a[i] <= x) break;
    s++;
    x = a[i];
  }
  if (f > s)
    ans += string(f, 'L');
  else
    ans += string(s, 'R');
  cout << ans.size() << "\n" << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
