Dumbear loves numbers very much.
One day Dumbear found that each number can be expressed as a continued fraction. See below.
Formally, we say a number k can be expressed as a continued faction if
where a
0, a
1, …, a
n are positive integers except that a
0 maybe be 0 and a
n cannot be 1.
Dumbear also found a sequence which looks like the Farey sequence. Initially the sequence
and if we insert an element
between all the two adjacent element
,
in D
i, then we get a sequence D
i+1. So you can see
and
Assume initially you are on the element
in D
0, and if now you are on the element k in D
i, then if you go left(‘L’)(or right(‘R’)) you will be on the left(or right) element of k in D
i+1. So a sequence composed of ‘L’ and ‘R’ denotes a number. Such as ‘RL’ denotes the number
Now give you a sequence composed of ‘L’ and ‘R’, you should print the continued fraction form of the number. You should use ‘-‘ to show the vinculum(the horizontal line), you should print one space both in front and back of ‘+’, and all parts up or down the vinculum should be right aligned. You should not print unnecessary space, ‘-‘ or other character. See details in sample.