#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int a[200005];
int ans[200005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int l = 1, r = n;
  int tmp = 0;
  int vew = 0;
  while (max(a[l], a[r]) > tmp && l <= r) {
    if (a[l] < a[r] && a[l] > tmp) {
      ans[vew++] = 0;
      tmp = a[l];
      l++;
      continue;
    }
    if (a[l] > a[r] && a[r] > tmp) {
      ans[vew++] = 1;
      tmp = a[r];
      r--;
      continue;
    }
    if (a[l] < a[r] && a[l] <= tmp) {
      ans[vew++] = 1;
      tmp = a[r];
      r--;
      continue;
    }
    if (a[l] > a[r] && a[r] <= tmp) {
      ans[vew++] = 0;
      tmp = a[l];
      l++;
      continue;
    }
    if (a[l] == a[r]) {
      int num1 = 0;
      int num2 = 0;
      for (int i = l; l <= r; i++) {
        if (a[i] > a[i - 1]) {
          num1++;
        } else
          break;
      }
      for (int i = r; i >= l; i--) {
        if (a[i] > a[i + 1]) {
          num2++;
        } else
          break;
      }
      if (num1 > num2) {
        while (num1--) {
          ans[vew++] = 0;
        }
      } else {
        while (num2--) {
          ans[vew++] = 1;
        }
      }
      break;
    }
    if (l == r) {
      if (a[l] > tmp) {
        ans[vew++] = 0;
        tmp = a[l];
        break;
      } else {
        break;
      }
    }
  }
  cout << vew << endl;
  for (int i = 0; i < vew; i++) {
    if (ans[i] == 0) {
      cout << "L";
    } else {
      cout << "R";
    }
  }
}
