CF847E.Packmen

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A game field is a strip of 1×n1×n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty.

Packman can move to neighboring cell in 11 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk.

In the initial moment of time all Packmen begin to move. Each Packman can change direction of its move unlimited number of times, but it is not allowed to go beyond the boundaries of the game field. Packmen do not interfere with the movement of other packmen; in one cell there can be any number of packmen moving in any directions.

Your task is to determine minimum possible time after which Packmen can eat all the asterisks.

输入格式

The first line contains a single integer nn ( 2<=n<=1052<=n<=10^{5} ) — the length of the game field.

The second line contains the description of the game field consisting of nn symbols. If there is symbol '.' in position ii — the cell ii is empty. If there is symbol '*' in position ii — in the cell ii contains an asterisk. If there is symbol 'P' in position ii — Packman is in the cell ii .

It is guaranteed that on the game field there is at least one Packman and at least one asterisk.

输出格式

Print minimum possible time after which Packmen can eat all asterisks.

输入输出样例

  • 输入#1

    7
    *..P*P*
    

    输出#1

    3
    
  • 输入#2

    10
    .**PP.*P.*
    

    输出#2

    2
    

说明/提示

In the first example Packman in position 44 will move to the left and will eat asterisk in position 11 . He will spend 33 time units on it. During the same 33 time units Packman in position 66 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 55 (in 11 time unit) and then move from the position 55 to the right and eat asterisk in the position 77 (in 22 time units). So in 33 time units Packmen will eat all asterisks on the game field.

In the second example Packman in the position 44 will move to the left and after 22 time units will eat asterisks in positions 33 and 22 . Packmen in positions 55 and 88 will move to the right and in 22 time units will eat asterisks in positions 77 and 1010 , respectively. So 22 time units is enough for Packmen to eat all asterisks on the game field.

首页