#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &u) {
  u = 0;
  char c = getchar();
  long long flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
  if (flag) u = -u;
}
bool checkmin(long long &a, long long b) { return (b < a ? a = b, 1 : 0); }
bool checkmax(long long &a, long long b) { return (b > a ? a = b, 1 : 0); }
const long long N = 510005;
long long n, len;
long long Begin[N], End[N];
char t[N], s[N];
long long ch[N][26], fail[N], F[N];
struct AhoCorasick {
  long long sz;
  void init() { sz = 2; }
  void insert(long long rt, char *str) {
    long long len = strlen(str), tmp = rt;
    for (long long i = 0; i < len; ++i) {
      long long d = str[i] - 'a';
      if (ch[tmp][d] == 0) {
        ch[tmp][d] = sz++;
      }
      tmp = ch[tmp][d];
    }
    ++F[tmp];
  }
  void build(long long rt) {
    queue<long long> q;
    q.push(rt);
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      for (long long i = 0; i < 26; ++i) {
        long long w = (x == rt ? rt : ch[fail[x]][i]);
        if (ch[x][i]) {
          fail[ch[x][i]] = w;
          F[ch[x][i]] += F[w];
          q.push(ch[x][i]);
        } else {
          ch[x][i] = w;
        }
      }
    }
  }
  void query(long long rt, char *str, long long *ans) {
    long long len = strlen(str), now = rt;
    for (long long i = 0; i < len; ++i) {
      now = ch[now][str[i] - 'a'];
      ans[i] += F[now];
    }
  }
} ac;
void init() {
  scanf("%s", t);
  read(n);
  len = strlen(t);
  ac.init();
  for (long long i = 1; i <= n; ++i) {
    scanf("%s", s);
    long long l = strlen(s);
    ac.insert(0, s);
    reverse(s, s + l);
    ac.insert(1, s);
  }
  ac.build(0);
  ac.build(1);
  ac.query(0, t, End);
  reverse(t, t + len);
  ac.query(1, t, Begin);
  reverse(Begin, Begin + len);
  long long ans = 0;
  for (long long i = 0; i < len - 1; ++i) {
    ans += End[i] * Begin[i + 1];
  }
  printf("%lld\n", ans);
}
void solve() {}
int main() {
  init();
  solve();
  return 0;
}

### Prompt

Create a solution in cpp for 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;
template <class T>
void read(T &u) {
  u = 0;
  char c = getchar();
  long long flag = 0;
  while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
  while (c >= '0' && c <= '9')
    u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
  if (flag) u = -u;
}
bool checkmin(long long &a, long long b) { return (b < a ? a = b, 1 : 0); }
bool checkmax(long long &a, long long b) { return (b > a ? a = b, 1 : 0); }
const long long N = 510005;
long long n, len;
long long Begin[N], End[N];
char t[N], s[N];
long long ch[N][26], fail[N], F[N];
struct AhoCorasick {
  long long sz;
  void init() { sz = 2; }
  void insert(long long rt, char *str) {
    long long len = strlen(str), tmp = rt;
    for (long long i = 0; i < len; ++i) {
      long long d = str[i] - 'a';
      if (ch[tmp][d] == 0) {
        ch[tmp][d] = sz++;
      }
      tmp = ch[tmp][d];
    }
    ++F[tmp];
  }
  void build(long long rt) {
    queue<long long> q;
    q.push(rt);
    while (!q.empty()) {
      long long x = q.front();
      q.pop();
      for (long long i = 0; i < 26; ++i) {
        long long w = (x == rt ? rt : ch[fail[x]][i]);
        if (ch[x][i]) {
          fail[ch[x][i]] = w;
          F[ch[x][i]] += F[w];
          q.push(ch[x][i]);
        } else {
          ch[x][i] = w;
        }
      }
    }
  }
  void query(long long rt, char *str, long long *ans) {
    long long len = strlen(str), now = rt;
    for (long long i = 0; i < len; ++i) {
      now = ch[now][str[i] - 'a'];
      ans[i] += F[now];
    }
  }
} ac;
void init() {
  scanf("%s", t);
  read(n);
  len = strlen(t);
  ac.init();
  for (long long i = 1; i <= n; ++i) {
    scanf("%s", s);
    long long l = strlen(s);
    ac.insert(0, s);
    reverse(s, s + l);
    ac.insert(1, s);
  }
  ac.build(0);
  ac.build(1);
  ac.query(0, t, End);
  reverse(t, t + len);
  ac.query(1, t, Begin);
  reverse(Begin, Begin + len);
  long long ans = 0;
  for (long long i = 0; i < len - 1; ++i) {
    ans += End[i] * Begin[i + 1];
  }
  printf("%lld\n", ans);
}
void solve() {}
int main() {
  init();
  solve();
  return 0;
}

```