#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 10;
int a[MAX];
vector<char> ans;
int check(int i, int d) {
  int ans = 0;
  int now = a[i];
  for (int j = i + d; a[j] > a[j - d]; j += d) ans++;
  return ans;
}
void do_rest(int i, int d) {
  int now = a[i];
  char c = (d == 1 ? 'L' : 'R');
  ans.push_back(c);
  i += d;
  while (now < a[i]) {
    ans.push_back(c);
    now = a[i];
    i += d;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int i = 0;
  int j = n - 1;
  int now = -1;
  while (now < a[i] || now < a[j]) {
    if (a[i] < a[j] && now < a[i]) {
      ans.push_back('L');
      now = a[i++];
    } else if (a[j] < a[i] && now < a[j]) {
      ans.push_back('R');
      now = a[j--];
    } else if (a[i] == a[j] && i != j) {
      if (check(i, +1) > check(j, -1)) {
        do_rest(i, +1);
        break;
      } else {
        do_rest(j, -1);
        break;
      }
    } else if (now < a[i]) {
      ans.push_back('L');
      now = a[i++];
    } else {
      ans.push_back('R');
      now = a[j--];
    }
  }
  cout << (int)ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); i++) cout << ans[i];
  cout << endl;
  return 0;
}
