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_automation {
  int q[200010];
  int qb, qf, used;
  int m = 26;
  struct node {
    int nxt[30], fail, cnt;
    void clear() {
      memset(nxt, -1, sizeof nxt);
      fail = -1;
      cnt = 0;
    }
  } mem[200010];
  int newnode() {
    int ans = ++used;
    mem[ans].clear();
    return ans;
  }
  void init() {
    used = -1;
    newnode();
    qb = qf = 0;
  }
  void insert(char *s, int n, int r) {
    int now = 0;
    for (int i = 0; i < n; i++) {
      if (mem[now].nxt[s[i] - 'a'] == -1) mem[now].nxt[s[i] - 'a'] = newnode();
      now = mem[now].nxt[s[i] - 'a'];
    }
    mem[now].cnt += r;
    return;
  }
  void build() {
    mem[0].fail = 0;
    for (int i = 0; i < m; i++) {
      if (mem[0].nxt[i] == -1)
        mem[0].nxt[i] = 0;
      else {
        mem[mem[0].nxt[i]].fail = 0;
        q[qb++] = mem[0].nxt[i];
      }
    }
    while (qb > qf) {
      int u = q[qf++];
      mem[u].cnt += mem[mem[u].fail].cnt;
      for (int i = 0; i < m; i++) {
        if (mem[u].nxt[i] == -1)
          mem[u].nxt[i] = mem[mem[u].fail].nxt[i];
        else {
          mem[mem[u].nxt[i]].fail = mem[mem[u].fail].nxt[i];
          q[qb++] = mem[u].nxt[i];
        }
      }
    }
  }
} AC1, AC2;
char s[200010], t[200010], ss[200010];
long long cnt[200010];
int main() {
  scanf("%s", t);
  int n = strlen(t);
  int x = 0;
  cin >> x;
  AC1.init();
  AC2.init();
  while (x--) {
    scanf("%s", ss);
    AC1.insert(ss, strlen(ss), 1);
    reverse(ss, ss + strlen(ss));
    AC2.insert(ss, strlen(ss), 1);
  }
  AC1.build();
  AC2.build();
  for (int i = 0; i < n; i++) cnt[i] = 1;
  int st = 0;
  for (int i = 0; i < n; i++) {
    st = AC1.mem[st].nxt[t[i] - 'a'];
    cnt[i] *= AC1.mem[st].cnt;
  }
  st = 0;
  long long ans = 0;
  for (int i = n - 1; i > 0; i--) {
    st = AC2.mem[st].nxt[t[i] - 'a'];
    cnt[i - 1] *= AC2.mem[st].cnt;
    ans += cnt[i - 1];
  }
  cout << ans << endl;
}