#include using namespace std; #define ll long long #define FOR(i, j, k, in) for (int i=j; i=k; i-=in) #define REP(i, j) FOR(i, 0, j, 1) #define RREP(i, j) FOR(i, j, 0, 1) #define ALL(a) a.begin(), a.end() #define RALL(a) a.end(), a.begin() #define F first #define S second #define PB push_back #define MP make_pair #define pii pair #define MOD 1000000007 ll total=0; struct trie { int words=0; int ends=0; vector sons = vector(26, NULL); }; void insertw(string a, trie * t) { t->words=0; REP(i, a.size()) { total += t->words; t->words++; if (t->sons[a[i] - 'a'] == NULL) { t->sons[a[i] - 'a'] = new trie; } t = t->sons[a[i] - 'a']; } total += t->words; t->words++; t->ends++; } void deletew(string a, trie * t) { t->words=1; REP(i, a.size()) { t->words--; total -= t->words; t = t->sons[a[i] - 'a']; } t->words--; total -= t->words; t->ends--; } void solve() { ll n, k; cin >> n >> k; vector st(n); ll m=0; REP(i, n) { cin >> st[i]; m = max(m, (ll) st[i].size()); } int s=0, e=0; ll res=0; trie t; while (true) { if (total < k) { if (e == n) { break; } insertw(st[e], &t); e++; } else { // cout << s << e << endl; deletew(st[s], &t); s++; res += n-e+1; } // cout << total << endl; // REP(i, 26) { // // cout << (char)('a' + i); // } // // cout << endl; // REP(j, m) { // REP(i, 26) { // // cout << totals[j][i]; // } // // cout << endl; // } } cout << res << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n=1; // cin >> n; REP(i, n) { solve(); } return 0; }