#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005, maxk = 27;
int n;
int chd[2][maxn][maxk], val[2][maxn], fail[2][maxn], lcs[maxn], lcp[maxn],
    tot[2];
long long ans;
string s, t;
queue<int> q;
void insert(int t, string s) {
  int now = 0;
  for (int i = 0; i < s.size(); now = chd[t][now][s[i] - 96], i++)
    if (chd[t][now][s[i] - 96] == 0) chd[t][now][s[i] - 96] = ++tot[t];
  val[t][now]++;
}
void getfail(int t) {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= 26; i++)
    if (chd[t][0][i]) q.push(chd[t][0][i]), fail[t][chd[t][0][i]] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    val[t][x] += val[t][fail[t][x]];
    for (int i = 1; i <= 26; i++) {
      if (chd[t][x][i])
        q.push(chd[t][x][i]), fail[t][chd[t][x][i]] = chd[t][fail[t][x]][i];
      else
        chd[t][x][i] = chd[t][fail[t][x]][i];
    }
  }
}
void init() {
  int now = 0;
  for (int i = 0; i < s.size(); i++) {
    now = chd[0][now][s[i] - 96];
    lcs[i] = val[0][now];
  }
  now = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    now = chd[1][now][s[i] - 96];
    lcp[i] = val[1][now];
  }
}
int main() {
  tot[0] = tot[1] = 0, cin >> s;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> t, insert(0, t);
    reverse(t.begin(), t.end()), insert(1, t);
  }
  getfail(0), getfail(1), init();
  for (int i = 1; i < s.size(); i++) ans += 1ll * lcs[i - 1] * lcp[i];
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Generate a cpp solution to 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 maxn = 200005, maxk = 27;
int n;
int chd[2][maxn][maxk], val[2][maxn], fail[2][maxn], lcs[maxn], lcp[maxn],
    tot[2];
long long ans;
string s, t;
queue<int> q;
void insert(int t, string s) {
  int now = 0;
  for (int i = 0; i < s.size(); now = chd[t][now][s[i] - 96], i++)
    if (chd[t][now][s[i] - 96] == 0) chd[t][now][s[i] - 96] = ++tot[t];
  val[t][now]++;
}
void getfail(int t) {
  while (!q.empty()) q.pop();
  for (int i = 1; i <= 26; i++)
    if (chd[t][0][i]) q.push(chd[t][0][i]), fail[t][chd[t][0][i]] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    val[t][x] += val[t][fail[t][x]];
    for (int i = 1; i <= 26; i++) {
      if (chd[t][x][i])
        q.push(chd[t][x][i]), fail[t][chd[t][x][i]] = chd[t][fail[t][x]][i];
      else
        chd[t][x][i] = chd[t][fail[t][x]][i];
    }
  }
}
void init() {
  int now = 0;
  for (int i = 0; i < s.size(); i++) {
    now = chd[0][now][s[i] - 96];
    lcs[i] = val[0][now];
  }
  now = 0;
  for (int i = s.size() - 1; i >= 0; i--) {
    now = chd[1][now][s[i] - 96];
    lcp[i] = val[1][now];
  }
}
int main() {
  tot[0] = tot[1] = 0, cin >> s;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> t, insert(0, t);
    reverse(t.begin(), t.end()), insert(1, t);
  }
  getfail(0), getfail(1), init();
  for (int i = 1; i < s.size(); i++) ans += 1ll * lcs[i - 1] * lcp[i];
  printf("%lld\n", ans);
  return 0;
}

```