All problems

Problem 844

Push Dominoes

Medium · 20 pts · String, Two Pointers, Simulation

Problem

Dominoes stand in a line. Each is pushed left (L), pushed right (R) or standing still (.). Every second, a domino falling left pushes its left neighbour, and one falling right pushes its right neighbour. A standing domino pushed from both sides at the same moment stays upright, and a falling domino does not push a domino that has already fallen. Print the final state. Compare, for each standing domino, the distance to the nearest R on its left and the nearest L on its right.

Input

A single string of the characters L, R and '.'.

Output

Print the final state of the dominoes.

Constraints

1 <= length <= 100000

Example input

.L.R...LR..L..

Example output

LL.RR.LLRRLL..

Explanation

In .L.R...LR..L.., the first domino falls left (LL), the block R...L becomes RR.LL (the middle one is pushed from both sides at once), and R..L becomes RRLL, while the last two dominoes are never pushed, giving LL.RR.LLRRLL..

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Maximum Number of Vowels in a Substring of Given Length Next: Orderly Queue