#include <bits/stdc++.h>
using namespace std;
int m, n, j, k, l, i, o, p, __t, S[230000], N[230000], Len,
    DivideNum(300), MostRight[230000];
long long Final[230000];
char ch, Read[230000];
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
struct SuffixArray {
  int *x, *y, X[230000], Y[230000], Tot[230000], SA[230000], Rank[230000],
      Height[230000], Diff;
  int Mini[230000][20], Two[230000];
  void Prepare() {
    for (int i = (0); i <= (Len - 1); i++) Mini[i][0] = Height[i];
    for (int i = 2, j = 1; i <= Len; i <<= 1, j++)
      for (int s = 0; s + i <= Len; s++)
        Mini[s][j] = min(Mini[s][j - 1], Mini[s + (i >> 1)][j - 1]);
    Two[1] = 0;
    for (int i = 1; i < Len + 10; i++) {
      Two[i] = Two[i - 1];
      if ((1 << (Two[i] + 1)) == i) Two[i]++;
    }
  }
  int Calc(int Lef, int Rig) {
    int Len = Two[Rig - Lef + 1];
    if (Lef > Rig) return 2000000000;
    return min(Mini[Lef][Len], Mini[Rig - (1 << Len) + 1][Len]);
  }
  void DA() {
    Diff = DivideNum + 10;
    x = X, y = Y;
    S[Len] = -1;
    for (int i = (0); i <= (Len - 1); i++) Tot[x[i] = S[i]]++;
    for (int i = (1); i <= (Diff - 1); i++) Tot[i] += Tot[i - 1];
    for (int i = (0); i <= (Len - 1); i++) SA[--Tot[x[i]]] = i;
    for (int p = 1, j = 1; p < Len; j <<= 1, Diff = p) {
      p = 0;
      for (int i = (Len - j); i <= (Len - 1); i++) y[p++] = i;
      for (int i = (0); i <= (Len - 1); i++)
        if (SA[i] >= j) y[p++] = SA[i] - j;
      for (int i = (0); i <= (Diff - 1); i++) Tot[i] = 0;
      for (int i = (0); i <= (Len - 1); i++) Tot[x[y[i]]]++;
      for (int i = (1); i <= (Diff - 1); i++) Tot[i] += Tot[i - 1];
      for (int i = (Len - 1); i >= (0); i--) SA[--Tot[x[y[i]]]] = y[i];
      swap(x, y);
      p = 1, x[SA[0]] = 0;
      for (int i = (1); i <= (Len - 1); i++) {
        int a1 = y[SA[i]], a2 = (SA[i] + j < Len) ? (y[SA[i] + j]) : (-100);
        int b1 = y[SA[i - 1]],
            b2 = (SA[i - 1] + j < Len) ? (y[SA[i - 1] + j]) : (-100);
        if (a1 == b1 && a2 == b2)
          x[SA[i]] = p - 1;
        else
          x[SA[i]] = p++;
      }
    }
    for (int i = (0); i <= (Len - 1); i++) Rank[SA[i]] = i;
    int K = 0;
    for (int i = (0); i <= (Len - 1); i++) {
      if (Rank[i] == 0)
        K = 0;
      else {
        K -= (K > 0);
        for (; S[i + K] == S[SA[Rank[i] - 1] + K]; K++)
          ;
      }
      Height[Rank[i]] = K;
    }
    Prepare();
  }
} suffix;
struct DiffrentNumQ {
  int Ans[230000], Place[230000];
  map<int, int> Number;
  map<int, int>::iterator Dele;
  void AddNumber(int N, int P) {
    if (Place[N] != -1) {
      Dele = Number.lower_bound(Place[N]);
      Number.erase(Dele);
    }
    Number[P] = N;
    Place[N] = P;
  }
  void DeleteNumber() {
    if (Number.size() > n) {
      Dele = Number.begin();
      Place[Dele->second] = -1;
      Number.erase(Dele);
    }
  }
  void Solve() {
    memset(Place, -1, sizeof Place);
    for (int i = (0); i <= (Len - 1); i++) {
      if (N[suffix.SA[i]]) {
        AddNumber(N[suffix.SA[i]], i + 1);
        DeleteNumber();
      }
      if (Number.size() == n)
        Ans[i] = (Number.begin())->first - 1;
      else
        Ans[i] = -1;
    }
  }
} DifferentNum;
bool Check(int St, int Limit) {
  int R = St, L = St;
  for (int lef = R, rig = Len - 1; lef <= rig;) {
    int mid = (lef + rig) / 2;
    if (suffix.Calc(St + 1, mid) >= Limit)
      R = mid, lef = mid + 1;
    else
      rig = mid - 1;
  }
  for (int lef = 0, rig = St; lef <= rig;) {
    int mid = (lef + rig) / 2;
    if (suffix.Calc(mid + 1, St) >= Limit)
      L = mid, rig = mid - 1;
    else
      lef = mid + 1;
  }
  return DifferentNum.Ans[R] >= L;
}
int main() {
  read(m), read(n);
  for (int i = (1); i <= (m); i++) {
    scanf("%s", Read + 1);
    for (int j = 1; Read[j]; j++) S[Len++] = Read[j], N[Len - 1] = i;
    MostRight[i] = Len;
    S[Len++] = ++DivideNum;
  }
  suffix.DA();
  DifferentNum.Solve();
  for (int i = (0); i <= (Len - 1); i++)
    if (N[suffix.SA[i]]) {
      int Expend = 0;
      for (int lef = 0, rig = MostRight[N[suffix.SA[i]]] - suffix.SA[i];
           lef <= rig;) {
        int mid = (lef + rig) / 2;
        if (Check(i, mid))
          Expend = mid, lef = mid + 1;
        else
          rig = mid - 1;
      }
      Final[N[suffix.SA[i]]] += (long long)Expend;
    }
  for (int i = (1); i <= (m); i++) printf("%I64d ", Final[i]);
}

