#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int a[2 * 100000 + 1];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i += 1) cin >> a[i];
  int i = 0;
  int j = n - 1;
  string moves;
  int min = -1;
  while (1) {
    if (a[i] < a[j] && a[i] > min) {
      moves += 'L';
      min = a[i++];
    } else if (a[j] < a[i] && a[j] > min) {
      moves += 'R';
      min = a[j--];
    } else if (a[i] > min && a[j] <= min) {
      moves += 'L';
      min = a[i++];
    } else if (a[j] > min && a[i] <= min) {
      moves += 'R';
      min = a[j--];
    } else if (i == j && a[j] > min) {
      moves += 'L';
      break;
    } else if (a[i] == a[j] && a[i] > min) {
      int lmoves = 1;
      for (int k = i + 1; k <= j; k++) {
        if (a[k] > a[k - 1])
          lmoves++;
        else
          break;
      }
      int rmoves = 1;
      for (int k = j - 1; k >= i; k--) {
        if (a[k] > a[k + 1])
          rmoves++;
        else
          break;
      }
      if (lmoves > rmoves) {
        while (lmoves--) moves += 'L';
      } else
        while (rmoves--) moves += 'R';
      break;
    } else {
      break;
    }
  }
  cout << moves.size() << "\n" << moves;
}
