#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, i, l, r, last = 0;
  string s;
  cin >> n;
  vector<int> v(n);
  for (i = 0; i < n; i++) cin >> v[i];
  l = 0, r = n - 1;
  bool ok = true;
  while (v[l] != v[r]) {
    if (v[l] < v[r] && v[l] > last) {
      s.push_back('L');
      last = v[l++];
    } else if (v[r] < v[l] && v[r] > last) {
      s.push_back('R');
      last = v[r--];
    } else if (v[l] > v[r] && v[l] > last) {
      s.push_back('L');
      last = v[l++];
    } else if (v[r] > v[l] && v[r] > last) {
      s.push_back('R');
      last = v[r--];
    } else {
      ok = false;
      break;
    }
  }
  if (v[l] == v[r] && v[l] <= last) ok = false;
  if (!ok) {
    cout << s.size() << endl;
    cout << s << endl;
    return 0;
  }
  int x, y, tlast;
  x = l, y = r, tlast = last;
  string a, b;
  while (x <= y && v[x] > tlast) {
    a.push_back('L');
    tlast = v[x++];
  }
  x = l, y = r, tlast = last;
  while (y >= x && v[y] > tlast) {
    b.push_back('R');
    tlast = v[y--];
  }
  if (a.size() > b.size())
    s += a;
  else
    s += b;
  cout << s.size() << endl;
  cout << s << endl;
}
