## TLE '17 Contest 1 P3 - Screensaver 2

View as PDF

Points: 7 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type
A screenshot of :kevin: in action.

On the second day of school, the computer science teacher shows some more impressive screensavers on the computer. This time, the screensaver called :kevin: stands out to you, mainly due to the simple rules that govern :kevin:.

Upon careful analysis, :kevin: can be represented as an array of mirrors placed along a horizontal line. There is unit distance between adjacent mirrors, and the mirrors can be oriented in two ways, horizontally and vertically.

A ball enters the array from the left end, and is moving to the right at a rate of unit distance per second. The first bounce occurs at seconds. The rules of bouncing are in the following list:

• If the ball hits a horizontal mirror, the ball's direction stays the same and the mirror becomes vertical.
• If the ball hits a vertical mirror, the ball will move in the opposite direction and the mirror becomes horizontal.

As a fan of :kevin:, you want to implement this screensaver yourself! Firstly, the ball tends to leave the array too quickly. Given the initial conditions, your task is to calculate the number of seconds that the ball will stay in the array. Since this number may be too small for your own taste, there will be updates. On the update, change the initial orientation of the mirror and output the new number of seconds.

1 25
2 25
3 50

#### Input Specification

The first line will contain two space-separated integers, and .

The second line will contain characters. The character represents the initial orientation of the mirror.

On the next lines, the line will contain the integer . The initial orientation of the mirror will be changed.

#### Output Specification

For each of the changes, on an empty line, output the number of seconds that the ball will stay in the array. It is guaranteed that this number will not exceed .

#### Sample Input

5 4
|--|-
1
1
1
4

#### Sample Output

7
1
7
5

#### Explanation for Sample Output

On the first change, the initial array set to ---|-.

The ball leaves the array after seconds.

On the second change, the initial array set to |--|-.

The ball leaves the array after second.

On the third change, the initial array is set to ---|-. This is the same as the first change, so the ball leaves the array after seconds.

On the fourth change, the initial array is set to -----, and all mirrors are horizontal. The ball leaves the array after seconds.