#P4611. [COI 2012] TRAMPOLIN

[COI 2012] TRAMPOLIN

Description

Specifically, he chose a sequence of NN skyscrapers, numbered from 11 to NN from left to right. He initially stays on the KK-th skyscraper. Unfortunately, his ability is limited, so he can only jump left or right to an adjacent skyscraper, and only to a skyscraper whose height is not greater than the height of his current skyscraper.

However, some skyscrapers have trampolines. From such a skyscraper, he can jump to any other skyscraper, no matter how tall it is and no matter where it is.

Find the maximum number of distinct skyscrapers he can reach starting from the KK-th skyscraper. If a skyscraper is visited multiple times, it is counted only once. Skyscraper KK is also counted, whether or not he returns to it.

Input Format

The first line contains two integers NN and KK (3N3000003 \le N \le 300\,000, 1KN1 \le K \le N), representing the total number of skyscrapers and the starting skyscraper.

The second line contains NN integers, each less than 10610^6, describing the heights of the skyscrapers from left to right.

The third line contains NN characters, . or T. If the ii-th character is T, it means there is a trampoline on the ii-th skyscraper.

Output Format

Output one integer, the maximum number of skyscrapers that can be reached.

6 4
12 16 16 16 14 14
.T....
5
10 1
10 7 3 1 1 9 8 2 4 10
..T..T....
7

Hint

The route for Sample 2 is as follows: 123610981 \to 2 \to 3 \to 6 \to 10 \to 9 \to 8.

Translated by ChatGPT 5