#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int xinc[] = {0, 0, 1, -1};
const int yinc[] = {1, -1, 0, 0};
const long double PI = acos(-1.0);
int n, a[N];
deque<int> q;
string ans1, ans2;
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i], q.push_back(a[i]);
  int last = 0;
  while (!q.empty()) {
    int frn = q.front();
    int bck = q.back();
    if (frn < bck) {
      if (frn > last) {
        q.pop_front();
        ans1 += 'L';
        ans2 += 'L';
        last = frn;
      } else if (bck > last) {
        q.pop_back();
        ans1 += 'R';
        ans2 += 'R';
        last = bck;
      } else
        break;
    } else if (frn > bck) {
      if (bck > last) {
        q.pop_back();
        ans1 += 'R';
        ans2 += 'R';
        last = bck;
      } else if (frn > last) {
        q.pop_front();
        ans1 += 'L';
        ans2 += 'L';
        last = frn;
      } else
        break;
    } else {
      deque<int> q1, q2;
      q1 = q, q2 = q;
      int l1 = last, l2 = last;
      while (!q1.empty() && q1.front() > l1)
        l1 = q1.front(), q1.pop_front(), ans1 += 'L';
      while (!q2.empty() && q2.back() > l2)
        l2 = q2.back(), q2.pop_back(), ans2 += 'R';
      break;
    }
  }
  if (ans1.size() > ans2.size()) {
    cout << ans1.size() << '\n';
    cout << ans1 << '\n';
  } else {
    cout << ans2.size() << '\n';
    cout << ans2 << '\n';
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  t = 1;
  while (t--) solve();
  return 0;
}
