#P6101. [EER2] 出言不逊

[EER2] 出言不逊

Description

Keai wants to participate in an open contest, but she gets rejected every time.

Keai is very angry, so she learned to speak rudely.

Keai uses a string SS to store what she wants to say, but this sentence is too mild. To speak rudely, Keai needs to operate on the string. In each operation, Keai can choose a character cc. If cc appears xx times in string SS, then Keai will append xx copies of character cc to the end of SS.

Keai thinks that only when the length of this string is at least LL can she speak rudely. Keai wants to know the minimum number of operations needed to make the length of this string greater than or equal to LL.

If you do not tell Keai, Keai will speak rudely to you.

Input Format

The first line contains a string SS.

The second line contains a positive integer LL.

Their meanings are as described in the statement.

Output Format

Output one integer in a single line, representing the minimum number of operations.

nzhtl1477
15

2

Hint

Sample Explanation

In the first operation, choose character 7. The string becomes nzhtl147777, and the length is 1111.

In the second operation, choose character 7. The string becomes nzhtl1477777777, and the length is 1515.

Constraints and Notes

For 100%100\% of the testdata, 1S1061\leq |S|\leq 10^6, 1L<2641\leq L\lt 2^{64}. The string SS contains only uppercase letters, lowercase letters, and digits, for a total of 6262 different characters.

S|S| denotes the length of string SS.

This problem has 44 subtasks, each with the following constraints:

Subtask 1 (1515 points): It is guaranteed that S=L1|S|=L-1.

Subtask 2 (2020 points): It is guaranteed that only character d appears in SS.

Subtask 3 (3030 points): L106L\leq 10^6.

Subtask 4 (3535 points): No special constraints.

Notes

Please pay attention to the upper bound of LL.

The data is generated on Windows. Note that the line ending of each line is \r\n rather than \n.

Translated by ChatGPT 5