cswork / OAOpen practice workspace

UberOA #5

Resources A/P Conversion Cycles

Estimated EasyJudge-ready

Topics (AI-labelled)Simulation

In each cycle, first consume conversionRate P's to convert them into one A; if that is not possible and there is an A, consume one A; if neither can be done, stop, and the stopping action does not count as a cycle. Follow the statement strictly: consuming an A does not produce any extra P. The original first two examples, 13 and 4, conflict with the statement and are corrected to 5 and 2 respectively.

This site's standard input and output are explicit.

Input

The first line contains n conversionRate, and the second line contains a contiguous string of n A/P characters. 2≤n≤500, 2≤conversionRate≤500.

Output

Output one integer, the answer.

Example 1

Input:

6 2
AAAPPP

Output:

5

Example 2

Input:

2 2
AA

Output:

2

Example 3

Input:

3 3
PPP

Output:

2

Example notes

Example 1: convert once, leaving 4 A's and 1 P, then consume 4 A's, for 5 cycles in total. Example 2: consume two A's and stop, for 2 cycles in total. Example 3: convert once to get an A, then consume it, for 2 cycles in total.

Editorial

Loading solution…