#include <bits/stdc++.h>
using namespace std;
int n;
deque<int> a;
string ans;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int t;
  for (long long i = (0); i < (n); ++i) {
    cin >> t;
    a.push_back(t);
  }
  t = 0;
  while (!a.empty()) {
    if (a.front() < a.back()) {
      if (a.front() > t) {
        t = a.front();
        a.pop_front();
        ans.push_back('L');
      } else if (a.back() > t) {
        t = a.back();
        a.pop_back();
        ans.push_back('R');
      } else
        break;
    } else if (a.front() > a.back()) {
      if (a.back() > t) {
        t = a.back();
        a.pop_back();
        ans.push_back('R');
      } else if (a.front() > t) {
        t = a.front();
        a.pop_front();
        ans.push_back('L');
      } else
        break;
    } else {
      if (a.front() <= t) break;
      if (a.size() <= 2) {
        ans.push_back('L');
        break;
      }
      int ct1 = 0, ct2 = 0;
      for (long long i = (0); i < (a.size() - 1); ++i) {
        if (a[i] < a[i + 1])
          ct1++;
        else {
          ct1++;
          break;
        }
      }
      for (long long i = (a.size() - 1); i >= (1); --i) {
        if (a[i] < a[i - 1])
          ct2++;
        else {
          ct2++;
          break;
        }
      }
      if (ct1 > ct2) {
        for (long long i = (0); i < (ct1); ++i) ans.push_back('L');
      } else {
        for (long long i = (0); i < (ct2); ++i) ans.push_back('R');
      }
      break;
    }
  }
  cout << ans.length() << endl;
  cout << ans << endl;
  return 0;
}
