#include <bits/stdc++.h>
using namespace std;
long long const mod = 998244353;
inline long long add(long long a, long long b) {
  return ((a % mod) + (b % mod) + mod) % mod;
}
inline long long mul(long long a, long long b) {
  return (((a % mod) * (b % mod)) % mod + mod) % mod;
}
inline long long sub(long long a, long long b) {
  return ((a % mod) - (b % mod) + mod) % mod;
}
long long power(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long modInv(long long x) { return power(x, mod - 2, mod) % mod; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  long long i = 0;
  long long j = n - 1;
  long long prev = 0;
  string second;
  while (i <= j) {
    if (a[i] < a[j]) {
      if (prev < a[i]) {
        ans++;
        second.push_back('L');
        prev = a[i];
        i++;
      } else if (prev < a[j]) {
        ans++;
        second.push_back('R');
        prev = a[j];
        j--;
      } else {
        break;
      }
    } else if (a[i] > a[j]) {
      if (prev < a[j]) {
        ans++;
        second.push_back('R');
        prev = a[j];
        j--;
      } else if (prev < a[i]) {
        ans++;
        second.push_back('L');
        prev = a[i];
        i++;
      } else {
        break;
      }
    } else {
      if (i == j) {
        if (a[i] > prev) {
          ans++;
          second.push_back('L');
        }
        break;
      }
      long long ans1 = 0;
      long long prev2 = prev;
      string p;
      for (int k = i; k < j; k++) {
        if (a[k] > prev2) {
          prev2 = a[k];
          ans1++;
          p.push_back('L');
        } else {
          break;
        }
      }
      long long ans2 = 0;
      prev2 = prev;
      string q;
      for (int k = j; k > i; k--) {
        if (a[k] > prev2) {
          prev2 = a[k];
          ans2++;
          q.push_back('R');
        } else {
          break;
        }
      }
      if (ans1 > ans2)
        second = second + p;
      else {
        second = second + q;
      }
      ans = ans + max(ans1, ans2);
      break;
    }
  }
  cout << ans << endl;
  cout << second << endl;
  return 0;
}
