#include <bits/stdc++.h>
using namespace std;
int T[300100][30], cnt = 0, val[300100], fa[300100];
string s, t, ss[300010], tt;
vector<int> g[300100];
queue<int> q;
void insert(int x, int n, int f) {
  if (x == n) {
    val[f]++;
    return;
  }
  int v = s[x] - 'a';
  if (T[f][v] == 0) T[f][v] = ++cnt;
  insert(x + 1, n, T[f][v]);
}
void build() {
  int i, v, u;
  for (i = 0; i < 27; i++) {
    if (T[0][i]) {
      q.push(T[0][i]);
      fa[T[0][i]] = 0;
      g[0].push_back(T[0][i]);
    }
  }
  for (; q.size(); q.pop()) {
    u = q.front();
    for (i = 0; i < 27; i++) {
      v = T[u][i];
      if (v == 0)
        T[u][i] = T[fa[u]][i];
      else {
        fa[v] = T[fa[u]][i];
        g[fa[v]].push_back(v);
        q.push(v);
      }
    }
  }
}
void dfs(int u) {
  int i, v;
  for (i = 0; i < g[u].size(); i++) {
    v = g[u][i];
    val[v] += val[u];
    dfs(v);
  }
}
long long A[300010], B[300010];
int main() {
  int j, v, i, n, m;
  cin >> tt;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) cin >> ss[i];
  for (i = 1; i <= m; i++) {
    s = "";
    for (j = 0; j < ss[i].size(); j++) s += ss[i][j];
    insert(0, s.size(), 0);
  }
  build();
  dfs(0);
  int p = 0;
  t = tt;
  for (i = 0; i < t.size(); i++) {
    v = t[i] - 'a';
    p = T[p][v];
    A[i] = val[p];
  }
  memset(T, 0, sizeof(T));
  memset(fa, 0, sizeof(fa));
  memset(val, 0, sizeof(val));
  for (i = 0; i <= 200000; i++) g[i].clear();
  cnt = 0;
  for (i = 1; i <= m; i++) {
    s = "";
    for (j = ss[i].size() - 1; j >= 0; j--) s += ss[i][j];
    insert(0, s.size(), 0);
  }
  build();
  dfs(0);
  p = 0;
  t = "";
  for (i = tt.size() - 1; i >= 0; i--) t += tt[i];
  for (i = 0; i < t.size(); i++) {
    v = t[i] - 'a';
    p = T[p][v];
    B[i] = val[p];
  }
  long long ans = 0, x;
  for (i = 0; i < t.size(); i++) {
    x = i + 1;
    x = t.size() - 1 - x;
    if (x >= 0) ans += A[i] * B[x];
  }
  cout << ans << endl;
  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;
int T[300100][30], cnt = 0, val[300100], fa[300100];
string s, t, ss[300010], tt;
vector<int> g[300100];
queue<int> q;
void insert(int x, int n, int f) {
  if (x == n) {
    val[f]++;
    return;
  }
  int v = s[x] - 'a';
  if (T[f][v] == 0) T[f][v] = ++cnt;
  insert(x + 1, n, T[f][v]);
}
void build() {
  int i, v, u;
  for (i = 0; i < 27; i++) {
    if (T[0][i]) {
      q.push(T[0][i]);
      fa[T[0][i]] = 0;
      g[0].push_back(T[0][i]);
    }
  }
  for (; q.size(); q.pop()) {
    u = q.front();
    for (i = 0; i < 27; i++) {
      v = T[u][i];
      if (v == 0)
        T[u][i] = T[fa[u]][i];
      else {
        fa[v] = T[fa[u]][i];
        g[fa[v]].push_back(v);
        q.push(v);
      }
    }
  }
}
void dfs(int u) {
  int i, v;
  for (i = 0; i < g[u].size(); i++) {
    v = g[u][i];
    val[v] += val[u];
    dfs(v);
  }
}
long long A[300010], B[300010];
int main() {
  int j, v, i, n, m;
  cin >> tt;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) cin >> ss[i];
  for (i = 1; i <= m; i++) {
    s = "";
    for (j = 0; j < ss[i].size(); j++) s += ss[i][j];
    insert(0, s.size(), 0);
  }
  build();
  dfs(0);
  int p = 0;
  t = tt;
  for (i = 0; i < t.size(); i++) {
    v = t[i] - 'a';
    p = T[p][v];
    A[i] = val[p];
  }
  memset(T, 0, sizeof(T));
  memset(fa, 0, sizeof(fa));
  memset(val, 0, sizeof(val));
  for (i = 0; i <= 200000; i++) g[i].clear();
  cnt = 0;
  for (i = 1; i <= m; i++) {
    s = "";
    for (j = ss[i].size() - 1; j >= 0; j--) s += ss[i][j];
    insert(0, s.size(), 0);
  }
  build();
  dfs(0);
  p = 0;
  t = "";
  for (i = tt.size() - 1; i >= 0; i--) t += tt[i];
  for (i = 0; i < t.size(); i++) {
    v = t[i] - 'a';
    p = T[p][v];
    B[i] = val[p];
  }
  long long ans = 0, x;
  for (i = 0; i < t.size(); i++) {
    x = i + 1;
    x = t.size() - 1 - x;
    if (x >= 0) ans += A[i] * B[x];
  }
  cout << ans << endl;
  return 0;
}

```