func_code_string: #include <bits/stdc++.h>   #pragma GCC optimize( Ofast,no-stack-protector )   #pragma GCC target(         sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( fast-math )   using namespace std;   const int INF = 1e9 + 9;   const long long MAXN = 2e5 + 7;   const long long MAXN1 = 1 << 10;   const long long MAXN2 = 1e6 + 7;   const long long MOD = 1e9 + 7;   const long long PW = 239;   const long long BLOCK = 316;   void solve();   mt19937 mt(1e9 + 7);   signed main() {     srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 );     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     if (0) cin >> q;     while (q--) solve();   }   long long dp[MAXN1][MAXN1];   int last[MAXN1];   void solve() {     memset(last, -1, sizeof last);     long long n, k;     string s;     cin >> n >> k >> s;     dp[0][0] = 1;     dp[0][1] = 1;     last[s[0] -  a ] = 0;     for (int i = 1; i < s.size(); ++i) {       dp[i][1] = 1;       for (int j = 2; j <= s.size(); ++j) {         for (int t = 0; t < 26; ++t) {           if (last[t] == -1) continue;           dp[i][j] += dp[last[t]][j - 1];           dp[i][j] = min<long long>(dp[i][j], 1e13);         }       }       last[s[i] -  a ] = i;     }     long long ans = 0;     for (long long i = n; i >= 0; --i) {       if (i == 0) {         long long tmp = min(k, 1ll);         ans += (n - i) * tmp;         k -= tmp;         break;       }       for (int j = 0; j < 26; ++j) {         if (last[j] == -1) continue;         long long tmp = min(k, dp[last[j]][i]);         ans += (n - i) * tmp;         k -= tmp;       }     }     if (k != 0) ans = -1;     cout << ans;   }   