#include <bits/stdc++.h>
using namespace std;
const int N = 400004;
int n, m, S = 448, Z[N], ri[N], le[N], node = 1, nodeReverse = 1;
string s, t;
struct hm {
  int ch[30], finish;
  hm() { finish = 0; }
};
hm trie[N], trieReverse[N];
void process1() {
  string keep = s + t;
  int l = keep.length();
  int L = 0, R = 0;
  Z[0] = l;
  for (int i = 1; i < l; i++) {
    if (i > R) {
      L = R = i;
      while (R < l && keep[R] == keep[R - L]) R++;
      Z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < l && keep[R - L] == keep[R]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  }
  L = s.length();
  for (int i = L; i < l; i++) {
    if (Z[i] >= L) ri[i - L + 1]++;
  }
  keep = t + s;
  for (int i = 0; i < l / 2; i++) {
    swap(keep[i], keep[l - i - 1]);
  }
  L = 0, R = 0;
  Z[0] = l;
  for (int i = 1; i < l; i++) {
    if (i > R) {
      L = R = i;
      while (R < l && keep[R] == keep[R - L]) R++;
      Z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < l && keep[R - L] == keep[R]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  }
  L = s.length();
  for (int i = L; i < l; i++) {
    if (Z[i] >= L) {
      le[m - (i - L)]++;
    }
  }
}
void Push() {
  int u = 1;
  for (int i = 0; i < s.length(); i++) {
    if (trie[u].ch[s[i] - 'a' + 1] == 0) trie[u].ch[s[i] - 'a' + 1] = ++node;
    u = trie[u].ch[s[i] - 'a' + 1];
  }
  trie[u].finish++;
  u = 1;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (trieReverse[u].ch[s[i] - 'a' + 1] == 0)
      trieReverse[u].ch[s[i] - 'a' + 1] = ++nodeReverse;
    u = trieReverse[u].ch[s[i] - 'a' + 1];
  }
  trieReverse[u].finish++;
}
void process2() {
  for (int i = 0; i < m; i++) {
    int u = 1;
    for (int j = i; j < m; j++) {
      if (trie[u].ch[t[j] - 'a' + 1] == 0) break;
      u = trie[u].ch[t[j] - 'a' + 1];
      ri[i + 1] += trie[u].finish;
    }
  }
  for (int i = m - 1; i >= 0; i--) {
    int u = 1;
    for (int j = i; j >= 0; j--) {
      if (trieReverse[u].ch[t[j] - 'a' + 1] == 0) break;
      u = trieReverse[u].ch[t[j] - 'a' + 1];
      le[i + 1] += trieReverse[u].finish;
    }
  }
}
int main() {
  cin >> t >> n;
  m = t.length();
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (s.length() >= S)
      process1();
    else
      Push();
  }
  process2();
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    ans += (long long)le[i] * (long long)ri[i + 1];
  }
  cout << ans;
}

### Prompt

Create a solution in CPP for the following problem:

You are given a string t and n strings s_1, s_2, ..., s_n. All strings consist of lowercase Latin letters.

Let f(t, s) be the number of occurences of string s in string t. For example, f('aaabacaa', 'aa') = 3, and f('ababa', 'aba') = 2.

Calculate the value of ∑_{i=1}^{n} ∑_{j=1}^{n} f(t, s_i + s_j), where s + t is the concatenation of strings s and t. Note that if there are two pairs i_1, j_1 and i_2, j_2 such that s_{i_1} + s_{j_1} = s_{i_2} + s_{j_2}, you should include both f(t, s_{i_1} + s_{j_1}) and f(t, s_{i_2} + s_{j_2}) in answer.

Input

The first line contains string t (1 ≤ |t| ≤ 2 ⋅ 10^5).

The second line contains integer n (1 ≤ n ≤ 2 ⋅ 10^5).

Each of next n lines contains string s_i (1 ≤ |s_i| ≤ 2 ⋅ 10^5).

It is guaranteed that ∑_{i=1}^{n} |s_i| ≤ 2 ⋅ 10^5. All strings consist of lowercase English letters.

Output

Print one integer — the value of ∑_{i=1}^{n} ∑_{j=1}^{n} f(t, s_i + s_j).

Examples

Input


aaabacaa
2
a
aa


Output


5


Input


aaabacaa
4
a
a
a
b


Output


33

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 400004;
int n, m, S = 448, Z[N], ri[N], le[N], node = 1, nodeReverse = 1;
string s, t;
struct hm {
  int ch[30], finish;
  hm() { finish = 0; }
};
hm trie[N], trieReverse[N];
void process1() {
  string keep = s + t;
  int l = keep.length();
  int L = 0, R = 0;
  Z[0] = l;
  for (int i = 1; i < l; i++) {
    if (i > R) {
      L = R = i;
      while (R < l && keep[R] == keep[R - L]) R++;
      Z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < l && keep[R - L] == keep[R]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  }
  L = s.length();
  for (int i = L; i < l; i++) {
    if (Z[i] >= L) ri[i - L + 1]++;
  }
  keep = t + s;
  for (int i = 0; i < l / 2; i++) {
    swap(keep[i], keep[l - i - 1]);
  }
  L = 0, R = 0;
  Z[0] = l;
  for (int i = 1; i < l; i++) {
    if (i > R) {
      L = R = i;
      while (R < l && keep[R] == keep[R - L]) R++;
      Z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (Z[k] < R - i + 1)
        Z[i] = Z[k];
      else {
        L = i;
        while (R < l && keep[R - L] == keep[R]) R++;
        Z[i] = R - L;
        R--;
      }
    }
  }
  L = s.length();
  for (int i = L; i < l; i++) {
    if (Z[i] >= L) {
      le[m - (i - L)]++;
    }
  }
}
void Push() {
  int u = 1;
  for (int i = 0; i < s.length(); i++) {
    if (trie[u].ch[s[i] - 'a' + 1] == 0) trie[u].ch[s[i] - 'a' + 1] = ++node;
    u = trie[u].ch[s[i] - 'a' + 1];
  }
  trie[u].finish++;
  u = 1;
  for (int i = s.length() - 1; i >= 0; i--) {
    if (trieReverse[u].ch[s[i] - 'a' + 1] == 0)
      trieReverse[u].ch[s[i] - 'a' + 1] = ++nodeReverse;
    u = trieReverse[u].ch[s[i] - 'a' + 1];
  }
  trieReverse[u].finish++;
}
void process2() {
  for (int i = 0; i < m; i++) {
    int u = 1;
    for (int j = i; j < m; j++) {
      if (trie[u].ch[t[j] - 'a' + 1] == 0) break;
      u = trie[u].ch[t[j] - 'a' + 1];
      ri[i + 1] += trie[u].finish;
    }
  }
  for (int i = m - 1; i >= 0; i--) {
    int u = 1;
    for (int j = i; j >= 0; j--) {
      if (trieReverse[u].ch[t[j] - 'a' + 1] == 0) break;
      u = trieReverse[u].ch[t[j] - 'a' + 1];
      le[i + 1] += trieReverse[u].finish;
    }
  }
}
int main() {
  cin >> t >> n;
  m = t.length();
  for (int i = 1; i <= n; i++) {
    cin >> s;
    if (s.length() >= S)
      process1();
    else
      Push();
  }
  process2();
  long long ans = 0;
  for (int i = 1; i < m; i++) {
    ans += (long long)le[i] * (long long)ri[i + 1];
  }
  cout << ans;
}

```