The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).

You are given a sequence a consisting of n integers.

You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the rightmost element of the sequence, write it down and remove it from the sequence. Your task is to write down a strictly increasing sequence, and among all such sequences you should take the longest (the length of the sequence is the number of elements in it).

For example, for the sequence [1, 2, 4, 3, 2] the answer is 4 (you take 1 and the sequence becomes [2, 4, 3, 2], then you take the rightmost element 2 and the sequence becomes [2, 4, 3], then you take 3 and the sequence becomes [2, 4] and then you take 4 and the sequence becomes [2], the obtained increasing sequence is [1, 2, 3, 4]).

Input

The first line of the input contains one integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of elements in a.

The second line of the input contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 2 ⋅ 10^5), where a_i is the i-th element of a.

Output

In the first line of the output print k — the maximum number of elements in a strictly increasing sequence you can obtain.

In the second line print a string s of length k, where the j-th character of this string s_j should be 'L' if you take the leftmost element during the j-th move and 'R' otherwise. If there are multiple answers, you can print any.

Examples

Input


5
1 2 4 3 2


Output


4
LRRR


Input


7
1 3 5 6 5 4 2


Output


6
LRLRRR


Input


3
2 2 2


Output


1
R


Input


4
1 2 4 3


Output


4
LLRR

Note

