ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

Ural Championship 2007

About     Problems     Submit solution     Judge status     Standings
Contest is over

H. Another Japanese Puzzle

Time limit: 1.0 second
Memory limit: 64 MB
A lecturer of the Ural State University has bought an amusing toy in Tokyo: a small airplane and a set of plastic plates. The plates can be put together to form a path for the plane the same way as a puzzle can be assembled from pieces. There are many ways to put together the plates, but if one makes it the right way, a map of Japan is assembled, and the plane will go along a closed path visiting all major Japan's sights. Try to guess what the lecturer's wife said when she saw the toy—“Thank you!” or “Was it necessary to spend so much money on such rubbish?” No, she said: “What a pity that you haven't bought several sets! We could assemble a much longer path!”
Imagine that you have many plates with path segments. What is the longest closed path that you can assemble?
The plates can be assumed to be squares of equal size, and the path always connects the centers of two sides of a square. It means that there are two kinds of plates: with straight lines and with turns.


The only line of the input contains two integers: the number of plates with straight segments S and the number of plates with turns T (0 ≤ ST ≤ 1000, S + T > 0).


In the first line output the maximal number of plates N that can be used to assemble a path for the plane. In the second line output the path in the following format: a line of length N consisting of letters F, L, and R. Here F means that the corresponding segment of the path is straight, L denotes a left turn, and R denotes a right turn. The total number of letters F must not exceed S, and the total number of letters L and R must not exceed T. The path must be closed (the last square must join the first square) and the squares can't overlap. If it is impossible to assemble a closed path from the available plates, then output “Atawazu” (“Impossible”, Jap.).


5 6
49 3
Problem Author: Stanislav Vasilyev (prepared by Vladimir Yakovlev)
Problem Source: The 11th Urals Collegiate Programing Championship, Ekaterinburg, April 21, 2007
To submit the solution for this problem go to the Problem set: 1549. Another Japanese Puzzle