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 = 200100;
string d[N];
string txt;
int n;
struct vertex {
  unordered_map<int, int> next;
  int ids = 0, cumids = -1;
  int id = 0, p = 0, pc, l = -1, tl = -1;
  vertex(int id = 0, int p = 0, int pc = 0) : id(id), p(p), pc(pc) {}
};
vector<vertex> t(1);
void add(int id) {
  int u = 0;
  for (char c : d[id]) {
    if (!t[u].next.count(c)) {
      t[u].next[c] = t.size();
      t.push_back(vertex(t[u].next[c], t[u].id, c));
    }
    u = t[u].next[c];
  }
  ++t[u].ids;
}
int getnext(int u, int c);
int getlink(int u) {
  if (t[u].l == -1) t[u].l = t[u].p ? getnext(getlink(t[u].p), t[u].pc) : 0;
  return t[u].l;
}
int getnext(int u, int c) {
  if (!t[u].next.count(c)) t[u].next[c] = u ? getnext(getlink(u), c) : 0;
  return t[u].next[c];
}
int getcum(int u) {
  if (~t[u].cumids || !u) return t[u].cumids;
  return t[u].cumids = t[u].ids + getcum(getlink(u));
}
int cnt[N][2];
void traverse(string &txt, int cn) {
  int u = 0;
  for (int i = 0; i < txt.size(); ++i) {
    u = getnext(u, txt[i]);
    cnt[i][cn] += getcum(u);
  }
}
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  t[0].cumids = 0;
  cin >> txt >> n;
  int m = txt.size();
  for (int i = 0; i < n; ++i) cin >> d[i];
  for (int i = 0; i < n; ++i) add(i);
  traverse(txt, 0);
  for (int i = 0; i < n; ++i) reverse(d[i].begin(), d[i].end());
  t.clear();
  t.push_back({});
  t[0].cumids = 0;
  for (int i = 0; i < n; ++i) add(i);
  reverse(txt.begin(), txt.end());
  traverse(txt, 1);
  long long res = 0;
  for (int i = 0; i < m - 1; ++i)
    res += cnt[i][0] * (long long)cnt[m - i - 2][1];
  cout << res << endl;
}