#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
long long n, luu[N], ans;
string s[N], t;
struct AhoCorasick {
  vector<int> adj[N];
  int val[N], cnt = 0;
  struct node {
    int child[26], nex[26], link, sz;
  } trie[N];
  void add(string s, int type) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int x = s[i] - 97;
      if (trie[now].child[x] == 0) {
        cnt++;
        trie[now].child[x] = cnt;
      }
      now = trie[now].child[x];
    }
    if (type == 0) trie[now].sz++;
  }
  void bfs() {
    queue<int> q;
    q.push(0);
    while (q.size() > 0) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int v = trie[u].child[i];
        trie[u].nex[i] = trie[trie[u].link].nex[i];
        if (v != 0) {
          trie[v].link = trie[u].nex[i];
          trie[u].nex[i] = v;
          q.push(v);
        }
      }
    }
  }
  void dfs(int u) {
    for (int v : adj[u]) {
      val[v] = val[u] + trie[v].sz;
      dfs(v);
    }
  }
  void calc() {
    for (int i = 1; i <= cnt; i++) {
      adj[trie[i].link].push_back(i);
    }
    dfs(0);
  }
} Aho_lef, Aho_rig;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    Aho_lef.add(s[i], 0);
  }
  Aho_lef.add(t, 1);
  Aho_lef.bfs();
  Aho_lef.calc();
  int now = 0;
  for (int i = 0; i < t.length(); i++) {
    int x = t[i] - 97;
    now = Aho_lef.trie[now].child[x];
    luu[i] = Aho_lef.val[now];
  }
  for (int i = 1; i <= n; i++) {
    reverse(s[i].begin(), s[i].end());
    Aho_rig.add(s[i], 0);
  }
  reverse(t.begin(), t.end());
  Aho_rig.add(t, 1);
  reverse(t.begin(), t.end());
  Aho_rig.bfs();
  Aho_rig.calc();
  now = 0;
  for (int i = t.length() - 1; i > 0; i--) {
    int x = t[i] - 97;
    now = Aho_rig.trie[now].child[x];
    ans = ans + 1LL * luu[i - 1] * Aho_rig.val[now];
  }
  cout << ans;
}

### Prompt

Please create a solution in cpp 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;
const int N = 4e5 + 5;
long long n, luu[N], ans;
string s[N], t;
struct AhoCorasick {
  vector<int> adj[N];
  int val[N], cnt = 0;
  struct node {
    int child[26], nex[26], link, sz;
  } trie[N];
  void add(string s, int type) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
      int x = s[i] - 97;
      if (trie[now].child[x] == 0) {
        cnt++;
        trie[now].child[x] = cnt;
      }
      now = trie[now].child[x];
    }
    if (type == 0) trie[now].sz++;
  }
  void bfs() {
    queue<int> q;
    q.push(0);
    while (q.size() > 0) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int v = trie[u].child[i];
        trie[u].nex[i] = trie[trie[u].link].nex[i];
        if (v != 0) {
          trie[v].link = trie[u].nex[i];
          trie[u].nex[i] = v;
          q.push(v);
        }
      }
    }
  }
  void dfs(int u) {
    for (int v : adj[u]) {
      val[v] = val[u] + trie[v].sz;
      dfs(v);
    }
  }
  void calc() {
    for (int i = 1; i <= cnt; i++) {
      adj[trie[i].link].push_back(i);
    }
    dfs(0);
  }
} Aho_lef, Aho_rig;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    Aho_lef.add(s[i], 0);
  }
  Aho_lef.add(t, 1);
  Aho_lef.bfs();
  Aho_lef.calc();
  int now = 0;
  for (int i = 0; i < t.length(); i++) {
    int x = t[i] - 97;
    now = Aho_lef.trie[now].child[x];
    luu[i] = Aho_lef.val[now];
  }
  for (int i = 1; i <= n; i++) {
    reverse(s[i].begin(), s[i].end());
    Aho_rig.add(s[i], 0);
  }
  reverse(t.begin(), t.end());
  Aho_rig.add(t, 1);
  reverse(t.begin(), t.end());
  Aho_rig.bfs();
  Aho_rig.calc();
  now = 0;
  for (int i = t.length() - 1; i > 0; i--) {
    int x = t[i] - 97;
    now = Aho_rig.trie[now].child[x];
    ans = ans + 1LL * luu[i - 1] * Aho_rig.val[now];
  }
  cout << ans;
}

```