# How do you speed up the program? There's a solution, but five tests out of ten don't take time (3 seconds)

• Numbering The city of Beitland has decided to build a new microregion that will consist of one long street. The construction of houses will look as follows. First, it'll be the first house to get number zero. (Applause, in Beitland, all numbers start from zero.) All houses will then be built on the left or right of the existing construction. Houses will receive numbers as they enter into service.

Let's see the example. Let's see, house number one was built on the left of house number 0. Then the numbering of houses on the left to the right would look like 1 0. Next, home number 2 was built on the left. Now there will be room 2 0 at home. Next, home number 3 was built to the right of the existing one. Now, there's gonna be houses on the street with rooms 2 1 0 3. Finally, if house number 4 is built on the left and houses with numbers 5 and 6 on the right, the sequence of house numbers will turn to 4 2 1 0 3 5 6.

The street was built with n-n-1 houses. For every single house with an unnulled number, we have learned from which side it was built. Now your job is to write a program that will list the house numbers on the street to the right.

Input format In the first line, a number of n, the number of built houses, is being supplied. 2 ≤ n ≤ 400000. In the second line, a sequence of n-1 "L" or "R" symbols is recorded. The "L" symbol in the i-this position means that a house with number i was built on the left of the previous one, and the "R" symbol on the right.

Output data format Remove through the gap in one line a sequence of n chisel - the number of houses after completion.

Test method and description The program is checked for 10 tests. Every test runs two points. The test is not used in the test.

In the first five tests n ≤ 100.

``````Sample Input:
7
LLRLRR
Sample Output:
4 2 1 0 3 5 6
``````

My decision is:

``````dom = int(input())
a = input()
spisok = [0]
k = 0
while k < dom - 1:
if a[k] == 'L':
spisok.insert(0, k + 1)
if a[k] == 'R':
spisok.append(k + 1)
k += 1
print(*spisok)
``````

• Put left and right-wing houses on separate appendix lists.

Then turn the left list, remove it, then the right.

(Insert at the beginning of the list causes continuous redistribution of memory)

``````dom = int(input())
a = input()
spisokL = []
spisokR = [0]
k = 0
while k < dom - 1:
if a[k] == 'L':
spisokL.append(k + 1)
if a[k] == 'R':
spisokR.append(k + 1)
k += 1
spisokL.reverse()
print(*spisokL, *spisokR)
``````

2

2

2

2

2

2

2

2

2

2

2

2

2

2

2