#include <bits/stdc++.h>
using namespace std;
const long long int N = 1005;
char en = '\n';
long long int inf = 1e16;
long long int mod = 1e9 + 7;
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int K = 26;
const int root = 0;
struct aho_corasick {
  struct Vertex {
    int next[K];
    int leaf = 0, count = -1;
    int p = -1;
    char pch;
    int link = -1;
    int go[K];
    Vertex(int p = -1, char ch = '$') : p(p), pch(ch) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Vertex> t;
  aho_corasick() { t.push_back(Vertex()); }
  void add_string(string const &s) {
    int v = 0;
    for (char ch : s) {
      int c = ch - 'a';
      if (t[v].next[c] == -1) {
        t[v].next[c] = t.size();
        t.emplace_back(v, ch);
      }
      v = t[v].next[c];
    }
    t[v].leaf++;
  }
  int calc(int v) {
    if (v == 0) return 0;
    if (t[v].count == -1) t[v].count = t[v].leaf + calc(get_link(v));
    return t[v].count;
  }
  void calc() {
    t[0].count = 0;
    for (int v = 1; v < t.size(); v++) {
      calc(v);
    }
  }
  int get_link(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else
        t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
  }
  int go(int v, char ch) {
    int c = ch - 'a';
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
        t[v].go[c] = t[v].next[c];
      else
        t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string t;
  cin >> t;
  long long int n;
  cin >> n;
  string arr[n + 5];
  aho_corasick obj;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
    obj.add_string(arr[i]);
  }
  obj.calc();
  long long int n1 = t.length();
  long long int pre[n1 + 5], suff[n1 + 5];
  memset(pre, 0, sizeof(pre));
  memset(suff, 0, sizeof(suff));
  long long int currNode = root;
  for (long long int i = 0; i < t.length(); i++) {
    currNode = obj.go(currNode, t[i]);
    pre[i] = obj.t[currNode].count;
  }
  obj = aho_corasick();
  reverse(t.begin(), t.end());
  for (long long int i = 1; i <= n; i++) {
    reverse(arr[i].begin(), arr[i].end());
    obj.add_string(arr[i]);
  }
  obj.calc();
  currNode = root;
  for (long long int i = 0; i < t.length(); i++) {
    currNode = obj.go(currNode, t[i]);
    suff[t.length() - i - 1] = obj.t[currNode].count;
  }
  long long int res = 0;
  for (long long int j = 1; j < t.length(); j++) {
    long long int left1 = pre[j - 1];
    long long int right1 = suff[j];
    res += left1 * right1;
  }
  cout << res << en;
  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;
const long long int N = 1005;
char en = '\n';
long long int inf = 1e16;
long long int mod = 1e9 + 7;
long long int power(long long int x, long long int n, long long int mod) {
  long long int res = 1;
  x %= mod;
  while (n) {
    if (n & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}
const int K = 26;
const int root = 0;
struct aho_corasick {
  struct Vertex {
    int next[K];
    int leaf = 0, count = -1;
    int p = -1;
    char pch;
    int link = -1;
    int go[K];
    Vertex(int p = -1, char ch = '$') : p(p), pch(ch) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Vertex> t;
  aho_corasick() { t.push_back(Vertex()); }
  void add_string(string const &s) {
    int v = 0;
    for (char ch : s) {
      int c = ch - 'a';
      if (t[v].next[c] == -1) {
        t[v].next[c] = t.size();
        t.emplace_back(v, ch);
      }
      v = t[v].next[c];
    }
    t[v].leaf++;
  }
  int calc(int v) {
    if (v == 0) return 0;
    if (t[v].count == -1) t[v].count = t[v].leaf + calc(get_link(v));
    return t[v].count;
  }
  void calc() {
    t[0].count = 0;
    for (int v = 1; v < t.size(); v++) {
      calc(v);
    }
  }
  int get_link(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else
        t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
  }
  int go(int v, char ch) {
    int c = ch - 'a';
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
        t[v].go[c] = t[v].next[c];
      else
        t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
  }
};
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string t;
  cin >> t;
  long long int n;
  cin >> n;
  string arr[n + 5];
  aho_corasick obj;
  for (long long int i = 1; i <= n; i++) {
    cin >> arr[i];
    obj.add_string(arr[i]);
  }
  obj.calc();
  long long int n1 = t.length();
  long long int pre[n1 + 5], suff[n1 + 5];
  memset(pre, 0, sizeof(pre));
  memset(suff, 0, sizeof(suff));
  long long int currNode = root;
  for (long long int i = 0; i < t.length(); i++) {
    currNode = obj.go(currNode, t[i]);
    pre[i] = obj.t[currNode].count;
  }
  obj = aho_corasick();
  reverse(t.begin(), t.end());
  for (long long int i = 1; i <= n; i++) {
    reverse(arr[i].begin(), arr[i].end());
    obj.add_string(arr[i]);
  }
  obj.calc();
  currNode = root;
  for (long long int i = 0; i < t.length(); i++) {
    currNode = obj.go(currNode, t[i]);
    suff[t.length() - i - 1] = obj.t[currNode].count;
  }
  long long int res = 0;
  for (long long int j = 1; j < t.length(); j++) {
    long long int left1 = pre[j - 1];
    long long int right1 = suff[j];
    res += left1 * right1;
  }
  cout << res << en;
  return 0;
}

```