#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  int l = 0, r = n - 1;
  string answer = "";
  int cur = INT_MIN;
  while (l <= r) {
    if (a[l] > cur && a[r] > cur) {
      if (a[l] < a[r]) {
        answer += 'L';
        cur = a[l];
        l++;
      } else if (a[r] < a[l]) {
        answer += 'R';
        cur = a[r];
        r--;
      } else if (a[l] == a[r]) {
        if (l == r) {
          answer += 'L';
          l++;
          continue;
        }
        int i = l;
        int curs = cur;
        while (i < r) {
          if (a[i] > curs) {
            curs = a[i];
            i++;
          } else
            break;
        }
        i--;
        int first = i - l + 1;
        int j = r;
        curs = cur;
        while (j > l) {
          if (a[j] > curs) {
            curs = a[j];
            j--;
          } else
            break;
        }
        j++;
        int second = r - j + 1;
        if (first >= second) {
          while (first--) {
            answer += 'L';
          }
          l = i;
          cur = a[l];
        } else {
          while (second--) {
            answer += 'R';
          }
          r = j;
          cur = a[r];
        }
      }
    } else if (a[l] > cur) {
      answer += 'L';
      cur = a[l];
      l++;
    } else if (a[r] > cur) {
      answer += 'R';
      cur = a[r];
      r--;
    } else
      break;
  }
  cout << answer.size() << "\n";
  cout << answer << "\n";
  return 0;
}
