#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e60;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
inline char mygetchar() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
template <typename T>
void chkmax(T &x, const T &y) {
  if (y > x) x = y;
  return;
}
template <typename T>
void chkmin(T &x, const T &y) {
  if (y < x) x = y;
  return;
}
void TZL();
void RANK1();
int main() {
  TZL();
  RANK1();
  return 0;
}
const int N = 1e5 + 100;
int *s[N];
int apr[N], tot, clk;
struct sam {
  struct edge {
    sam *to;
    edge *next;
  };
  set<int> all;
  sam *ch[27], *par, *son;
  int id, cnt, mx, siz;
  int dfn, End;
  edge *head;
  bool vis;
  sam() {
    for (int i = 0, _end_ = (27); i < _end_; ++i) ch[i] = 0;
    par = 0;
    id = -1;
    cnt = mx = 0;
    head = 0;
    vis = 0;
    all.clear();
  }
  void cpy(sam *x) {
    memcpy((ch), (x->ch), sizeof((x->ch)));
    par = x->par;
    return;
  }
  void expand(int e, int ID = -1);
  void add_edge(sam *u) {
    edge *e = new edge;
    e->next = head;
    e->to = u;
    head = e;
    return;
  }
  void make_graph() {
    if (vis) return;
    vis = 1;
    if (par) par->add_edge(this);
    for (int i = 0, _end_ = (27); i < _end_; ++i)
      if (ch[i]) ch[i]->make_graph();
    return;
  }
  void pre_dfs();
  void dfs(bool keep = 0);
} * root, *last;
sam **rdfn;
void sam::expand(int e, int ID) {
  sam *p = last, *np = new sam;
  np->mx = p->mx + 1;
  np->id = ID;
  while (p && !p->ch[e]) p->ch[e] = np, p = p->par;
  if (!p)
    np->par = root;
  else {
    sam *q = p->ch[e];
    if (q->mx == p->mx + 1)
      np->par = q;
    else {
      sam *nq = new sam;
      nq->cpy(q);
      nq->mx = p->mx + 1;
      q->par = np->par = nq;
      while (p && p->ch[e] == q) p->ch[e] = nq, p = p->par;
    }
  }
  last = np;
  return;
}
void sam::pre_dfs() {
  int hs = 0;
  siz = 1;
  son = 0;
  dfn = (++clk);
  for (auto e = head; e; e = e->next) {
    e->to->pre_dfs();
    siz += e->to->siz;
    if (e->to->siz > hs) {
      hs = e->to->siz;
      son = e->to;
    }
  }
  End = clk;
  return;
}
void sam::dfs(bool keep) {
  for (auto e = head; e; e = e->next) e->to->dfs();
  if (son) {
    all = son->all;
    for (auto e = head; e; e = e->next)
      if (e->to != son) all.insert(e->to->all.begin(), e->to->all.end());
  }
  if (~id) all.insert(id);
  cnt = (int)all.size();
  return;
}
int n, k;
void TZL() {
  root = new sam;
  last = root;
  scf(n, k);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    static char t[N];
    scanf("%s", t);
    int l = strlen(t);
    s[i] = new int[l + 1];
    for (int j = 0, _end_ = (l); j < _end_; ++j)
      last->expand(s[i][j] = (t[j] - 'a'), i);
    last->expand(s[i][l] = 26);
  }
  root->make_graph();
  root->pre_dfs();
  rdfn = new sam *[clk + 10];
  root->dfs();
  return;
}
void RANK1() {
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    long long ans = 0;
    sam *cur = root;
    int matched = 0;
    for (int j = 0; s[i][j] < 26; ++j) {
      int &e = s[i][j];
      while (cur && !cur->ch[e]) cur = cur->par, matched = cur ? cur->mx : 0;
      if (!cur) {
        cur = root;
        matched = 0;
      } else {
        cur = cur->ch[e];
        ++matched;
      }
      while (cur && cur->cnt < k) cur = cur->par, matched = cur ? cur->mx : 0;
      ans += (long long)matched;
    }
    printf("%lld ", ans);
  }
  return;
}

### Prompt

