#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 100;
struct AcAm {
  int fail[N], ch[N][26], si[N], size;
  int insert(char *s) {
    int len = strlen(s + 1), u = 0;
    for (int i = 1; i <= len; i++) {
      int c = s[i] - 'a';
      if (!ch[u][c]) ch[u][c] = ++size;
      u = ch[u][c];
    }
    si[u]++;
    return u;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++)
      if (ch[0][i]) q.push(ch[0][i]);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int y = ch[x][i];
        if (y) {
          fail[y] = ch[fail[x]][i];
          si[y] += si[fail[y]];
          q.push(y);
        } else
          ch[x][i] = ch[fail[x]][i];
      }
    }
  }
  int query(int x) { return si[x]; }
} t, rt;
int pos[N], rpos[N];
int main() {
  static char ch[N];
  scanf("%s", ch + 1);
  int m = strlen(ch + 1);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    static char S[N];
    scanf("%s", S + 1);
    int len = strlen(S + 1);
    t.insert(S);
    reverse(S + 1, S + 1 + len);
    rt.insert(S);
  }
  t.build();
  rt.build();
  for (int i = 1, u = 0; i <= m; i++) {
    int c = ch[i] - 'a';
    u = t.ch[u][c];
    pos[i] = t.query(u);
  }
  reverse(ch + 1, ch + 1 + m);
  long long ans = 0;
  for (int i = 1, u = 0; i <= m; i++) {
    int c = ch[i] - 'a';
    u = rt.ch[u][c];
    rpos[m - i + 1] = rt.query(u);
  }
  for (int i = 1; i <= m; i++) {
    ans += pos[i] * 1ll * rpos[i + 1];
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Please create a solution in cpp 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 N = 6e5 + 100;
struct AcAm {
  int fail[N], ch[N][26], si[N], size;
  int insert(char *s) {
    int len = strlen(s + 1), u = 0;
    for (int i = 1; i <= len; i++) {
      int c = s[i] - 'a';
      if (!ch[u][c]) ch[u][c] = ++size;
      u = ch[u][c];
    }
    si[u]++;
    return u;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < 26; i++)
      if (ch[0][i]) q.push(ch[0][i]);
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int y = ch[x][i];
        if (y) {
          fail[y] = ch[fail[x]][i];
          si[y] += si[fail[y]];
          q.push(y);
        } else
          ch[x][i] = ch[fail[x]][i];
      }
    }
  }
  int query(int x) { return si[x]; }
} t, rt;
int pos[N], rpos[N];
int main() {
  static char ch[N];
  scanf("%s", ch + 1);
  int m = strlen(ch + 1);
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    static char S[N];
    scanf("%s", S + 1);
    int len = strlen(S + 1);
    t.insert(S);
    reverse(S + 1, S + 1 + len);
    rt.insert(S);
  }
  t.build();
  rt.build();
  for (int i = 1, u = 0; i <= m; i++) {
    int c = ch[i] - 'a';
    u = t.ch[u][c];
    pos[i] = t.query(u);
  }
  reverse(ch + 1, ch + 1 + m);
  long long ans = 0;
  for (int i = 1, u = 0; i <= m; i++) {
    int c = ch[i] - 'a';
    u = rt.ch[u][c];
    rpos[m - i + 1] = rt.query(u);
  }
  for (int i = 1; i <= m; i++) {
    ans += pos[i] * 1ll * rpos[i + 1];
  }
  cout << ans << endl;
  return 0;
}

```