#include <bits/stdc++.h>
using namespace std;
const int Block = 450;
char s[200010];
int len;
char t[200010];
int m;
struct Tire {
  int son[200010][26];
  int cnt[200010];
  int tot;
  int newnode() {
    memset(son[tot], -1, sizeof(son[tot]));
    cnt[tot] = 0, tot++;
    return tot - 1;
  }
  void init() { tot = 0, newnode(); }
  void insert(char *s, int len) {
    int now = 0;
    for (int i = 0; i < len; i++) {
      if (son[now][s[i] - 'a'] == -1) son[now][s[i] - 'a'] = newnode();
      now = son[now][s[i] - 'a'];
    }
    cnt[now]++;
  }
} T;
long long cnt1[200010], cnt2[200010];
int fail[1000010];
void Buildfail(char *s, int m) {
  int j = -1;
  fail[0] = -1;
  for (int i = 1; i <= m; i++) {
    while (j >= 0 && s[j] != s[i - 1]) j = fail[j];
    fail[i] = ++j;
    if (i != m && s[i] == s[fail[i]] && fail[fail[i]] != -1)
      fail[i] = fail[fail[i]];
  }
}
void solve() {
  t[m] = '\0';
  Buildfail(t, m);
  for (int i = 0, k = 0; i < len; i++) {
    while (k >= 0 && t[k] != s[i]) k = fail[k];
    k++;
    if (k == m) cnt2[i]++, cnt1[i - m + 1]++;
  }
}
int main() {
  scanf("%s", s), len = strlen(s);
  int n;
  scanf("%d", &n);
  T.init();
  for (int i = 0; i < n; i++) {
    scanf("%s", t), m = strlen(t);
    if (m <= Block)
      T.insert(t, m);
    else
      solve();
  }
  for (int i = 0; i < len; i++) {
    int now = 0, j = i;
    while (now != -1) {
      cnt1[i] += T.cnt[now], cnt2[j - 1] += T.cnt[now];
      if (j == len) break;
      now = T.son[now][s[j] - 'a'], j++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    ans += 1ll * cnt2[i] * cnt1[i + 1];
  }
  printf("%I64d\n", ans);
  return 0;
}

### Prompt

Your task is to create a Cpp solution to the following 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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int Block = 450;
char s[200010];
int len;
char t[200010];
int m;
struct Tire {
  int son[200010][26];
  int cnt[200010];
  int tot;
  int newnode() {
    memset(son[tot], -1, sizeof(son[tot]));
    cnt[tot] = 0, tot++;
    return tot - 1;
  }
  void init() { tot = 0, newnode(); }
  void insert(char *s, int len) {
    int now = 0;
    for (int i = 0; i < len; i++) {
      if (son[now][s[i] - 'a'] == -1) son[now][s[i] - 'a'] = newnode();
      now = son[now][s[i] - 'a'];
    }
    cnt[now]++;
  }
} T;
long long cnt1[200010], cnt2[200010];
int fail[1000010];
void Buildfail(char *s, int m) {
  int j = -1;
  fail[0] = -1;
  for (int i = 1; i <= m; i++) {
    while (j >= 0 && s[j] != s[i - 1]) j = fail[j];
    fail[i] = ++j;
    if (i != m && s[i] == s[fail[i]] && fail[fail[i]] != -1)
      fail[i] = fail[fail[i]];
  }
}
void solve() {
  t[m] = '\0';
  Buildfail(t, m);
  for (int i = 0, k = 0; i < len; i++) {
    while (k >= 0 && t[k] != s[i]) k = fail[k];
    k++;
    if (k == m) cnt2[i]++, cnt1[i - m + 1]++;
  }
}
int main() {
  scanf("%s", s), len = strlen(s);
  int n;
  scanf("%d", &n);
  T.init();
  for (int i = 0; i < n; i++) {
    scanf("%s", t), m = strlen(t);
    if (m <= Block)
      T.insert(t, m);
    else
      solve();
  }
  for (int i = 0; i < len; i++) {
    int now = 0, j = i;
    while (now != -1) {
      cnt1[i] += T.cnt[now], cnt2[j - 1] += T.cnt[now];
      if (j == len) break;
      now = T.son[now][s[j] - 'a'], j++;
    }
  }
  long long ans = 0;
  for (int i = 0; i < len; i++) {
    ans += 1ll * cnt2[i] * cnt1[i + 1];
  }
  printf("%I64d\n", ans);
  return 0;
}

```