#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
struct node {
  int child[26];
  int fail = 0;
  long long int end = 0;
};
struct ACAM {
  node ac[MAXN];
  int ac_sz = 1;
  void ac_clear(int x) {
    for (int i = 0; i < 26; i++) ac[x].child[i] = 0;
    ac[x].fail = 0;
    ac[x].end = 0;
  }
  void add_word(string &s, int word_id) {
    int x = 0, c = 0;
    for (auto &_c : s) {
      c = _c - 'a';
      if (!ac[x].child[c]) {
        ac[x].child[c] = ac_sz++;
        ac_clear(ac[x].child[c]);
      }
      x = ac[x].child[c];
    }
    ac[x].end++;
  }
  void ac_build() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
      if (ac[0].child[i]) {
        ac[ac[0].child[i]].fail = 0;
        q.push(ac[0].child[i]);
      }
    }
    while (!q.empty()) {
      int u = q.front(), v;
      q.pop();
      for (int i = 0; i < 26; i++) {
        v = ac[ac[u].fail].child[i];
        if (ac[u].child[i]) {
          ac[ac[u].child[i]].fail = v;
          ac[ac[u].child[i]].end += ac[v].end;
          q.push(ac[u].child[i]);
        } else
          ac[u].child[i] = v;
      }
    }
  }
  void query(string &s, long long int *cnt) {
    int x = 0, c = 0;
    for (int i = 1; i <= s.size(); i++) {
      c = s[i - 1] - 'a';
      x = ac[x].child[c];
      cnt[i] = ac[x].end;
    }
  }
};
ACAM opt, rev;
long long int n, dp1[MAXN], dp2[MAXN];
string s;
string p;
long long int ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    opt.add_word(p, i);
    reverse(p.begin(), p.end());
    rev.add_word(p, i);
  }
  opt.ac_build();
  rev.ac_build();
  opt.query(s, dp1);
  reverse(s.begin(), s.end());
  rev.query(s, dp2);
  for (int i = 1; i < s.size(); i++) {
    ans += dp1[i] * dp2[s.size() - i];
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Develop a solution in cpp 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 int MAXN = 2e5 + 10;
struct node {
  int child[26];
  int fail = 0;
  long long int end = 0;
};
struct ACAM {
  node ac[MAXN];
  int ac_sz = 1;
  void ac_clear(int x) {
    for (int i = 0; i < 26; i++) ac[x].child[i] = 0;
    ac[x].fail = 0;
    ac[x].end = 0;
  }
  void add_word(string &s, int word_id) {
    int x = 0, c = 0;
    for (auto &_c : s) {
      c = _c - 'a';
      if (!ac[x].child[c]) {
        ac[x].child[c] = ac_sz++;
        ac_clear(ac[x].child[c]);
      }
      x = ac[x].child[c];
    }
    ac[x].end++;
  }
  void ac_build() {
    queue<int> q;
    for (int i = 0; i < 26; i++) {
      if (ac[0].child[i]) {
        ac[ac[0].child[i]].fail = 0;
        q.push(ac[0].child[i]);
      }
    }
    while (!q.empty()) {
      int u = q.front(), v;
      q.pop();
      for (int i = 0; i < 26; i++) {
        v = ac[ac[u].fail].child[i];
        if (ac[u].child[i]) {
          ac[ac[u].child[i]].fail = v;
          ac[ac[u].child[i]].end += ac[v].end;
          q.push(ac[u].child[i]);
        } else
          ac[u].child[i] = v;
      }
    }
  }
  void query(string &s, long long int *cnt) {
    int x = 0, c = 0;
    for (int i = 1; i <= s.size(); i++) {
      c = s[i - 1] - 'a';
      x = ac[x].child[c];
      cnt[i] = ac[x].end;
    }
  }
};
ACAM opt, rev;
long long int n, dp1[MAXN], dp2[MAXN];
string s;
string p;
long long int ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p;
    opt.add_word(p, i);
    reverse(p.begin(), p.end());
    rev.add_word(p, i);
  }
  opt.ac_build();
  rev.ac_build();
  opt.query(s, dp1);
  reverse(s.begin(), s.end());
  rev.query(s, dp2);
  for (int i = 1; i < s.size(); i++) {
    ans += dp1[i] * dp2[s.size() - i];
  }
  cout << ans << endl;
  return 0;
}

```