#include <bits/stdc++.h>
using namespace std;
int Data[(int)3e5 + 10], n, cnt = 0;
vector<int> ans;
vector<char> Path;
int func(int l, int r, int just) {
  int Last = just;
  int CntLeft = 0;
  for (int i = l; i < r; i++) {
    if (Data[i] <= Last) break;
    CntLeft++;
    Last = Data[i];
  }
  Last = just;
  int CntRight = 0;
  for (int i = r; i > l; i--) {
    if (Data[i] <= Last) break;
    CntRight++;
    Last = Data[i];
  }
  Last = just;
  if (CntRight > CntLeft) {
    for (int i = r; i > l; i--) {
      if (Data[i] <= Last) break;
      Last = Data[i];
      Path.push_back('R');
    }
    return CntRight;
  } else {
    for (int i = l; i < r; i++) {
      if (Data[i] <= Last) break;
      Last = Data[i];
      Path.push_back('L');
    }
    return CntLeft;
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> Data[i];
  }
  int r = n, l = 1;
  while (1) {
    if (cnt == n) break;
    if (Data[l] == Data[r] and l != r) {
      int just;
      if (ans.size() == 0)
        just = -1;
      else
        just = ans.back();
      cnt += func(l, r, just);
      break;
    }
    if (ans.size() == 0) {
      if (Data[l] < Data[r]) {
        Path.push_back('L');
        ans.push_back(Data[l]);
        l++;
      } else {
        Path.push_back('R');
        ans.push_back(Data[r]);
        r--;
      }
      cnt++;
      continue;
    }
    if (ans.back() >= max(Data[l], Data[r])) break;
    if (Data[l] < Data[r] and Data[l] > ans.back()) {
      Path.push_back('L');
      ans.push_back(Data[l]);
      l++;
    } else if (Data[r] > ans.back()) {
      Path.push_back('R');
      ans.push_back(Data[r]);
      r--;
    } else {
      Path.push_back('L');
      ans.push_back(Data[l]);
      l++;
    }
    cnt++;
  }
  cout << cnt << endl;
  for (int i = 0; i < (int)Path.size(); i++) cout << Path[i];
  cout << endl;
  return 0;
}
