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 N = 2e5 + 10;
const int S = 26;
int rec[2][N];
struct Aho_Corasick_Automaton {
  int sz, root;
  vector<vector<int> > nextt;
  vector<int> fail, cnt;
  inline int idx(char c) { return c - 'a'; }
  inline int newNode() {
    cnt.push_back(0);
    nextt.push_back(vector<int>(S, 0));
    return sz++;
  }
  void init() {
    sz = 0;
    nextt.clear();
    cnt.clear();
    fail.clear();
    root = newNode();
  }
  void insert(const char* s) {
    int u = root;
    for (; *s; s++) {
      int c = idx(*s);
      int& v = nextt[u][c];
      if (!v) v = newNode();
      u = v;
    }
    cnt[u]++;
  }
  void build() {
    vector<int> q;
    fail.resize(nextt.size());
    fail[root] = root;
    for (int i = 0; i < S; i++) {
      int& v = nextt[root][i];
      if (v) {
        fail[v] = root;
        q.push_back(v);
      } else
        v = root;
    }
    for (int k = 0; k < q.size(); k++) {
      int u = q[k];
      for (int i = 0; i < S; i++) {
        int& v = nextt[u][i];
        if (v) {
          fail[v] = nextt[fail[u]][i];
          cnt[v] += cnt[nextt[fail[u]][i]];
          q.push_back(v);
        } else
          v = nextt[fail[u]][i];
      }
    }
  }
  void query(const char* s, int id) {
    int u = root, tot = 0;
    for (; *s; s++, tot++) {
      int c = idx(*s);
      u = nextt[u][c];
      rec[id][tot] = cnt[u];
    }
  }
};
Aho_Corasick_Automaton AC1, AC2;
char s[N], t[N];
int main() {
  int m, n, len;
  long long ans;
  scanf("%s", s + 1);
  m = strlen(s + 1);
  AC1.init();
  AC2.init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t + 1);
    len = strlen(t + 1);
    AC1.insert(t + 1);
    reverse(t + 1, t + len + 1);
    AC2.insert(t + 1);
  }
  AC1.build();
  AC1.query(s + 1, 0);
  reverse(s + 1, s + m + 1);
  AC2.build();
  AC2.query(s + 1, 1);
  ans = 0;
  for (int i = 0; i < m - 1; i++) ans += 1LL * rec[0][i] * rec[1][m - 2 - i];
  printf("%I64d\n", ans);
  return 0;
}