The first example is described in the problem statement.
#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 2147483640;
const long long linf = 1e15;
template <class T>
T fast_pow(T x, T k, T m) {
  T ans = 1;
  while (k) {
    if (k % 2 == 1) ans = ans * x % m;
    k = k / 2;
    x = x * x % m;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int exgcd(int a, int b, int &x, int &y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  int d = exgcd(b, a % b, x, y);
  int t = x;
  x = y;
  y = t - a / b * y;
  return d;
}
bool exgcd_work(int a, int b, int &x, int &y, int c) {
  int g = exgcd(a, b, x, y);
  int _a = a / g, _b = b / g;
  if (c % g != 0) return 0;
  while (x <= 0) x += _a, y += _b;
  x *= c / g, y *= c / g;
  return 1;
}
template <class T>
T muti_gcd(T a[], int n) {
  T ans = a[1];
  for (int i = 2; i <= n; i++) ans = gcd(ans, a[i]);
  return ans;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void init_prime(bool not_prime[], int prime[], int &head, int n) {
  not_prime[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (!not_prime[i]) prime[++head] = i;
    for (int j = 1; j <= head && (long long)prime[j] * i <= n; j++) {
      not_prime[prime[j] * i] = 1;
      if (i % prime[j] == 0) break;
    }
  }
}
bool is_prime(int x) {
  int t = sqrt(x);
  for (int i = 2; i <= t; i++)
    if (x % i == 0) return 0;
  return 1;
}
int crt(int n, int a[], int m[]) {
  int d = 1, x, y, ans = 0;
  for (int i = 1; i <= n; i++) d = d * m[i];
  for (int i = 1; i <= n; i++) {
    int M = d / m[i];
    exgcd(M, m[i], x, y);
    ans = (ans + M * x * a[i]) % d;
  }
  if (ans < 0) ans += d;
  return ans;
}
int get_phi(int n) {
  int ans = n, t = sqrt(n);
  for (int i = 2; i <= t; i++) {
    if (n % i == 0) {
      ans -= ans / i;
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) ans -= ans / n;
  return ans;
}
int init_phi() { return -1; }
long long euler(long long a, string b, long long m) {
  bool flag = 0;
  long long t = 0, phi_m = get_phi(m);
  for (string::iterator p = b.begin(); p != b.end(); p++) {
    t = t * 10 + (*p) - '0';
    if (t >= phi_m) t %= phi_m, flag = 1;
  }
  return flag ? fast_pow(a, t % phi_m + phi_m, m) : fast_pow(a, t, m);
}
template <size_t sz, long long MOD>
struct mat {
  int n, m;
  long long a[sz][sz];
  mat(int x = 0) { n = m = x, memset(this->a, 0, sizeof(this->a)); }
  mat(int x, int y) { n = x, m = y, memset(this->a, 0, sizeof(this->a)); }
  void unit(int x) {
    n = m = x;
    memset(a, 0, sizeof(a));
    for (int i = 1; i <= n; i++) a[i][i] = 1;
  }
  long long *operator[](size_t i) { return a[i]; }
  mat operator*(mat x) {
    mat res(n, x.m);
    if (m == x.n) {
      for (int k = 1; k <= m; k++)
        for (int i = 1; i <= n; i++)
          for (int j = 1; j <= x.m; j++)
            res.a[i][j] = (res.a[i][j] + a[i][k] * x.a[k][j] % MOD) % MOD;
    }
    return res;
  }
  void operator*=(mat x) { *this = (*this) * x; }
  void pow(long long k) {
    mat<sz, MOD> ans(n), x = (*this);
    ans.unit(ans.n);
    while (k) {
      if (k & 1) ans = ans * x;
      k = k >> 1, x = x * x;
    }
    (*this) = ans;
  }
  void print(bool flag = 0) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) printf("%lld ", a[i][j]);
      printf("\n");
    }
    if (flag)
      for (int i = 1; i <= n; i++) printf("-");
    if (flag) printf("\n");
  }
  void read() {
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) scanf("%lld", &a[i][j]);
  }
};
long long get_inv(long long x, long long mod) {
  return fast_pow(x, mod - 2, mod);
}
template <size_t sz>
bool guass(double a[][sz], int n) {
  double t;
  int i = 1, to;
  const double eps = 1e-6;
  for (int i = 1; i <= n; i++) {
    for (to = i; to <= n; to++)
      if (fabs(a[to][i]) > eps) break;
    if (to > n) continue;
    if (to != i)
      for (int j = 1; j <= n + 1; j++) swap(a[to][j], a[i][j]);
    t = a[i][i];
    for (int j = 1; j <= n + 1; j++) a[i][j] /= t;
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      t = a[j][i];
      for (int k = 1; k <= n + 1; k++) a[j][k] -= t * a[i][k];
    }
  }
  for (int i = 1; i <= n; i++)
    if (fabs(a[i][n + 1]) > eps) return 0;
  return 1;
}
template <size_t sz>
void guass(long long a[][sz], int n, int MOD) {
  long long t;
  int i = 1, to;
  for (int i = 1; i <= n; i++) {
    for (to = i; to <= n; to++)
      if (a[to][i]) break;
    if (to > n) continue;
    if (to != i)
      for (int j = 1; j <= n + 1; j++) swap(a[to][j], a[i][j]);
    t = get_inv(a[i][i], MOD);
    for (int j = 1; j <= n + 1; j++) a[i][j] *= t, a[i][j] %= MOD;
    for (int j = 1; j <= n; j++) {
      if (j == i) continue;
      t = a[j][i];
      for (int k = 1; k <= n + 1; k++)
        a[j][k] = ((a[j][k] - t * a[i][k] % MOD) % MOD + MOD) % MOD;
    }
  }
}
int read() {
  int t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  return t * f;
}
extern const int MAXN = 200005;
extern const int N = 10000000;
int n, mx = 0;
int a[MAXN];
string ans;
int work() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  int l = 1, r = n;
  while (l <= r) {
    if (a[l] > mx && a[r] > mx) {
      if (a[l] == a[r]) {
        int tl = l + 1, tr = r - 1;
        while (a[tl] > a[tl - 1] && tl < r) tl++;
        while (a[tr] > a[tr + 1] && tr > l) tr--;
        if (tl - l - 1 > r - tr - 1)
          ans.push_back('L'), mx = a[l++];
        else
          ans.push_back('R'), mx = a[r--];
      } else {
        if (a[l] > a[r])
          ans.push_back('R'), mx = a[r--];
        else
          ans.push_back('L'), mx = a[l++];
      }
    } else {
      if (a[l] > mx) ans.push_back('L'), mx = a[l++];
      if (a[r] > mx) ans.push_back('R'), mx = a[r--];
    }
    if (a[l] <= mx && a[r] <= mx) break;
  }
  cout << ans.length() << endl;
  cout << ans << endl;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  work();
  return 0;
}
