#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
template <class T>
void mini(T &l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T &l, T r) {
  l = max(l, r);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  os << "[";
  for (auto vv : v) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> p) {
  return os << "(" << p.first << "," << p.second << ")";
}
using llint = long long;
const int N = 2e5 + 10;
set<int> *merge(set<int> *a, set<int> *b) {
  if (a->size() < b->size()) swap(a, b);
  a->insert((*b).begin(), (*b).end());
  delete b;
  return a;
}
struct Node {
  Node *go[27], *par;
  int val, id;
  vector<Node *> ch;
  Node() {
    memset(go, 0, sizeof(go));
    val = 0;
    par = 0;
    id = -1;
  }
  int n_include;
  set<int> *dfs() {
    set<int> *st = new set<int>();
    if (id != -1) st->insert(id);
    for (auto it = ch.begin(); it != ch.end(); ++it) {
      st = merge(st, (*it)->dfs());
    }
    n_include = st->size();
    return st;
  }
};
Node pool[N * 2 + 10], *cur = pool;
Node *root, *last;
void init() { root = last = cur++; }
void extend(int w, int id = -1) {
  Node *p = last, *np = cur++;
  np->val = p->val + 1;
  np->id = id;
  while (p && p->go[w] == 0) p->go[w] = np, p = p->par;
  if (p == 0) {
    np->par = root;
  } else {
    Node *q = p->go[w];
    if (q->val == p->val + 1)
      np->par = q;
    else {
      Node *nq = cur++;
      memcpy(nq->go, q->go, sizeof(q->go));
      nq->val = p->val + 1;
      nq->par = q->par;
      q->par = np->par = nq;
      while (p && p->go[w] == q) p->go[w] = nq, p = p->par;
    }
  }
  last = np;
}
string a[N];
int n, k;
void run() {
  init();
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (int j = 0; j < a[i].size(); ++j) {
      extend(a[i][j] - 'a', i);
    }
    extend(26);
  }
  for (Node *i = pool; i != cur; ++i) {
    if (i->par) i->par->ch.push_back(i);
  }
  root->dfs();
  for (int i = 0; i < n; ++i) {
    string &s = a[i];
    int l = 0;
    Node *c = root;
    llint ans = 0;
    for (int j = 0; j < s.size(); ++j) {
      int w = s[j] - 'a';
      while (c && c->go[w] == 0) {
        c = c->par;
        if (c) l = c->val;
      }
      if (c) {
        c = c->go[w];
        ++l;
      } else {
        c = root;
        l = 0;
      }
      while (c && c->n_include < k) {
        c = c->par;
        if (c)
          l = c->val;
        else
          l = 0;
      }
      ans += l;
    }
    cout << ans << " ";
  }
  cout << endl;
}
int main() {
  run();
  return 0;
}

### Prompt

Develop a solution in cpp to the problem described below:

The Little Elephant loves strings very much. 

He has an array a from n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n, then let's denote the element number i as ai. For each string ai (1 ≤ i ≤ n) the Little Elephant wants to find the number of pairs of integers l and r (1 ≤ l ≤ r ≤ |ai|) such that substring ai[l... r] is a substring to at least k strings from array a (including the i-th string).

Help the Little Elephant solve this problem.

If you are not familiar with the basic notation in string problems, you can find the corresponding definitions in the notes.

Input

The first line contains two space-separated integers — n and k (1 ≤ n, k ≤ 105). Next n lines contain array a. The i-th line contains a non-empty string ai, consisting of lowercase English letter. The total length of all strings ai does not exceed 105.

Output

On a single line print n space-separated integers — the i-th number is the answer for string ai.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3 1
abc
a
ab


Output

6 1 3 


Input

7 4
rubik
furik
abab
baba
aaabbbababa
abababababa
zero


Output

1 0 9 9 21 30 0 

Note

Let's assume that you are given string a = a1a2... a|a|, then let's denote the string's length as |a| and the string's i-th character as ai.

A substring a[l... r] (1 ≤ l ≤ r ≤ |a|) of string a is string alal + 1... ar.

String a is a substring of string b, if there exists such pair of integers l and r (1 ≤ l ≤ r ≤ |b|), that b[l... r] = a.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using namespace placeholders;
template <class T>
void mini(T &l, T r) {
  l = min(l, r);
}
template <class T>
void maxi(T &l, T r) {
  l = max(l, r);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> v) {
  os << "[";
  for (auto vv : v) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> p) {
  return os << "(" << p.first << "," << p.second << ")";
}
using llint = long long;
const int N = 2e5 + 10;
set<int> *merge(set<int> *a, set<int> *b) {
  if (a->size() < b->size()) swap(a, b);
  a->insert((*b).begin(), (*b).end());
  delete b;
  return a;
}
struct Node {
  Node *go[27], *par;
  int val, id;
  vector<Node *> ch;
  Node() {
    memset(go, 0, sizeof(go));
    val = 0;
    par = 0;
    id = -1;
  }
  int n_include;
  set<int> *dfs() {
    set<int> *st = new set<int>();
    if (id != -1) st->insert(id);
    for (auto it = ch.begin(); it != ch.end(); ++it) {
      st = merge(st, (*it)->dfs());
    }
    n_include = st->size();
    return st;
  }
};
Node pool[N * 2 + 10], *cur = pool;
Node *root, *last;
void init() { root = last = cur++; }
void extend(int w, int id = -1) {
  Node *p = last, *np = cur++;
  np->val = p->val + 1;
  np->id = id;
  while (p && p->go[w] == 0) p->go[w] = np, p = p->par;
  if (p == 0) {
    np->par = root;
  } else {
    Node *q = p->go[w];
    if (q->val == p->val + 1)
      np->par = q;
    else {
      Node *nq = cur++;
      memcpy(nq->go, q->go, sizeof(q->go));
      nq->val = p->val + 1;
      nq->par = q->par;
      q->par = np->par = nq;
      while (p && p->go[w] == q) p->go[w] = nq, p = p->par;
    }
  }
  last = np;
}
string a[N];
int n, k;
void run() {
  init();
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    for (int j = 0; j < a[i].size(); ++j) {
      extend(a[i][j] - 'a', i);
    }
    extend(26);
  }
  for (Node *i = pool; i != cur; ++i) {
    if (i->par) i->par->ch.push_back(i);
  }
  root->dfs();
  for (int i = 0; i < n; ++i) {
    string &s = a[i];
    int l = 0;
    Node *c = root;
    llint ans = 0;
    for (int j = 0; j < s.size(); ++j) {
      int w = s[j] - 'a';
      while (c && c->go[w] == 0) {
        c = c->par;
        if (c) l = c->val;
      }
      if (c) {
        c = c->go[w];
        ++l;
      } else {
        c = root;
        l = 0;
      }
      while (c && c->n_include < k) {
        c = c->par;
        if (c)
          l = c->val;
        else
          l = 0;
      }
      ans += l;
    }
    cout << ans << " ";
  }
  cout << endl;
}
int main() {
  run();
  return 0;
}

```