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;
template <class T>
inline bool checkMin(T& a, T b) {
  return (a > b ? a = b, 1 : 0);
}
template <class T>
inline bool checkMax(T& a, T b) {
  return (a < b ? a = b, 1 : 0);
}
const long long K = 26;
const long long N = 400005;
const char B = 'a';
struct Node {
  Node* e[K];
  Node* fail;
  long long item, dep;
  Node(long long dep) : dep(dep) {
    for (long long i = 0; i < K; i++) e[i] = NULL;
    fail = NULL;
    item = 0;
  }
};
class AhoCorasick {
 private:
  Node* second;
  long long times[N];

 public:
  AhoCorasick() { second = new Node(0); }
  void insert(char* s) {
    Node* pos = second;
    while (*s) {
      long long v = *s - B;
      if (pos->e[v] == NULL) pos->e[v] = new Node(pos->dep + 1);
      pos = pos->e[v];
      s++;
    }
    pos->item++;
  }
  void build() {
    second->fail = second;
    queue<Node*> que;
    for (long long i = 0; i < K; i++)
      if (second->e[i] != NULL) {
        que.push(second->e[i]);
        second->e[i]->fail = second;
      } else
        second->e[i] = second;
    while (!que.empty()) {
      Node* u = que.front();
      que.pop();
      for (long long i = 0; i < K; i++) {
        if (u->e[i] != NULL) {
          u->e[i]->fail = u->fail->e[i];
          u->e[i]->item += u->e[i]->fail->item;
          que.push(u->e[i]);
        } else {
          u->e[i] = u->fail->e[i];
        }
      }
    }
  }
  void query(char* s, long long ans[]) {
    Node* u = second;
    long long id = 0;
    while (*s) {
      long long v = *s - B;
      u = u->e[v];
      ans[id] += u->item;
      id++;
      s++;
    }
  }
  ~AhoCorasick() { delete second; }
};
char t[N];
char s[N];
long long st[N];
long long n;
AhoCorasick Aho0, Aho1;
void init() {
  scanf("%s", t);
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    scanf("%s", s);
    Aho0.insert(s);
    long long l = strlen(s);
    reverse(s, s + l);
    Aho1.insert(s);
  }
}
long long pre[N], suf[N];
void solve() {
  Aho0.build();
  Aho1.build();
  Aho0.query(t, pre);
  long long l = strlen(t);
  reverse(t, t + l);
  Aho1.query(t, suf);
  reverse(suf, suf + l);
  for (long long i = 0; i < l; i++)
    ;
  ;
  for (long long i = 0; i < l; i++)
    ;
  ;
  long long ans = 0;
  for (long long i = 1; i <= l - 1; i++) ans += pre[i - 1] * suf[i];
  printf("%lld\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}