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 = 1e6 + 100, second = 28;
int nex[N][second], o = 1, f[N], par[N], acc[N];
long long int za[N], be[N], en[N];
string st[N];
void add(string &s, int i) {
  int cur = 0;
  for (char c : s) {
    if (nex[cur][c - 'a'] == -1) nex[cur][c - 'a'] = o++;
    cur = nex[cur][c - 'a'];
  }
  acc[cur] = i + 1;
  za[cur]++;
}
bool fin = 0;
void aho() {
  f[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int r = q.front();
    q.pop();
    par[r] = ((acc[f[r]]) ? f[r] : par[f[r]]);
    for (int i = 0; i < 26; i++) {
      if (nex[r][i] == -1) {
        nex[r][i] = max(nex[f[r]][i], 0);
      } else {
        int u = nex[r][i];
        if (r != 0)
          f[u] = nex[f[r]][i];
        else
          f[u] = 0;
        q.push(u);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(nex, -1, sizeof(nex));
  string s;
  cin >> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> st[i];
    add(st[i], i);
  }
  aho();
  int cur = 0, num = 0;
  for (char c : s) {
    cur = nex[cur][c - 'a'];
    int cur2 = cur;
    while (cur2 != 0) {
      if (acc[cur2] > 0) {
        int u = acc[cur2] - 1;
        long long int zar = za[cur2];
        en[num] += zar;
        be[num - (int)st[u].size() + 1] += zar;
      }
      cur2 = par[cur2];
    }
    num++;
  }
  long long int ans = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    ans += en[i] * be[i + 1];
  }
  cout << ans;
}