Trick or Treat (Hard)!


Submit solution

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

Author:
Problem type

You are trick-or-treating with a candy bucket that can hold at most K candies.
Each house either gives a "Treat" or a "Trick".

  • "Treat" gives \(+2\) candies.
  • "Trick" makes you drop \(1\) candy (but not below \(0\)).
  • You can never have more than \(K\) candies — any extras are wasted.

Determine how many candies you have after visiting all \(N\) houses.

Input Specification

The first line contains two integers \(N\) and \(K\) \((1 ≤ N, K ≤ 1000)\).
The second line contains \(N\) space-separated strings, each either "Trick" or "Treat".

Output Specification

Print one integer — the number of candies in your bucket after all houses.

Sample Input

6 5
Treat Trick Treat Treat Treat Trick

Sample Output

4

Comments

There are no comments at the moment.