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 maxn = 2e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
string t, s[maxn];
int n;
int x = 1, N;
int trie[maxn][28], cnt[maxn], fail[maxn], last[maxn];
int ps[2][maxn];
void init() {
  x = 1;
  memset(trie, 0, sizeof(trie));
  memset(cnt, 0, sizeof(cnt));
  memset(fail, 0, sizeof(fail));
  memset(last, 0, sizeof(last));
}
void Insert(string second) {
  int now = 0;
  for (char c : second) {
    if (!trie[now][c - 'a']) trie[now][c - 'a'] = x++;
    now = trie[now][c - 'a'];
  }
  cnt[now]++;
}
void GetFail() {
  queue<int> q;
  fail[0] = 0;
  for (int i = 0; i < 26; i++) {
    int v = trie[0][i];
    if (v) {
      fail[v] = 0;
      q.push(v);
      last[v] = 0;
    }
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      int v = trie[now][i];
      if (!v) continue;
      q.push(v);
      int first = fail[now];
      while (first && !trie[first][i]) first = fail[first];
      fail[v] = trie[first][i];
      last[v] = (cnt[fail[v]] ? fail[v] : last[fail[v]]);
    }
  }
}
void Add(int type, int I, int J) {
  if (J) {
    ps[type][I] += cnt[J];
    Add(type, I, last[J]);
  }
}
void Find(int type) {
  int j = 0;
  for (int i = 0; i < N; i++) {
    int c = t[i] - 'a';
    while (j && !trie[j][c]) j = fail[j];
    j = trie[j][c];
    if (cnt[j])
      Add(type, i, j);
    else
      Add(type, i, last[j]);
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> t >> n;
  N = t.length();
  for (int i = 1; i <= n; i++) cin >> s[i];
  init();
  for (int i = 1; i <= n; i++) Insert(s[i]);
  GetFail();
  Find(0);
  init();
  reverse((t).begin(), (t).end());
  for (int i = 1; i <= n; i++)
    reverse((s[i]).begin(), (s[i]).end()), Insert(s[i]);
  GetFail();
  Find(1);
  long long ans = 0;
  for (int i = 0; i < N - 1; i++)
    ans = (ans + ps[0][i] * 1ll * ps[1][N - i - 2]);
  cout << ans << '\n';
}