PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000059. Mã đường đi trong cây Stern–Brocot (The Stern-Brocot Number System)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Mã đường đi trong cây Stern–Brocot (The Stern-Brocot Number System)

The Stern-Brocot Number System

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Each node of the Stern–Brocot tree is determined by a left bound a/ba/b and a right bound c/dc/d. Its value is (a+c)/(b+d)(a+c)/(b+d): add the two numerators and add the two denominators.

The root uses bounds 0/10/1 and 1/01/0, so its value is 1/11/1. Here 1/01/0 denotes a positive-infinity boundary, not an ordinary fraction.

From a node u/vu/v, an L step keeps the left bound and replaces the right bound by u/vu/v. An R step replaces the left bound by u/vu/v and keeps the right bound. Compute the child value from the updated bounds using the same rule.

Given a reduced positive fraction p/qp/q different from 1/11/1, output the sequence of L and R steps from the root to its node.

Input

Two positive coprime integers p and q with p != q.

Output

The string of L and R characters.

Subtasks

  • Subtask 1 (20 points): 1≤p,q≤301\le p,q\le 30; path length at most 100100.
  • Subtask 2 (30 points): 1≤p,q≤10001\le p,q\le 1000; path length at most 30003000.
  • Subtask 3 (50 points): 1≤p,q≤1061\le p,q\le 10^6; path length at most 2⋅1062\cdot10^6.

Examples

Input

5 7

Output

LRRL

Explanation

The path to 5/7 is L, R, R, L.