### Prompt

Please formulate 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;
int m, n, j, k, l, i, o, p, __t, S[230000], N[230000], Len,
    DivideNum(300), MostRight[230000];
long long Final[230000];
char ch, Read[230000];
void read(int &a) {
  for (ch = getchar(); (ch < '0' || ch > '9') && (ch != '-'); ch = getchar())
    ;
  if (ch == '-')
    a = 0, __t = -1;
  else
    a = ch - '0', __t = 1;
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    a = a * 10 + ch - '0';
  a *= __t;
}
struct SuffixArray {
  int *x, *y, X[230000], Y[230000], Tot[230000], SA[230000], Rank[230000],
      Height[230000], Diff;
  int Mini[230000][20], Two[230000];
  void Prepare() {
    for (int i = (0); i <= (Len - 1); i++) Mini[i][0] = Height[i];
    for (int i = 2, j = 1; i <= Len; i <<= 1, j++)
      for (int s = 0; s + i <= Len; s++)
        Mini[s][j] = min(Mini[s][j - 1], Mini[s + (i >> 1)][j - 1]);
    Two[1] = 0;
    for (int i = 1; i < Len + 10; i++) {
      Two[i] = Two[i - 1];
      if ((1 << (Two[i] + 1)) == i) Two[i]++;
    }
  }
  int Calc(int Lef, int Rig) {
    int Len = Two[Rig - Lef + 1];
    if (Lef > Rig) return 2000000000;
    return min(Mini[Lef][Len], Mini[Rig - (1 << Len) + 1][Len]);
  }
  void DA() {
    Diff = DivideNum + 10;
    x = X, y = Y;
    S[Len] = -1;
    for (int i = (0); i <= (Len - 1); i++) Tot[x[i] = S[i]]++;
    for (int i = (1); i <= (Diff - 1); i++) Tot[i] += Tot[i - 1];
    for (int i = (0); i <= (Len - 1); i++) SA[--Tot[x[i]]] = i;
    for (int p = 1, j = 1; p < Len; j <<= 1, Diff = p) {
      p = 0;
      for (int i = (Len - j); i <= (Len - 1); i++) y[p++] = i;
      for (int i = (0); i <= (Len - 1); i++)
        if (SA[i] >= j) y[p++] = SA[i] - j;
      for (int i = (0); i <= (Diff - 1); i++) Tot[i] = 0;
      for (int i = (0); i <= (Len - 1); i++) Tot[x[y[i]]]++;
      for (int i = (1); i <= (Diff - 1); i++) Tot[i] += Tot[i - 1];
      for (int i = (Len - 1); i >= (0); i--) SA[--Tot[x[y[i]]]] = y[i];
      swap(x, y);
      p = 1, x[SA[0]] = 0;
      for (int i = (1); i <= (Len - 1); i++) {
        int a1 = y[SA[i]], a2 = (SA[i] + j < Len) ? (y[SA[i] + j]) : (-100);
        int b1 = y[SA[i - 1]],
            b2 = (SA[i - 1] + j < Len) ? (y[SA[i - 1] + j]) : (-100);
        if (a1 == b1 && a2 == b2)
          x[SA[i]] = p - 1;
        else
          x[SA[i]] = p++;
      }
    }
    for (int i = (0); i <= (Len - 1); i++) Rank[SA[i]] = i;
    int K = 0;
    for (int i = (0); i <= (Len - 1); i++) {
      if (Rank[i] == 0)
        K = 0;
      else {
        K -= (K > 0);
        for (; S[i + K] == S[SA[Rank[i] - 1] + K]; K++)
          ;
      }
      Height[Rank[i]] = K;
    }
    Prepare();
  }
} suffix;
struct DiffrentNumQ {
  int Ans[230000], Place[230000];
  map<int, int> Number;
  map<int, int>::iterator Dele;
  void AddNumber(int N, int P) {
    if (Place[N] != -1) {
      Dele = Number.lower_bound(Place[N]);
      Number.erase(Dele);
    }
    Number[P] = N;
    Place[N] = P;
  }
  void DeleteNumber() {
    if (Number.size() > n) {
      Dele = Number.begin();
      Place[Dele->second] = -1;
      Number.erase(Dele);
    }
  }
  void Solve() {
    memset(Place, -1, sizeof Place);
    for (int i = (0); i <= (Len - 1); i++) {
      if (N[suffix.SA[i]]) {
        AddNumber(N[suffix.SA[i]], i + 1);
        DeleteNumber();
      }
      if (Number.size() == n)
        Ans[i] = (Number.begin())->first - 1;
      else
        Ans[i] = -1;
    }
  }
} DifferentNum;
bool Check(int St, int Limit) {
  int R = St, L = St;
  for (int lef = R, rig = Len - 1; lef <= rig;) {
    int mid = (lef + rig) / 2;
    if (suffix.Calc(St + 1, mid) >= Limit)
      R = mid, lef = mid + 1;
    else
      rig = mid - 1;
  }
  for (int lef = 0, rig = St; lef <= rig;) {
    int mid = (lef + rig) / 2;
    if (suffix.Calc(mid + 1, St) >= Limit)
      L = mid, rig = mid - 1;
    else
      lef = mid + 1;
  }
  return DifferentNum.Ans[R] >= L;
}
int main() {
  read(m), read(n);
  for (int i = (1); i <= (m); i++) {
    scanf("%s", Read + 1);
    for (int j = 1; Read[j]; j++) S[Len++] = Read[j], N[Len - 1] = i;
    MostRight[i] = Len;
    S[Len++] = ++DivideNum;
  }
  suffix.DA();
  DifferentNum.Solve();
  for (int i = (0); i <= (Len - 1); i++)
    if (N[suffix.SA[i]]) {
      int Expend = 0;
      for (int lef = 0, rig = MostRight[N[suffix.SA[i]]] - suffix.SA[i];
           lef <= rig;) {
        int mid = (lef + rig) / 2;
        if (Check(i, mid))
          Expend = mid, lef = mid + 1;
        else
          rig = mid - 1;
      }
      Final[N[suffix.SA[i]]] += (long long)Expend;
    }
  for (int i = (1); i <= (m); i++) printf("%I64d ", Final[i]);
}

```