#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 nn green cards, and each card has one of the following letters written on it: d,k,o,rd, k, o, r.

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 66 cards with the letter kk, she gets 3636 points.
  • For each time she forms the word krokod, she gets an additional 77 points.

Paula also has mm 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 nn and m(0n100,0m10)m(0\leq n\leq 100,0\leq m\leq 10), representing the number of green cards and the number of crocodile cards.

The second line contains a sequence of nn characters, where the ii-th character represents the letter on the ii-th green card. The sequence consists only of the characters d,k,o,rd, k, o, r.

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 11:

Paula has 22 letters dd (2×2=42\times 2=4 points), 66 letters kk (6×6=366\times 6=36 points), 44 letters oo (4×4=164\times 4=16 points), and 33 letters rr (3×3=93\times 3 = 9 points). The word krokod can be formed 22 times (7×2=147\times 2=14 points). Her total score is 7979 (4+36+16+9+14=794 + 36 + 16 + 9 + 14 = 79).

Explanation for Sample 22:

Paula can turn her crocodile card into a green card with the letter kk written on it.

Subtask ID Additional Constraints Score
00 Sample 00
11 m=1m=1 1717
22 m=2m=2 2626
33 No additional constraints 77

Translated by ChatGPT 5