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 N = 200010, BL = 447;
int n, m, A[N], B[N];
char s[N], ss[N];
int num[N], len[N], nxt[N];
void kmp(int n, char* a, int m, char* b) {
  int i, j;
  for (nxt[0] = j = -1, i = 1; i < n; nxt[i++] = j) {
    while (~j && a[j + 1] != a[i]) j = nxt[j];
    if (a[j + 1] == a[i]) ++j;
  }
  for (j = -1, i = 0; i < m; ++i) {
    while (~j && a[j + 1] != b[i]) j = nxt[j];
    if (a[j + 1] == b[i]) ++j;
    if (j == n - 1) {
      if (i - n + 1 >= 0) ++A[i - n + 1 + 1], ++B[i + 1];
      j = nxt[j];
    }
  }
}
int ed[N], em[N], chf[N][26], tt;
void insfTire(int p) {
  for (int l = strlen(s), first = 0, i = l - 1, w; i >= 0; --i) {
    if (!chf[first][w = s[i] - 'a']) chf[first][w] = ++tt;
    first = chf[first][w];
    if (i == 0) ed[first] = p, em[first]++;
  }
}
int edz[N], emz[N], chz[N][26], ttz;
void inszTire(int p) {
  for (int l = strlen(s), first = 0, i = 0, w; i <= l - 1; ++i) {
    if (!chz[first][w = s[i] - 'a']) chz[first][w] = ++ttz;
    first = chz[first][w];
    if (i == l - 1) edz[first] = p, emz[first]++;
  }
}
int main() {
  scanf(" %s", ss + 1);
  int L = strlen(ss + 1);
  scanf("%d", &m);
  for (int i = (1); i <= (m); ++i) {
    scanf(" %s", s);
    len[i] = strlen(s);
    if (len[i] > BL) {
      kmp(len[i], s, L, ss + 1);
    }
    insfTire(i);
    inszTire(i);
  }
  long long ans = 0, BB, AA;
  for (int i = (1); i <= (L - 1); ++i) {
    BB = AA = 0;
    int now = 0;
    for (int j = (i); j >= (i - BL + 1); --j)
      if (j >= 1) {
        now = chf[now][ss[j] - 'a'];
        if (!now) break;
        if (ed[now]) BB += em[now];
      }
    now = 0;
    for (int j = (i + 1); j <= (i + BL); ++j)
      if (j <= L) {
        now = chz[now][ss[j] - 'a'];
        if (!now) break;
        if (edz[now]) AA += emz[now];
      }
    ans += (long long)(B[i - 1 + 1] + BB) * (AA + A[i + 1]);
  }
  printf("%lld\n", ans);
  return 0;
}