Problem: 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. All these integers are distinct, each value from 1 to n appears in the sequence exactly once.

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 [2, 1, 5, 4, 3] the answer is 4 (you take 2 and the sequence becomes [1, 5, 4, 3], then you take the rightmost element 3 and the sequence becomes [1, 5, 4], then you take 4 and the sequence becomes [1, 5] and then you take 5 and the sequence becomes [1], the obtained increasing sequence is [2, 3, 4, 5]).

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 ≤ n), where a_i is the i-th element of a. All these integers are pairwise distinct.

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
2 1 5 4 3


Output


4
LRRR


Input


7
1 3 5 6 7 4 2


Output


7
LRLRLLL


Input


3
1 2 3


Output


3
LLL


Input


4
1 2 4 3


Output


4
LLRL

Note

The first example is described in the problem statement.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[200005];
int mmap[200005];
string st = "";
void extra();
void input() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
}
int L, R;
int leftBlock, rightBlock, noNeed, bothEqual;
priority_queue<int> pq;
void rightTheke(int R) {
  for (int i = R; i > L; i--) {
    if (arr[i] > pq.top() && mmap[arr[i]] == 0) {
      st += 'R';
      pq.push(arr[i]);
    } else
      break;
  }
}
void leftTheke(int L) {
  for (int i = L; i < R; i++) {
    if (arr[i] > pq.top() && mmap[arr[i]] == 0) {
      st += 'L';
      pq.push(arr[i]);
    } else
      break;
  }
}
void fun1() {
  L = 1, R = n;
  if (arr[L] < arr[R]) {
    pq.push(arr[L]);
    st += 'L';
    L++;
  } else if (arr[R] < arr[L]) {
    pq.push(arr[R]);
    st += 'R';
    R--;
  } else if (arr[R] == arr[L]) {
    bothEqual = 1;
    return;
  }
  while (L <= R) {
    if (arr[L] == arr[R]) {
      bothEqual = 1;
      break;
    }
    if (arr[L] < arr[R] && arr[L] > pq.top()) {
      if (mmap[arr[L]]) {
        leftBlock = 1;
        rightTheke(R);
        break;
      } else {
        st += 'L';
        pq.push(arr[L]);
        mmap[arr[L]]++;
        L++;
      }
    } else if (arr[R] < arr[L] && arr[R] > pq.top()) {
      if (mmap[arr[R]]) {
        rightBlock = 1;
        leftTheke(L);
        break;
      } else {
        st += 'R';
        pq.push(arr[R]);
        mmap[arr[R]]++;
        R--;
      }
    } else {
      int mx = max(arr[L], arr[R]);
      if (mx == arr[L] && mx > pq.top()) {
        if (mmap[arr[L]] == 0) {
          pq.push(arr[L]);
          mmap[arr[L]]++;
          st += 'L';
          L++;
        } else {
          noNeed = 1;
          break;
        }
      } else if (mx == arr[R] && mx > pq.top()) {
        if (mmap[arr[R]] == 0) {
          pq.push(arr[R]);
          mmap[arr[R]]++;
          st += 'R';
          R--;
        } else {
          noNeed = 1;
          break;
        }
      } else {
        noNeed = 1;
        break;
      }
    }
  }
}
void fun2() {
  if (arr[L] > pq.top()) {
    int t1 = 1, t2 = 1;
    for (int i = L; i < R; i++) {
      if (arr[i] < arr[i + 1]) {
        t1++;
      } else
        break;
    }
    for (int i = R; i > L; i--) {
      if (arr[i] < arr[i - 1]) {
        t2++;
      } else
        break;
    }
    if (max(t1, t2) == t1) {
      for (int i = L; i < R; i++) {
        if (arr[i] < arr[i + 1]) {
          st += 'L';
        } else
          break;
      }
      st += 'L';
    } else {
      for (int i = R; i > L; i--) {
        if (arr[i] < arr[i - 1]) {
          st += 'R';
        } else
          break;
      }
      st += 'R';
    }
  }
}
int main() {
  input();
  fun1();
  if (noNeed == 1 || leftBlock == 1 || rightBlock == 1) {
    cout << st.size() << endl;
    cout << st << endl;
    return 0;
  } else if (bothEqual) {
    if (pq.size() == 0) {
      extra();
      cout << st.size() << endl;
      cout << st << endl;
      return 0;
    }
    fun2();
    cout << st.size() << endl;
    cout << st << endl;
  }
  return 0;
}
void extra() {
  int t1 = 1, t2 = 1;
  for (int i = L; i < R; i++) {
    if (arr[i] < arr[i + 1]) {
      t1++;
    } else
      break;
  }
  for (int i = R; i > L; i--) {
    if (arr[i] < arr[i - 1]) {
      t2++;
    } else
      break;
  }
  if (max(t1, t2) == t1) {
    for (int i = L; i < R; i++) {
      if (arr[i] < arr[i + 1]) {
        st += 'L';
      } else
        break;
    }
    st += 'L';
  } else {
    for (int i = R; i > L; i--) {
      if (arr[i] < arr[i - 1]) {
        st += 'R';
      } else
        break;
    }
    st += 'R';
  }
}