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> > nxt;
  vector<int> fail, cnt;
  inline int idx(int c) {
    return c;
    return c - 'a';
  }
  inline int newNode() {
    cnt.push_back(0);
    nxt.push_back(vector<int>(S, 0));
    return sz++;
  }
  void init() {
    sz = 0;
    nxt.clear();
    cnt.clear();
    fail.clear();
    root = newNode();
  }
  void insert(const int str[], int len) {
    int u = root;
    for (int i = 0; i < len; ++i) {
      int c = str[i];
      int& v = nxt[u][c];
      if (!v) v = newNode();
      u = v;
    }
    cnt[u]++;
  }
  void build() {
    vector<int> Q;
    fail.resize(nxt.size());
    fail[root] = root;
    for (int i = 0; i < S; i++) {
      int& v = nxt[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 = nxt[u][i];
        if (v) {
          fail[v] = nxt[fail[u]][i];
          cnt[v] += cnt[nxt[fail[u]][i]];
          Q.push_back(v);
        } else
          v = nxt[fail[u]][i];
      }
    }
  }
  void query(const int* str, int len, int id) {
    int u = root;
    for (int i = 0; i < len; ++i) {
      int c = str[i];
      u = nxt[u][c];
      rec[id][i] = cnt[u];
    }
  }
};
Aho_Corasick_Automaton AC1, AC2;
char s[N], t[N];
int ss[N], tt[N];
int main() {
  int m, n, len;
  long long ans;
  scanf("%s", s + 1);
  m = strlen(s + 1);
  for (int i = 1; i <= m; ++i) ss[i] = s[i] - 'a';
  AC1.init();
  AC2.init();
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", t + 1);
    len = strlen(t + 1);
    for (int j = 1; j <= len; ++j) tt[j] = t[j] - 'a';
    AC1.insert(tt + 1, len);
    reverse(tt + 1, tt + len + 1);
    AC2.insert(tt + 1, len);
  }
  AC1.build();
  AC1.query(ss + 1, m, 0);
  reverse(ss + 1, ss + m + 1);
  AC2.build();
  AC2.query(ss + 1, m, 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;
}