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;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
struct aho_corasick {
  struct trie_node {
    map<char, trie_node *> nxt;
    int cnt_patterns = 0;
    trie_node *fail;
    bool is_root;
    trie_node(bool is_root = false) : is_root(is_root) { fail = NULL; }
    void insert(const char *str, int patternIdx) {
      if (*str == '\0') {
        cnt_patterns++;
        return;
      }
      if (nxt.find(*str) == nxt.end()) nxt[*str] = new trie_node();
      char ch = *str;
      nxt[ch]->insert(++str, patternIdx);
    }
  };
  trie_node *root;
  vector<string> patterns;
  aho_corasick(const vector<string> &_patterns) {
    patterns = _patterns;
    root = new trie_node(true);
    for (int i = 0; i < patterns.size(); i++)
      root->insert(patterns[i].c_str(), i);
    buildAhoTree();
  }
  void fail(trie_node *&cur, char ch) {
    while (!cur->is_root && !cur->nxt.count(ch)) cur = cur->fail;
    if (cur->nxt.count(ch))
      cur = cur->nxt[ch];
    else
      cur = root;
  }
  void buildAhoTree() {
    queue<trie_node *> q;
    for (auto &child : root->nxt) {
      q.push(child.second);
      child.second->fail = root;
    }
    while (!q.empty()) {
      trie_node *cur = q.front();
      q.pop();
      for (auto &child : cur->nxt) {
        trie_node *k = cur->fail;
        fail(k, child.first);
        child.second->fail = k;
        child.second->cnt_patterns += k->cnt_patterns;
        q.push(child.second);
      }
    }
  }
  vector<int> match(const string &str) {
    trie_node *k = root;
    vector<int> rt(str.size());
    for (int i = 0; i < str.size(); i++) {
      fail(k, str[i]);
      rt[i] += k->cnt_patterns;
    }
    return rt;
  }
};
int main() {
  run();
  string t;
  int n;
  cin >> t >> n;
  vector<string> v1(n), v2(n);
  for (int i = 0; i < n; i++) {
    cin >> v1[i];
    v2[i] = v1[i];
    reverse(v2[i].begin(), v2[i].end());
  }
  vector<int> c1 = aho_corasick(v1).match(t);
  reverse(t.begin(), t.end());
  vector<int> c2 = aho_corasick(v2).match(t);
  reverse(t.begin(), t.end());
  reverse(c2.begin(), c2.end());
  long long ans = 0;
  for (int i = 0; i + 1 < (int)(t.size()); i++) ans += 1LL * c1[i] * c2[i + 1];
  cout << ans << "\n";
}