#include <bits/stdc++.h>
long long p[2750131 + 5];
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long left = 0, right = n - 1, past = 0;
  string s = "";
  long long flag = 1;
  while (left < right && flag) {
    if (a[left] < a[right]) {
      if (a[left] > past) {
        s += 'L';
        past = a[left];
        left++;
      } else if (a[right] > past) {
        s += 'R';
        past = a[right];
        right--;
      } else {
        flag = 0;
      }
    } else if (a[right] < a[left]) {
      if (a[right] > past) {
        s += 'R';
        past = a[right];
        right--;
      } else if (a[left] > past) {
        s += 'L';
        past = a[left];
        left++;
      } else {
        flag = 0;
      }
    } else {
      if (a[left] <= past) {
        flag = 0;
        continue;
      }
      past = a[left];
      left++;
      long long sum1 = 1;
      while (a[left] > past) {
        sum1++;
        past = a[left];
        left++;
      }
      past = a[right];
      right--;
      long long sum2 = 1;
      while (a[right] > past) {
        sum2++;
        past = a[right];
        right--;
      }
      if (sum1 > sum2) {
        while (sum1--) {
          s += 'L';
        }
      } else {
        while (sum2--) {
          s += 'R';
        }
      }
      flag = 0;
    }
  }
  if (left == right && flag && a[left] > past) {
    s += 'L';
  }
  cout << s.size() << '\n';
  cout << s << '\n';
  return 0;
}
