Under construction

Still being built. Things may change

Making PPC

Time limit1sMemory limit1024 MB

Summary
Given a string of C and P characters and at most K swaps, maximize the number of PPC subsequences (P, then P, then C, in order).
Level

Medium5 of 10

Topics
Greedy, Two pointers, String
Solved
No attempts yet

Problem

Phoenix has a string SS that he treasures. SS has length NN and consists only of the uppercase letters C and P. The ii-th character of SS is written SiS_i.

Phoenix wants to decorate the venue of a contest with SS for the teams taking part in PPC. Before the contest, Phoenix can perform the following operation on SS at most KK times.

  • Choose two integers ii and jj with 1≤i<j≤N1 \le i < j \le N, and swap SiS_i and SjS_j.

Phoenix's goal is to make the finished string SS contain as many PPC subsequences as possible. A PPC subsequence is a triple (i,j,k)(i, j, k) with 1≤i<j<k≤N1 \le i < j < k \le N, Si=Sj=S_i = S_j = P, and Sk=S_k = C.

Input

The first line contains the length NN of the string SS and the maximum number of operations KK, separated by a space. (1≤K≤N≤2000001 \le K \le N \le 200000)

The second line contains the string SS of length NN. It is guaranteed that SS consists only of the uppercase letters C and P.

Output

Print the maximum number of PPC subsequences that Phoenix can make.

Examples3

  1. Example 1

    Input
    3 1
    CPP
    
    Expected output
    1
    
  2. Example 2

    Input
    8 2
    CCPCPPCP
    
    Expected output
    21
    
  3. Example 3

    Input
    3 1
    CPC
    
    Expected output
    0