Generate a CPP solution to the following problem:

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;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e60;
template <typename T>
inline void scf(T &x) {
  bool f = 0;
  x = 0;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  if (f) x = -x;
  return;
}
template <typename T1, typename T2>
void scf(T1 &x, T2 &y) {
  scf(x);
  return scf(y);
}
template <typename T1, typename T2, typename T3>
void scf(T1 &x, T2 &y, T3 &z) {
  scf(x);
  scf(y);
  return scf(z);
}
template <typename T1, typename T2, typename T3, typename T4>
void scf(T1 &x, T2 &y, T3 &z, T4 &w) {
  scf(x);
  scf(y);
  scf(z);
  return scf(w);
}
inline char mygetchar() {
  char c = getchar();
  while (c == ' ' || c == '\n') c = getchar();
  return c;
}
template <typename T>
void chkmax(T &x, const T &y) {
  if (y > x) x = y;
  return;
}
template <typename T>
void chkmin(T &x, const T &y) {
  if (y < x) x = y;
  return;
}
void TZL();
void RANK1();
int main() {
  TZL();
  RANK1();
  return 0;
}
const int N = 1e5 + 100;
int *s[N];
int apr[N], tot, clk;
struct sam {
  struct edge {
    sam *to;
    edge *next;
  };
  set<int> all;
  sam *ch[27], *par, *son;
  int id, cnt, mx, siz;
  int dfn, End;
  edge *head;
  bool vis;
  sam() {
    for (int i = 0, _end_ = (27); i < _end_; ++i) ch[i] = 0;
    par = 0;
    id = -1;
    cnt = mx = 0;
    head = 0;
    vis = 0;
    all.clear();
  }
  void cpy(sam *x) {
    memcpy((ch), (x->ch), sizeof((x->ch)));
    par = x->par;
    return;
  }
  void expand(int e, int ID = -1);
  void add_edge(sam *u) {
    edge *e = new edge;
    e->next = head;
    e->to = u;
    head = e;
    return;
  }
  void make_graph() {
    if (vis) return;
    vis = 1;
    if (par) par->add_edge(this);
    for (int i = 0, _end_ = (27); i < _end_; ++i)
      if (ch[i]) ch[i]->make_graph();
    return;
  }
  void pre_dfs();
  void dfs(bool keep = 0);
} * root, *last;
sam **rdfn;
void sam::expand(int e, int ID) {
  sam *p = last, *np = new sam;
  np->mx = p->mx + 1;
  np->id = ID;
  while (p && !p->ch[e]) p->ch[e] = np, p = p->par;
  if (!p)
    np->par = root;
  else {
    sam *q = p->ch[e];
    if (q->mx == p->mx + 1)
      np->par = q;
    else {
      sam *nq = new sam;
      nq->cpy(q);
      nq->mx = p->mx + 1;
      q->par = np->par = nq;
      while (p && p->ch[e] == q) p->ch[e] = nq, p = p->par;
    }
  }
  last = np;
  return;
}
void sam::pre_dfs() {
  int hs = 0;
  siz = 1;
  son = 0;
  dfn = (++clk);
  for (auto e = head; e; e = e->next) {
    e->to->pre_dfs();
    siz += e->to->siz;
    if (e->to->siz > hs) {
      hs = e->to->siz;
      son = e->to;
    }
  }
  End = clk;
  return;
}
void sam::dfs(bool keep) {
  for (auto e = head; e; e = e->next) e->to->dfs();
  if (son) {
    all = son->all;
    for (auto e = head; e; e = e->next)
      if (e->to != son) all.insert(e->to->all.begin(), e->to->all.end());
  }
  if (~id) all.insert(id);
  cnt = (int)all.size();
  return;
}
int n, k;
void TZL() {
  root = new sam;
  last = root;
  scf(n, k);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    static char t[N];
    scanf("%s", t);
    int l = strlen(t);
    s[i] = new int[l + 1];
    for (int j = 0, _end_ = (l); j < _end_; ++j)
      last->expand(s[i][j] = (t[j] - 'a'), i);
    last->expand(s[i][l] = 26);
  }
  root->make_graph();
  root->pre_dfs();
  rdfn = new sam *[clk + 10];
  root->dfs();
  return;
}
void RANK1() {
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    long long ans = 0;
    sam *cur = root;
    int matched = 0;
    for (int j = 0; s[i][j] < 26; ++j) {
      int &e = s[i][j];
      while (cur && !cur->ch[e]) cur = cur->par, matched = cur ? cur->mx : 0;
      if (!cur) {
        cur = root;
        matched = 0;
      } else {
        cur = cur->ch[e];
        ++matched;
      }
      while (cur && cur->cnt < k) cur = cur->par, matched = cur ? cur->mx : 0;
      ans += (long long)matched;
    }
    printf("%lld ", ans);
  }
  return;
}

```