#include <bits/stdc++.h>
using namespace std;
int ara[200002];
queue<char> q;
int main() {
  int n, i, l, r, j, res, cnt, cnt1;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &ara[i]);
  }
  res = -1;
  l = 0;
  r = n - 1;
  while (l <= r) {
    if (ara[l] < ara[r] && res < ara[l]) {
      q.push('L');
      res = ara[l];
      l++;
    } else if (ara[l] > ara[r] && res < ara[r]) {
      q.push('R');
      res = ara[r];
      r--;
    } else if (ara[l] == ara[r] && ara[l] > res) {
      j = l;
      i = l + 1;
      cnt = 1;
      while (i < r && ara[j] < ara[i]) {
        cnt++;
        j++;
        i++;
      }
      j = r;
      i = r - 1;
      cnt1 = 1;
      while (i > l && ara[j] < ara[i]) {
        cnt1++;
        j--;
        i--;
      }
      if (cnt > cnt1) {
        while (cnt--) q.push('L');
      } else {
        while (cnt1--) q.push('R');
      }
      break;
    } else if (res < ara[r]) {
      res = ara[r];
      q.push('R');
      r--;
    } else if (res < ara[l]) {
      res = ara[l];
      q.push('L');
      l++;
    } else
      break;
  }
  cout << q.size() << endl;
  while (!q.empty()) {
    cout << q.front();
    q.pop();
  }
  cout << endl;
  return 0;
}
