#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
void solve() {
  int n;
  cin >> n;
  int a[n];
  string s;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 0, r = n - 1, top = 0;
  while (l <= r) {
    vector<pair<int, char>> pair;
    if (top < a[l]) pair.push_back(make_pair(a[l], 'L'));
    if (top < a[r]) pair.push_back(make_pair(a[r], 'R'));
    sort(pair.begin(), pair.end());
    if (pair.size() == 2 && pair[0].first != pair[1].first) {
      pair.pop_back();
    }
    if (pair.size() == 1) {
      if (pair[0].second == 'L') {
        s += 'L';
        top = a[l];
        ++l;
      } else {
        s += 'R';
        top = a[r];
        r--;
      }
    } else if (pair.size() == 2) {
      int cntl = 1, cntr = 1;
      int m = l, n = r;
      while (a[m] < a[m + 1] && m < n) {
        m++;
        cntl++;
      }
      while (a[n] < a[n - 1] && m < n) {
        n--;
        cntr++;
      }
      if (cntl >= cntr) {
        s += 'L';
        top = a[l];
        ++l;
      } else {
        s += 'R';
        top = a[r];
        r--;
      }
    } else
      break;
  }
  cout << s.length() << endl;
  cout << s << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
