#include <bits/stdc++.h>
using namespace std;
int n;
int a[200004];
int main() {
  cin >> n;
  deque<pair<int, int> > q;
  for (int i = 0; i < n; i++) cin >> a[i], q.push_back({a[i], i});
  vector<int> v;
  vector<char> v2;
  char w = '0';
  while (!q.empty()) {
    if (w == 'R') {
      while (true) {
        if (q.empty()) break;
        if (v.size() && q.back().first <= v[v.size() - 1]) {
          break;
        }
        v.push_back(q.back().first);
        v2.push_back('R');
        q.pop_back();
      }
      break;
    }
    if (w == 'L') {
      while (true) {
        if (q.empty()) break;
        if (v.size() && q.front().first <= v[v.size() - 1]) {
          break;
        }
        v.push_back(q.front().first);
        v2.push_back('L');
        q.pop_front();
      }
      break;
    }
    if (v.size() == 0) {
      if (q.front().first < q.back().first)
        v.push_back(q.front().first), v2.push_back('L'), q.pop_front();
      else if (q.front().first > q.back().first)
        v.push_back(q.back().first), v2.push_back('R'), q.pop_back();
      else {
        int c = 0, c2 = 0;
        for (int i = q.back().second; i > q.front().second; i--) {
          if (a[i] >= a[i - 1]) break;
          c++;
        }
        for (int i = q.front().second; i < q.back().second; i++) {
          if (a[i] >= a[i + 1]) break;
          c2++;
        }
        if (c > c2)
          w = 'R';
        else
          w = 'L';
      }
    } else {
      if (v[v.size() - 1] < q.front().first) {
        if (v[v.size() - 1] < q.back().first) {
          if (q.front().first < q.back().first)
            v.push_back(q.front().first), v2.push_back('L'), q.pop_front();
          else if (q.front().first > q.back().first)
            v.push_back(q.back().first), v2.push_back('R'), q.pop_back();
          else {
            int c = 0, c2 = 0;
            for (int i = q.back().second; i > q.front().second; i--) {
              if (a[i] >= a[i - 1]) break;
              c++;
            }
            for (int i = q.front().second; i < q.back().second; i++) {
              if (a[i] >= a[i + 1]) break;
              c2++;
            }
            if (c > c2)
              w = 'R';
            else
              w = 'L';
          }
        } else {
          v.push_back(q.front().first), v2.push_back('L');
          q.pop_front();
        }
      } else if (v[v.size() - 1] < q.back().first) {
        v.push_back(q.back().first), v2.push_back('R');
        q.pop_back();
      } else
        break;
    }
  }
  cout << v2.size() << endl;
  for (int i = 0; i < v2.size(); i++) cout << v2[i];
  return 0;
}
