#include <bits/stdc++.h>
using namespace std;
int a[200009];
int L[200009];
int R[200009];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = n; i >= 1; i--) {
    if (a[i] < a[i + 1]) {
      R[i] = R[i + 1] + 1;
    } else {
      R[i] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (a[i] < a[i - 1]) {
      L[i] = L[i - 1] + 1;
    } else {
      L[i] = 1;
    }
  }
  int i = 1, j = n, ls = 0;
  vector<char> ans;
  while (1) {
    if (i == j) {
      if (a[i] > ls) ans.push_back('R');
      break;
    }
    if (a[i] < a[j]) {
      if (a[i] > ls) {
        ls = a[i];
        i++;
        ans.push_back('L');
      } else if (a[j] > ls) {
        ls = a[j];
        j--;
        ans.push_back('R');
      } else {
        break;
      }
    } else if (a[j] < a[i]) {
      if (a[j] > ls) {
        ls = a[j];
        j--;
        ans.push_back('R');
      } else if (a[i] > ls) {
        ls = a[i];
        i++;
        ans.push_back('L');
      } else {
        break;
      }
    } else {
      if (a[i] <= ls) {
        break;
      }
      int LL = L[j];
      int RR = R[i];
      char ch = 'L';
      if (LL >= RR) ch = 'R';
      int mx = max(LL, RR);
      if (mx > 0) {
        for (int i = 0; i < mx; i++) ans.push_back(ch);
      }
      break;
    }
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) cout << ans[i];
  return 0;
}
