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;
template <typename T>
inline void read(T &x) {
  x = 0;
  char ch = getchar();
  bool f = false;
  while (!isdigit(ch)) {
    if (ch == '-') {
      f = true;
    }
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  x = f ? -x : x;
  return;
}
template <typename T>
inline void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 ^ 48);
  return;
}
const int N = 2e5 + 5;
const int SIZE = 2e5 + 5;
struct AC {
  int ch[SIZE][26], Add[SIZE * 26], fail[SIZE * 26], val[SIZE], dep[SIZE * 26],
      tot, root;
  void Init() {
    memset(ch, 0, sizeof(ch));
    memset(Add, 0, sizeof(Add));
    memset(fail, 0, sizeof(fail));
    tot = root = 0;
    return;
  }
  void Insert(char *str) {
    int p = 0, len = strlen(str);
    for (int i = 0; i < len; i++) {
      int c = str[i] - 'a';
      if (!ch[p][c]) ch[p][c] = ++tot;
      p = ch[p][c];
    }
    Add[p]++;
    return;
  }
  void Build() {
    queue<int> q;
    for (int i = 0; i < 26; i++)
      if (ch[root][i])
        fail[ch[root][i]] = root, dep[ch[root][i]] = Add[ch[root][i]],
        q.push(ch[root][i]);
    while (!q.empty()) {
      int p = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        if (ch[p][i])
          fail[ch[p][i]] = ch[fail[p]][i], q.push(ch[p][i]),
          dep[ch[p][i]] = dep[fail[ch[p][i]]] + Add[ch[p][i]];
        else
          ch[p][i] = ch[fail[p]][i];
      }
    }
    return;
  }
  void Query(char *str) {
    int len = strlen(str), p = 0;
    for (int i = 0; i < len; i++) {
      p = ch[p][str[i] - 'a'];
      val[i] = dep[p];
    }
    return;
  }
} ACAM1, ACAM2;
int n, now;
char str[N], s[N];
long long ans;
int main() {
  scanf("%s", str);
  read(n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s);
    ACAM1.Insert(s);
    reverse(s, s + strlen(s));
    ACAM2.Insert(s);
  }
  ACAM1.Build(), ACAM2.Build();
  ACAM1.Query(str);
  reverse(str, str + strlen(str));
  ACAM2.Query(str);
  now = strlen(str);
  for (int i = 0; i < now - 1; i++) {
    ans += 1ll * ACAM1.val[i] * ACAM2.val[now - i - 2];
  }
  write(ans);
  return 0;
}