#include <bits/stdc++.h>
using namespace std;
char s[1000005], t[1000005];
struct AhoCorasickAutomaton {
  struct Node {
    Node *son[26], *fail, *last;
    long long cnt;
    Node() {
      memset(son, 0, sizeof(son));
      fail = last = 0;
      cnt = 0;
    }
  } * root;
  AhoCorasickAutomaton() { root = new Node; }
  long long a[1000005];
  void Insert(char *s) {
    Node *pos = root;
    int len = strlen(s);
    for (; *s; ++s) {
      int c = *s - 'a';
      if (!pos->son[c]) pos->son[c] = new Node;
      pos = pos->son[c];
    }
    pos->cnt++;
  }
  void Build() {
    root->fail = root->last = root;
    std::queue<Node *> Q;
    for (int c = 0; c < 26; ++c)
      if (root->son[c]) {
        root->son[c]->fail = root->son[c]->last = root;
        Q.push(root->son[c]);
      } else
        root->son[c] = root;
    while (!Q.empty()) {
      Node *cur = Q.front();
      Q.pop();
      for (int c = 0; c < 26; ++c)
        if (cur->son[c]) {
          Node *u = cur->son[c];
          u->fail = cur->fail->son[c];
          u->last = u->fail->cnt ? u->fail : u->fail->last;
          Q.push(u);
        } else
          cur->son[c] = cur->fail->son[c];
    }
  }
  void Match(char *s) {
    Node *pos = root;
    for (int i = 1; *s; ++s, ++i) {
      int c = *s - 'a';
      pos = pos->son[c];
      for (Node *tmp = pos; tmp != tmp->last; tmp = tmp->last) a[i] += tmp->cnt;
    }
  }
};
AhoCorasickAutomaton e, e2;
int main() {
  scanf("%s", s + 1);
  int n, len;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t + 1);
    e.Insert(t + 1);
    len = strlen(t + 1);
    reverse(t + 1, t + len + 1);
    e2.Insert(t + 1);
  }
  e.Build();
  e2.Build();
  len = strlen(s + 1);
  e.Match(s + 1);
  reverse(s + 1, s + len + 1);
  e2.Match(s + 1);
  long long ans = 0;
  for (int i = 0; i <= len; i++) ans += e.a[i] * e2.a[len - i];
  printf("%lld\n", ans);
  return 0;
}

### Prompt

Generate a cpp solution to 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;
char s[1000005], t[1000005];
struct AhoCorasickAutomaton {
  struct Node {
    Node *son[26], *fail, *last;
    long long cnt;
    Node() {
      memset(son, 0, sizeof(son));
      fail = last = 0;
      cnt = 0;
    }
  } * root;
  AhoCorasickAutomaton() { root = new Node; }
  long long a[1000005];
  void Insert(char *s) {
    Node *pos = root;
    int len = strlen(s);
    for (; *s; ++s) {
      int c = *s - 'a';
      if (!pos->son[c]) pos->son[c] = new Node;
      pos = pos->son[c];
    }
    pos->cnt++;
  }
  void Build() {
    root->fail = root->last = root;
    std::queue<Node *> Q;
    for (int c = 0; c < 26; ++c)
      if (root->son[c]) {
        root->son[c]->fail = root->son[c]->last = root;
        Q.push(root->son[c]);
      } else
        root->son[c] = root;
    while (!Q.empty()) {
      Node *cur = Q.front();
      Q.pop();
      for (int c = 0; c < 26; ++c)
        if (cur->son[c]) {
          Node *u = cur->son[c];
          u->fail = cur->fail->son[c];
          u->last = u->fail->cnt ? u->fail : u->fail->last;
          Q.push(u);
        } else
          cur->son[c] = cur->fail->son[c];
    }
  }
  void Match(char *s) {
    Node *pos = root;
    for (int i = 1; *s; ++s, ++i) {
      int c = *s - 'a';
      pos = pos->son[c];
      for (Node *tmp = pos; tmp != tmp->last; tmp = tmp->last) a[i] += tmp->cnt;
    }
  }
};
AhoCorasickAutomaton e, e2;
int main() {
  scanf("%s", s + 1);
  int n, len;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t + 1);
    e.Insert(t + 1);
    len = strlen(t + 1);
    reverse(t + 1, t + len + 1);
    e2.Insert(t + 1);
  }
  e.Build();
  e2.Build();
  len = strlen(s + 1);
  e.Match(s + 1);
  reverse(s + 1, s + len + 1);
  e2.Match(s + 1);
  long long ans = 0;
  for (int i = 0; i <= len; i++) ans += e.a[i] * e2.a[len - i];
  printf("%lld\n", ans);
  return 0;
}

```