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 + 10;
int cnt2[maxn];
int cnt[maxn];
struct trie {
  int nxt[maxn][26], fail[maxn], g[maxn];
  int ed[maxn];
  int rt, L;
  int newnode() {
    memset(nxt[L], -1, sizeof nxt[L]);
    fail[L] = g[L] = 0;
    ed[L++] = 0;
    return L - 1;
  }
  void init() {
    L = 0;
    rt = newnode();
  }
  void insert(const string& buf) {
    int len = buf.size();
    int now = rt;
    for (int i = 0; i < len; ++i) {
      if (nxt[now][buf[i] - 'a'] == -1) nxt[now][buf[i] - 'a'] = newnode();
      now = nxt[now][buf[i] - 'a'];
    }
    ed[now]++;
  }
  void build() {
    queue<int> q;
    fail[rt] = rt;
    g[rt] = rt;
    for (int i = 0; i < 26; ++i) {
      if (nxt[rt][i] == -1)
        nxt[rt][i] = rt;
      else {
        fail[nxt[rt][i]] = rt;
        g[nxt[rt][i]] = rt;
        q.push(nxt[rt][i]);
      }
    }
    while (!q.empty()) {
      int now = q.front();
      q.pop();
      for (int i = 0; i < 26; ++i) {
        if (nxt[now][i] == -1)
          nxt[now][i] = nxt[fail[now]][i];
        else {
          fail[nxt[now][i]] = nxt[fail[now]][i];
          if (ed[fail[nxt[now][i]]]) {
            g[nxt[now][i]] = fail[nxt[now][i]];
          } else
            g[nxt[now][i]] = g[fail[nxt[now][i]]];
          q.push(nxt[now][i]);
        }
      }
    }
  }
  void query(const string& buf) {
    int len = buf.size();
    int now = rt;
    for (int i = 0; i < len; ++i) {
      now = nxt[now][buf[i] - 'a'];
      int tmp = now;
      while (tmp != rt) {
        cnt[i] += ed[tmp];
        tmp = g[tmp];
      }
    }
  }
} a, b;
string t;
string s[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  int n;
  cin >> n;
  a.init();
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    a.insert(s[i]);
  }
  a.build();
  a.query(t);
  memcpy(cnt2, cnt, sizeof cnt);
  memset(cnt, 0, sizeof cnt);
  a.init();
  for (int i = 1; i <= n; ++i) {
    reverse(s[i].begin(), s[i].end());
    a.insert(s[i]);
  }
  a.build();
  reverse(t.begin(), t.end());
  a.query(t);
  long long ans = 0;
  for (int i = 0; i < t.size() - 1; ++i) {
    ans += 1ll * cnt2[i] * cnt[t.size() - i - 2];
  }
  cout << ans;
  return 0;
}