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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
string s;
string t[200005];
vector<int> suf, pre;
int n;
struct TRIE {
  TRIE *next[26];
  TRIE *fail;
  int output;
  TRIE() {
    for (int i = 0; i < 26; i++) next[i] = NULL;
    fail = NULL;
    output = 0;
  }
  ~TRIE() {
    for (int i = 0; i < 26; i++)
      if (next[i]) delete next[i];
  }
  void insert(string &s) {
    int n = s.size();
    TRIE *here = this;
    for (int i = 0; i < n; i++) {
      if (!here->next[s[i] - 'a']) here->next[s[i] - 'a'] = new TRIE;
      here = here->next[s[i] - 'a'];
    }
    here->output++;
  }
  void construct() {
    queue<TRIE *> Q;
    Q.push(this);
    this->fail = this;
    while (!Q.empty()) {
      auto f = Q.front();
      Q.pop();
      for (int i = 0; i < 26; i++) {
        if (!f->next[i]) continue;
        if (f == this) {
          f->next[i]->fail = f;
        } else {
          auto tmp = f->fail;
          while (tmp != this && !tmp->next[i]) tmp = tmp->fail;
          if (tmp->next[i]) tmp = tmp->next[i];
          f->next[i]->fail = tmp;
        }
        Q.push(f->next[i]);
        f->next[i]->output += f->next[i]->fail->output;
      }
    }
  }
  void find(string &s, vector<int> &v) {
    TRIE *here = this;
    int n = s.size();
    for (int i = 0; i < n; i++) {
      while (here != this && !here->next[s[i] - 'a']) here = here->fail;
      if (here->next[s[i] - 'a']) here = here->next[s[i] - 'a'];
      if (here->output) {
        v[i] += here->output;
      }
    }
  }
};
void solve() {
  cin >> s;
  cin >> n;
  suf.resize(s.size()), pre.resize(s.size());
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  long long ans = 0;
  TRIE tr;
  for (int i = 0; i < n; i++) tr.insert(t[i]);
  tr.construct();
  tr.find(s, suf);
  TRIE tr2;
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    reverse(t[i].begin(), t[i].end());
  }
  for (int i = 0; i < n; i++) tr2.insert(t[i]);
  tr2.construct();
  tr2.find(s, pre);
  reverse(pre.begin(), pre.end());
  for (int i = 1; i < (int)s.size(); i++) {
    ans += (long long)suf[i - 1] * pre[i];
  }
  cout << ans << endl;
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}