#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
int x[MAXN];
vector<char> v;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x[i]);
  }
  int ans = -1;
  int now = -1, first = 0, second = n - 1;
  while (1) {
    if (first == second) {
      ans = n - (second - first + 1);
      if (x[second] > now) {
        v.push_back('R');
        ans++;
      }
      break;
    }
    if (x[first] == x[second]) {
      if (x[first] < now) {
        break;
      }
      int l = x[first];
      int a = 0, b = 0;
      for (int i = first + 1; i <= second; i++) {
        if (l < x[i]) {
          l = x[i];
          a++;
        } else {
          break;
        }
      }
      l = x[second];
      for (int i = second - 1; i >= first; i--) {
        if (l < x[i]) {
          l = x[i];
          b++;
        } else {
          break;
        }
      }
      if (a > b) {
        if (x[first] > now) {
          now = x[first];
          v.push_back('L');
          first++;
        } else {
          break;
        }
      } else if (b > a) {
        if (x[second] > now) {
          now = x[second];
          second--;
          v.push_back('R');
        } else {
          break;
        }
      } else {
        if (x[second] > now) {
          now = x[second];
          second--;
          v.push_back('R');
        } else {
          break;
        }
      }
      continue;
    } else if (x[first] > x[second]) {
      if (x[second] > now) {
        now = x[second];
        second--;
        v.push_back('R');
        continue;
      } else if (x[first] > now) {
        now = x[first];
        first++;
        v.push_back('L');
        continue;
      }
    } else if (x[first] < x[second]) {
      if (x[first] > now) {
        now = x[first];
        first++;
        v.push_back('L');
        continue;
      } else if (x[second] > now) {
        now = x[second];
        second--;
        v.push_back('R');
        continue;
      }
    }
    break;
  }
  if (ans == -1) {
    ans = n - (second - first + 1);
  }
  printf("%d\n", ans);
  for (auto i : v) {
    printf("%c", i);
  }
}
