#include <bits/stdc++.h>
using namespace std;
struct Node {
  Node *Index[30];
  Node *fail;
  Node *last;
  int cnt;
  int dep;
  Node() {
    for (int i = 0; i < 30; i++) Index[i] = NULL;
    fail = NULL;
    last = NULL;
    cnt = 0;
    dep = 0;
  }
} *root = new Node();
void add(char c[]) {
  Node *n = root;
  for (int i = 0; c[i] != 0; i++) {
    if (!n->Index[c[i] - 'a']) {
      n->Index[c[i] - 'a'] = new Node();
      n->Index[c[i] - 'a']->dep = n->dep + 1;
    }
    n = n->Index[c[i] - 'a'];
  }
  n->cnt++;
}
void ac() {
  queue<Node *> q;
  q.push(root);
  root->fail = NULL;
  while (!q.empty()) {
    Node *n = q.front();
    q.pop();
    for (int i = 0; i < 30; i++) {
      if (n->Index[i]) {
        q.push(n->Index[i]);
        Node *p = n->fail;
        while (p != NULL && !p->Index[i]) p = p->fail;
        if (p) {
          n->Index[i]->fail = p->Index[i];
          n->Index[i]->last = p->Index[i]->last;
          if (p->Index[i]->cnt) n->Index[i]->last = p->Index[i];
        } else {
          n->Index[i]->fail = root;
        }
      }
    }
  }
}
int cnt1[200005], cnt2[200005];
void search(char c[]) {
  Node *n = root;
  for (int i = 0; c[i] != 0; i++) {
    while (!n->Index[c[i] - 'a'] && n != root) {
      n = n->fail;
    }
    if (n->Index[c[i] - 'a']) n = n->Index[c[i] - 'a'];
    Node *p = n;
    while (p) {
      cnt1[i] += p->cnt;
      cnt2[i - p->dep] += p->cnt;
      p = p->last;
    }
  }
}
void del(Node *n = root) {
  for (int i = 0; i < 30; i++)
    if (n->Index[i]) del(n->Index[i]);
  free(n);
}
int main() {
  char t[200005];
  scanf("%s", t);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char c[200005];
    scanf("%s", c);
    add(c);
  }
  ac();
  search(t);
  long long ans = 0;
  for (int i = 0; t[i] != 0; i++) {
    ans += (long long)cnt1[i] * cnt2[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;
struct Node {
  Node *Index[30];
  Node *fail;
  Node *last;
  int cnt;
  int dep;
  Node() {
    for (int i = 0; i < 30; i++) Index[i] = NULL;
    fail = NULL;
    last = NULL;
    cnt = 0;
    dep = 0;
  }
} *root = new Node();
void add(char c[]) {
  Node *n = root;
  for (int i = 0; c[i] != 0; i++) {
    if (!n->Index[c[i] - 'a']) {
      n->Index[c[i] - 'a'] = new Node();
      n->Index[c[i] - 'a']->dep = n->dep + 1;
    }
    n = n->Index[c[i] - 'a'];
  }
  n->cnt++;
}
void ac() {
  queue<Node *> q;
  q.push(root);
  root->fail = NULL;
  while (!q.empty()) {
    Node *n = q.front();
    q.pop();
    for (int i = 0; i < 30; i++) {
      if (n->Index[i]) {
        q.push(n->Index[i]);
        Node *p = n->fail;
        while (p != NULL && !p->Index[i]) p = p->fail;
        if (p) {
          n->Index[i]->fail = p->Index[i];
          n->Index[i]->last = p->Index[i]->last;
          if (p->Index[i]->cnt) n->Index[i]->last = p->Index[i];
        } else {
          n->Index[i]->fail = root;
        }
      }
    }
  }
}
int cnt1[200005], cnt2[200005];
void search(char c[]) {
  Node *n = root;
  for (int i = 0; c[i] != 0; i++) {
    while (!n->Index[c[i] - 'a'] && n != root) {
      n = n->fail;
    }
    if (n->Index[c[i] - 'a']) n = n->Index[c[i] - 'a'];
    Node *p = n;
    while (p) {
      cnt1[i] += p->cnt;
      cnt2[i - p->dep] += p->cnt;
      p = p->last;
    }
  }
}
void del(Node *n = root) {
  for (int i = 0; i < 30; i++)
    if (n->Index[i]) del(n->Index[i]);
  free(n);
}
int main() {
  char t[200005];
  scanf("%s", t);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char c[200005];
    scanf("%s", c);
    add(c);
  }
  ac();
  search(t);
  long long ans = 0;
  for (int i = 0; t[i] != 0; i++) {
    ans += (long long)cnt1[i] * cnt2[i];
  }
  printf("%lld\n", ans);
  return 0;
}

```