#P9172. [COCI 2022/2023 #4] 7Krokods
[COCI 2022/2023 #4] 7Krokods
Background
Enhanced version Second enhanced version
Problem Description
Krokod likes playing board games with Paula. He wants to play the 7Krokods game, but Paula does not like complicated games, so Krokod decided that they will play using only green cards and crocodile cards.
Paula has green cards, and each card has one of the following letters written on it: .
Her total score is defined as the sum of the following parts.
- For each letter, she gets a score equal to the square of the number of cards with that letter. For example, if she has cards with the letter , she gets points.
- For each time she forms the word
krokod, she gets an additional points.
Paula also has crocodile cards. She can use any crocodile card to replace a green card, with the green card having any letter she chooses.
Compute the maximum score she can get from her cards.
Input Format
The first line contains two integers and , representing the number of green cards and the number of crocodile cards.
The second line contains a sequence of characters, where the -th character represents the letter on the -th green card. The sequence consists only of the characters .
Output Format
Output one integer in a single line, the maximum possible score Paula can achieve.
15 0
krokodkrokodkrk
79
5 1
rokod
17
8 2
ddkkoorr
35
Hint
Explanation for Sample :

Paula has letters ( points), letters ( points), letters ( points), and letters ( points). The word krokod can be formed times ( points). Her total score is ().
Explanation for Sample :
Paula can turn her crocodile card into a green card with the letter written on it.
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| Sample | ||
| No additional constraints |
Translated by ChatGPT 5