## LCC/Moose '20 Contest 5 J2 - Puzzle Streaking

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Justin is playing a chess puzzle minigame!

In this minigame, you start with points. Based on if he solves the current puzzle or not, he will gain or lose score.

For each problem that Justin solves correctly, he gains point. However, if he gets the problem wrong, he loses points.

In this puzzle minigame, there is also a streak, which gives you bonus points if you solve some amount of problems correct in a row. If Justin manages to hit the streak, which is done by solving problems in a row, he gains points and his streak resets to . Otherwise, if he gets a problem wrong, his streak also resets to and he gets no bonus points from the streak.

Justin is planning to solve problems in total, but he may not be able to, if he runs out of points before he solves all the puzzles. Given results, either AC for a solved puzzle or WA for an incorrect solve, figure out how many points he will end with, or if he loses all of his points( or negative values) before the puzzles, he gets score.

#### Input Specification

The first line will contain 3 integers , , and , representing the number of points you start off with, the number of puzzles, the streak value, and the bonus points you get for hitting a specific streak, respectively. It is guaranteed that all of these values will be between and .

#### Output Specification

Output one integer, the number of points that Justin ends with after doing the puzzles, or if he loses all of his points before solving all of them.

#### Sample Input 1

65 5 5 5
AC
AC
AC
AC
AC

#### Sample Output 1

75

#### Sample Explanation

Justin starts off with , and he solved problems, so he gets point for each of them. However, he also hits the streak of , so he gains points, totaling up to .

#### Sample Input 2

1 7 5 6
AC
AC
AC
AC
WA
WA
AC

#### Sample Output 2

0

#### Sample Explanation 2

Justin started off with point, solved problems, so he has points. However, he got wrong, so he loses points, thus going into negatives. Because of this, we print .