Sunflowers in the Gust
Marta grows n sunflowers in a single straight row, numbered 1 to n from left to right. A
morning gust has just passed, and now every sunflower is in one of three states:
L: it leans to the left, toward floweri − 1;R: it leans to the right, toward floweri + 1;.: it stands upright.
The stems are weak and the heads are heavy, so leaning flowers push on their neighbours. The row
changes in whole seconds. During each second, every upright flower i is looked at, all at the
same time, using the states at the start of that second:
- it is pushed from the left if flower
i − 1exists and leansR(into it); - it is pushed from the right if flower
i + 1exists and leansL(into it).
If an upright flower is pushed from exactly one side, it tips away from that side: pushed from the
left it becomes R, pushed from the right it becomes L. If it is pushed from both sides in the
same second, the two pushes cancel and it stays upright. An upright flower that is not pushed stays
upright. A flower that leans never changes again; a flower that tipped during a second starts
pushing its own neighbour in the next second. The ends of the row are open: the first flower has no
left neighbour and the last flower has no right neighbour.
Eventually the row stops changing. Print what it looks like then.
Input
The first line contains n (1 ≤ n ≤ 10^6), the number of sunflowers.
The second line contains a string of exactly n characters, each of them L, R or .; the
i-th character is the state of flower i right after the gust.
Output
Print a single line with n characters: the state of every flower, in order, once the row has
stopped changing.
Notes
In the first example, flower 1 leans right and flower 5 leans left. After one second flowers 2
and 4 have tipped (toward flower 3); in the next second flower 3 is pushed from both sides at once
and stays upright for good. Flower 6 is never pushed: flower 5 leans away from it and flower 7
leans away from it too. Flowers 8 and 9 sit between a right-leaner and a left-leaner with an even
gap, so each tips toward its nearer pusher. Flowers 11 and 12 lie between an L and an R that
lean away from them, and stay upright; flowers 14 and 15 are tipped one after another by flower 13.
In the second example, flower 1 is tipped left by flower 2, and the last flower is tipped right by flower 5.