Subsequences (hard version)

题意翻译

本题和E题唯一的不同点是数据范围。 你有一个长度为$n$的字符串。你可以选择它的任意一个子序列。子序列定义为可以将这个字符串删去若干个字符得到。特别的,空串也是一个子序列。 对于一个长度为$m$的子序列,选出它的花费是$n-m$,也就是你需要删掉的字符数量。 你的任务是选出来$k$个**本质不同**的子序列,使得总花费最小。输出这个最小花费。 如果选不出$k$个,输出$-1$。 $\text{——by wucstdio}$

题目描述

The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa". You are given a string $ s $ consisting of $ n $ lowercase Latin letters. In one move you can take any subsequence $ t $ of the given string and add it to the set $ S $ . The set $ S $ can't contain duplicates. This move costs $ n - |t| $ , where $ |t| $ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters). Your task is to find out the minimum possible total cost to obtain a set $ S $ of size $ k $ or report that it is impossible to do so.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ k $ ( $ 1 \le n \le 100, 1 \le k \le 10^{12} $ ) — the length of the string and the size of the set, correspondingly. The second line of the input contains a string $ s $ consisting of $ n $ lowercase Latin letters.

输出格式


Print one integer — if it is impossible to obtain the set $ S $ of size $ k $ , print -1. Otherwise, print the minimum possible total cost to do it.

输入输出样例

输入样例 #1

4 5
asdf

输出样例 #1

4

输入样例 #2

5 6
aaaaa

输出样例 #2

15

输入样例 #3

5 7
aaaaa

输出样例 #3

-1

输入样例 #4

10 100
ajihiushda

输出样例 #4

233

说明

In the first example we can generate $ S $ = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in $ S $ is $ 0 $ and the cost of the others is $ 1 $ . So the total cost of $ S $ is $ 4 $ .