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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
char t[200005], ss[200005];
string s[200005];
int son[200005][26], fail[200005], last[200005], cnt[200005], tot;
int Q[200005], head, tail;
int pre[200005], suf[200005];
void insert(const char* s) {
  int u = 0;
  for (int i = 0; s[i]; ++i) {
    int& v = son[u][s[i] - 'a'];
    if (!v) v = ++tot;
    u = v;
  }
  ++cnt[u];
}
void AC() {
  fail[0] = 0;
  head = tail = 0;
  for (int i = 0; i < 26; ++i)
    if (son[0][i]) fail[son[0][i]] = 0, Q[tail++] = son[0][i];
  while (head != tail) {
    int u = Q[head++];
    for (int i = 0; i < 26; ++i) {
      int v = son[u][i];
      if (!v) {
        son[u][i] = son[fail[u]][i];
      } else {
        Q[tail++] = v;
        fail[v] = son[fail[u]][i];
        last[v] = cnt[fail[v]] ? fail[v] : last[fail[v]];
      }
    }
  }
}
int get(int u) {
  int ret = 0;
  while (u) {
    ret += cnt[u];
    u = last[u];
  }
  return ret;
}
void cal(int* res, int n) {
  memset(son, 0, sizeof(son));
  memset(cnt, 0, sizeof(cnt));
  memset(last, 0, sizeof(last));
  memset(fail, 0, sizeof(fail));
  tot = 0;
  for (int i = 0; i < n; ++i) insert(s[i].c_str());
  AC();
  int u = 0;
  for (int i = 0; t[i]; ++i) {
    u = son[u][t[i] - 'a'];
    if (cnt[u])
      res[i] = get(u);
    else if (last[u])
      res[i] = get(last[u]);
  }
}
int main() {
  int n;
  scanf("%s", t);
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", ss);
    s[i] = ss;
  }
  cal(pre, n);
  int m = strlen(t);
  reverse(t, t + m);
  for (int i = 0; i < n; ++i) reverse(s[i].begin(), s[i].end());
  cal(suf, n);
  long long ans = 0;
  for (int i = 0; i < m - 1; ++i) ans += 1LL * pre[i] * suf[m - i - 2];
  cout << ans << endl;
  return 0;
}