#include <bits/stdc++.h>
using namespace std;
int v[200005];
string solve(int i, int j, int last) {
  if (i == j && v[i] > last) {
    return "L";
  } else if (v[i] <= last && v[j] <= last) {
    return "";
  } else {
    if (v[i] == v[j]) {
      string l = solve(i + 1, j, v[i]);
      string r = solve(i, j - 1, v[j]);
      if (l.size() >= r.size()) {
        return "L" + l;
      } else {
        return "R" + r;
      }
    } else {
      if (v[i] > last && (v[i] < v[j] || v[j] <= last)) {
        return "L" + solve(i + 1, j, v[i]);
      } else {
        return "R" + solve(i, j - 1, v[j]);
      }
    }
  }
}
int main(int argc, char const *argv[]) {
  cout.sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  string res = solve(0, n - 1, 0);
  cout << res.size() << endl;
  cout << res << endl;
  return 0;
}
