#include <bits/stdc++.h>
using namespace std;
char s[200200], t[200200];
int st[200200], len[200200];
struct AC_Automata {
  int go[200200][26], fail[200200], flag[200200], nxt[200200][26];
  int nMem;
  int new_Node() {
    ++nMem;
    fail[nMem] = flag[nMem] = 0;
    for (int i = 0; i < 26; i++) go[nMem][i] = nxt[nMem][i] = 0;
    return nMem;
  }
  void init() {
    nMem = 0;
    for (int i = 0; i < 26; i++) go[0][i] = 1;
    new_Node();
  }
  void add(char *str, int n) {
    int cur = 1;
    for (int i = 0; i < n; i++) {
      int c = str[i] - 'a';
      if (!go[cur][c]) go[cur][c] = new_Node();
      cur = go[cur][c];
    }
    flag[cur]++;
  }
  void make_fail() {
    queue<int> que;
    que.push(1);
    while (!que.empty()) {
      int fr = que.front();
      que.pop();
      for (int i = 0; i < 26; i++) {
        if (go[fr][i]) {
          int ptr = fail[fr];
          while (ptr && !go[ptr][i]) ptr = fail[ptr];
          fail[go[fr][i]] = go[ptr][i];
          flag[go[fr][i]] += flag[fail[go[fr][i]]];
          que.push(go[fr][i]);
        }
      }
    }
  }
  int find_next(int p, int c) {
    if (nxt[p][c]) return nxt[p][c];
    int &ans = nxt[p][c];
    while (!go[p][c]) p = fail[p];
    return ans = go[p][c];
  }
} AC;
int a[200200];
int main() {
  scanf("%s", t);
  int n;
  cin >> n;
  AC.init();
  int cur = 0;
  for (int i = 0; i < n; i++) {
    st[i] = cur;
    scanf("%s", s + cur);
    len[i] = strlen(s + cur);
    AC.add(s + cur, len[i]);
    cur += len[i];
  }
  AC.make_fail();
  int m = strlen(t);
  int now = 1;
  for (int i = 0; i < m; i++) {
    now = AC.find_next(now, t[i] - 'a');
    a[i] = AC.flag[now];
  }
  AC.init();
  for (int i = 0; i < n; i++) {
    reverse(s + st[i], s + st[i] + len[i]);
    AC.add(s + st[i], len[i]);
  }
  AC.make_fail();
  long long ans = 0;
  now = 1;
  for (int i = m; --i;) {
    now = AC.find_next(now, t[i] - 'a');
    ans += (long long)AC.flag[now] * a[i - 1];
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

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[200200], t[200200];
int st[200200], len[200200];
struct AC_Automata {
  int go[200200][26], fail[200200], flag[200200], nxt[200200][26];
  int nMem;
  int new_Node() {
    ++nMem;
    fail[nMem] = flag[nMem] = 0;
    for (int i = 0; i < 26; i++) go[nMem][i] = nxt[nMem][i] = 0;
    return nMem;
  }
  void init() {
    nMem = 0;
    for (int i = 0; i < 26; i++) go[0][i] = 1;
    new_Node();
  }
  void add(char *str, int n) {
    int cur = 1;
    for (int i = 0; i < n; i++) {
      int c = str[i] - 'a';
      if (!go[cur][c]) go[cur][c] = new_Node();
      cur = go[cur][c];
    }
    flag[cur]++;
  }
  void make_fail() {
    queue<int> que;
    que.push(1);
    while (!que.empty()) {
      int fr = que.front();
      que.pop();
      for (int i = 0; i < 26; i++) {
        if (go[fr][i]) {
          int ptr = fail[fr];
          while (ptr && !go[ptr][i]) ptr = fail[ptr];
          fail[go[fr][i]] = go[ptr][i];
          flag[go[fr][i]] += flag[fail[go[fr][i]]];
          que.push(go[fr][i]);
        }
      }
    }
  }
  int find_next(int p, int c) {
    if (nxt[p][c]) return nxt[p][c];
    int &ans = nxt[p][c];
    while (!go[p][c]) p = fail[p];
    return ans = go[p][c];
  }
} AC;
int a[200200];
int main() {
  scanf("%s", t);
  int n;
  cin >> n;
  AC.init();
  int cur = 0;
  for (int i = 0; i < n; i++) {
    st[i] = cur;
    scanf("%s", s + cur);
    len[i] = strlen(s + cur);
    AC.add(s + cur, len[i]);
    cur += len[i];
  }
  AC.make_fail();
  int m = strlen(t);
  int now = 1;
  for (int i = 0; i < m; i++) {
    now = AC.find_next(now, t[i] - 'a');
    a[i] = AC.flag[now];
  }
  AC.init();
  for (int i = 0; i < n; i++) {
    reverse(s + st[i], s + st[i] + len[i]);
    AC.add(s + st[i], len[i]);
  }
  AC.make_fail();
  long long ans = 0;
  now = 1;
  for (int i = m; --i;) {
    now = AC.find_next(now, t[i] - 'a');
    ans += (long long)AC.flag[now] * a[i - 1];
  }
  cout << ans << endl;
  return 0;
}

```