#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vi ar(N);
  for (auto& e : ar) {
    cin >> e;
  }
  int L = 0, R = N - 1;
  int cnt = 0;
  int cur = -1;
  string moves;
  while (L <= R) {
    if (ar[L] <= cur && ar[R] <= cur) break;
    if (ar[L] == ar[R]) {
      int l_size = 0, r_size = 0;
      int prev = cur;
      while (L < N && prev < ar[L]) {
        prev = ar[L];
        ++L;
        ++l_size;
      }
      prev = cur;
      while (R >= 0 && prev < ar[R]) {
        prev = ar[R];
        --R;
        ++r_size;
      }
      if (l_size < r_size) {
        moves += string(r_size, 'R');
      } else {
        moves += string(l_size, 'L');
      }
      break;
    } else {
      int candidate = max(ar[R], ar[L]);
      if (ar[L] > cur && candidate > ar[L]) candidate = ar[L];
      if (ar[R] > cur && candidate > ar[R]) candidate = ar[R];
      cur = candidate;
      if (cur == ar[L]) {
        ++L;
        moves.push_back('L');
      } else {
        --R;
        moves.push_back('R');
      }
      ++cnt;
    }
  }
  cout << moves.size() << endl;
  cout << moves << endl;
}
