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;
const int mod = 1e9 + 7;
const int maxm = 2e5 + 10;
int trie1[maxm][27], cntword1[maxm], flag1[maxm], fail1[maxm], last1[maxm],
    ed[maxm], st[maxm];
int trie2[maxm][27], cntword2[maxm], flag2[maxm], fail2[maxm], last2[maxm];
int cnt1, cnt2;
char s[maxm], t[maxm], re[maxm], rr[maxm];
void insert(char ss[], int len) {
  int rt = 0;
  for (int i = 0; i < len; i++) {
    int nxt = ss[i] - 'a';
    if (!trie1[rt][nxt]) trie1[rt][nxt] = ++cnt1;
    rt = trie1[rt][nxt];
  }
  flag1[rt]++;
}
void getfail() {
  queue<int> q;
  for (int i = 0; i < 26; i++) {
    if (trie1[0][i]) {
      fail1[trie1[0][i]] = 0;
      q.push(trie1[0][i]);
    }
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    flag1[now] += flag1[fail1[now]];
    for (int i = 0; i < 26; i++) {
      if (trie1[now][i]) {
        fail1[trie1[now][i]] = trie1[fail1[now]][i];
        q.push(trie1[now][i]);
      } else
        trie1[now][i] = trie1[fail1[now]][i];
    }
  }
}
void query(char ss[]) {
  int now = 0, ans = 0;
  int len = strlen(ss + 1);
  for (int i = 0; i < len; i++) {
    now = trie1[now][ss[i] - 'a'];
    ed[i] += flag1[now];
  }
}
void insert2(char ss[], int len) {
  int rt = 0;
  for (int i = 0; i < len; i++) {
    int nxt = ss[i] - 'a';
    if (!trie2[rt][nxt]) trie2[rt][nxt] = ++cnt2;
    rt = trie2[rt][nxt];
  }
  flag2[rt]++;
}
void getfail2() {
  queue<int> q;
  for (int i = 0; i < 26; i++) {
    if (trie2[0][i]) {
      fail2[trie2[0][i]] = 0;
      q.push(trie2[0][i]);
    }
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    flag2[now] += flag2[fail2[now]];
    for (int i = 0; i < 26; i++) {
      if (trie2[now][i]) {
        fail2[trie2[now][i]] = trie2[fail2[now]][i];
        last2[trie2[now][i]] = flag2[fail2[trie2[now][i]]]
                                   ? fail2[trie2[now][i]]
                                   : last2[fail2[trie2[now][i]]];
        q.push(trie2[now][i]);
      } else
        trie2[now][i] = trie2[fail2[now]][i];
    }
  }
}
void query2(char ss[]) {
  int now = 0, ans = 0;
  int len = strlen(ss);
  for (int i = 0; i < len; i++) {
    now = trie2[now][ss[i] - 'a'];
    st[i] += flag2[now];
  }
}
int main() {
  scanf("%s", s);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t);
    int len = strlen(t);
    insert(t, len);
    for (int i = 0; i < len; i++) {
      re[i] = t[len - i - 1];
    }
    insert2(re, len);
  }
  getfail();
  query(s);
  getfail2();
  int len = strlen(s);
  for (int i = 0; i < len; i++) {
    rr[i] = s[len - i - 1];
  }
  query2(rr);
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    ans = ans + 1ll * ed[i] * st[len - i - 2];
  }
  printf("%I64d\n", ans);
  return 0;
}