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;
struct AC {
  int trieN;
  int ch[1000005][28];
  int val[1000005], tt[1000005];
  int fail[1000005];
  int sum[1000005];
  vector<int> v;
  void init() {
    trieN = -1;
    newnod();
  }
  int newnod() {
    memset(ch[++trieN], 0, sizeof ch[0]);
    val[trieN] = fail[trieN] = 0;
    return trieN;
  }
  void insert(const string& str) {
    int cur = 0;
    for (int i = 0; i < str.size(); i++) {
      int d = str[i] - 'a';
      if (!ch[cur][d]) {
        ch[cur][d] = newnod();
      }
      cur = ch[cur][d];
    }
    val[cur]++;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 28; i++) {
      if (ch[0][i]) {
        q.push(ch[0][i]);
      }
    }
    while (!q.empty()) {
      int cur = q.front();
      v.push_back(cur);
      q.pop();
      for (int i = 0; i < 28; i++) {
        if (ch[cur][i]) {
          fail[ch[cur][i]] = ch[fail[cur]][i];
          q.push(ch[cur][i]);
        } else {
          ch[cur][i] = ch[fail[cur]][i];
        }
      }
    }
    for (int i = 0; i < v.size(); i++) {
      int u = v[i];
      tt[u] = tt[fail[u]] + val[u];
    }
  }
  void query(const string& str) {
    int res = 0, cur = 0;
    for (int i = 0; str[i]; i++) {
      int d = str[i] - 'a';
      cur = ch[cur][d];
      sum[i] = tt[cur];
      res = 0;
    }
  }
} ac1, ac2;
int main() {
  string s, t;
  cin >> t;
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s;
    ac1.insert(s);
    reverse(s.begin(), s.end());
    ac2.insert(s);
  }
  ac1.build();
  ac2.build();
  ac1.query(t);
  long long ans = 0;
  reverse(t.begin(), t.end());
  ac2.query(t);
  int len = t.length();
  for (int i = 1; i <= len; i++) {
    ans += (long long)ac1.sum[i - 1] * ac2.sum[len - i - 1];
  }
  cout << ans << '\n';
}