#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  int max1 = 0, a[n + 1], left = 0, flag = 0, right = n - 1, count1 = 0,
      flagl = 0, flagr = 0;
  vector<char> vectl, vectr;
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<char> vect;
  while (left <= right) {
    if (a[left] == a[right] && max1 < a[left]) {
      int i = left;
      while (i < right && a[i] < a[i + 1]) {
        flagl = 1;
        vectl.push_back('L');
        i++;
      }
      vectl.push_back('L');
      i = right;
      while (i > left && a[i] < a[i - 1]) {
        flagr = 1;
        vectr.push_back('R');
        i--;
      }
      vectr.push_back('R');
      break;
    } else if (a[left] < a[right] && max1 < a[left]) {
      vect.push_back('L');
      max1 = a[left];
      left++;
    } else if (a[right] < a[left] && max1 < a[right]) {
      vect.push_back('R');
      max1 = a[right];
      right--;
    } else if (max1 < a[left]) {
      vect.push_back('L');
      max1 = a[left];
      left++;
    } else if (max1 < a[right]) {
      vect.push_back('R');
      max1 = a[right];
      right--;
    } else {
      break;
    }
    count1++;
  }
  if (vectl.size() > vectr.size()) {
    cout << count1 + vectl.size() << endl;
    for (int i = 0; i < count1; i++) cout << vect[i];
    for (int i = 0; i < vectl.size(); i++) cout << vectl[i];
  } else {
    cout << count1 + vectr.size() << endl;
    for (int i = 0; i < count1; i++) cout << vect[i];
    for (int i = 0; i < vectr.size(); i++) cout << vectr[i];
  }
  return 0;
}
