Back From Summer '19 P3: ASDFGHJKL

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

Jonathan is given a string S containing solely lowercase English letters. He is asked to perform the two following operations in order exactly once:

  • Remove a substring of length up to L (inclusive) from the string.
  • Remove up to K (inclusive) characters from the remaining string.

Let ca be the number of a's in the resultant string, cb be the number of b's, etc. Jonathan's goal is to minimize ca2+cb2++cz2 after performing the two operations. What is the minimum possible value?

Python users are recommended to use PyPy over CPython. There is a significant performance increase.

Input Specification

The first line will contain the string S (1|S|105). S will only contain lowercase English letters.

The second line will contain two integers, L,K (0L,K|S|).

Output Specification

Output the minimum possible value of ca2+cb2++cz2 for Jonathan.

Constraints

Subtask 1 [30%]

L=0

Subtask 2 [70%]

No additional constraints.

Sample Input 1

Copy
abcdefghijkllllll
0 5

Sample Output 1

Copy
12

Sample Input 2

Copy
rimuruclasher
3 2

Sample Output 2

Copy
8

Comments

There are no comments at the moment.