Under construction

Still being built. Things may change

Toy Train Tracks

Time limit1sMemory limit1024 MB

Summary
Given s straight and c curved track pieces, build the longest closed loop on a grid that does not cross itself and print its piece sequence.
Level

Medium6 of 10

Topics
Math, Geometry, Implementation
Solved
No attempts yet

Problem

Every little child, and quite a few adults, are fascinated by toy trains. From a toddler's choo-choo train to a hobbyist's elaborate model railroad filling an entire basement, they are a profitable business. The Toy Train Tracks Construction Company (TTTCC) manufactures train tracks for all ages and skill levels.

To keep existing customers busy and perhaps attract new ones, TTTCC has recently started publishing maps that show how to connect its train tracks into elaborate layouts. Usually a designer comes up with an interesting track layout, then publishes both the layout and the number of each track segment type (say, curves and straight parts) needed to build it. But TTTCC has learned that many customers want the reverse: they already have track segments lying around (maybe found in grandma's attic) and would like to use them to build a large train course. How difficult might that be?

To study the feasibility of automating the layout-creation process, TTTCC is interested in constructing train courses from two shapes: straight line segments and 90-degree turns (see Figure 1).

Valid layouts are created by placing these shapes on a square grid, with each track piece taking up exactly one grid cell. Both types of pieces can be rotated in 90-degree increments. A "proper" train track must be connected and form a single closed loop. Given a set of straight and curved track segments, what is the longest closed loop one can construct?

Figure 2: A sample track using four straight track segments and twelve curves. This corresponds to Sample Output 1.

Input

The input is a single line containing two integers ss and cc, the number of straight and curved track segments available, respectively (0≤s≤1050 \le s \le 10^5, 4≤c≤1054 \le c \le 10^5).

Output

Output a train loop that uses at most ss straight segments and cc curved segments and has the longest possible length (in number of track segments). The loop must be closed and cannot intersect itself. If several loops have the maximal length, any one of them is accepted.

If the loop has length nn, print a single string of length nn, where each character represents a segment in the order encountered during one traversal of the loop. S stands for a straight segment, L for a curved segment that turns left, and R for a curved segment that turns right.

Examples2

  1. Example 1

    Input
    4 12
    
    Expected output
    LSRLLRLSLSRLLSRL
    
  2. Example 2

    Input
    1 5
    
    Expected output
    LLLL