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;
int n;
string s[200010], t, tr;
long long f[200010], g[200010];
struct ACAM {
  struct node {
    int nx[26], fail;
    int cnt;
    node() {
      memset(nx, -1, sizeof nx);
      cnt = 0;
    }
  } t[200010];
  int root, tot;
  int que[200010], ql, qr;
  int newnode() {
    ++tot;
    t[tot] = node();
    return tot;
  }
  void init() {
    tot = 0;
    root = newnode();
  }
  void insert(string s) {
    int len = s.size();
    int now = root;
    for (int i = 0; i < len; ++i) {
      if (t[now].nx[s[i] - 'a'] == -1) t[now].nx[s[i] - 'a'] = newnode();
      now = t[now].nx[s[i] - 'a'];
    }
    ++t[now].cnt;
  }
  void build() {
    ql = 1, qr = 0;
    t[root].fail = root;
    for (int i = 0; i < 26; ++i) {
      if (t[root].nx[i] == -1) {
        t[root].nx[i] = root;
      } else {
        t[t[root].nx[i]].fail = root;
        que[++qr] = t[root].nx[i];
      }
    }
    while (ql <= qr) {
      int now = que[ql++];
      t[now].cnt += t[t[now].fail].cnt;
      for (int i = 0; i < 26; ++i) {
        if (t[now].nx[i] == -1) {
          t[now].nx[i] = t[t[now].fail].nx[i];
        } else {
          t[t[now].nx[i]].fail = t[t[now].fail].nx[i];
          que[++qr] = t[now].nx[i];
        }
      }
    }
  }
  void query(string s, long long *f) {
    int len = s.size();
    int now = root;
    for (int i = 0; i < len; ++i) {
      now = t[now].nx[s[i] - 'a'];
      f[i] = t[now].cnt;
    }
  }
} ac;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  while (cin >> t) {
    tr = t;
    reverse(tr.begin(), tr.end());
    cin >> n;
    ac.init();
    for (int i = 1; i <= n; ++i) cin >> s[i], ac.insert(s[i]);
    ac.build();
    ac.query(t, f);
    ac.init();
    for (int i = 1; i <= n; ++i) {
      reverse(s[i].begin(), s[i].end());
      ac.insert(s[i]);
    }
    ac.build();
    ac.query(tr, g);
    long long res = 0;
    int len = t.size();
    reverse(g, g + len);
    for (int i = 0; i < len - 1; ++i) {
      res += f[i] * g[i + 1];
    }
    cout << res << "\n";
  }
  return 0;
}