#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
const int A = 26;
char s[N], t[N];
struct AC {
  int tot = 0;
  int g[N][A], f[N], cnt[N];
  inline int newnode() { return ++tot; }
  inline void insert(char *s) {
    int cur = 0;
    for (int i = 0; s[i]; ++i) {
      int &nxt = g[cur][s[i] - 'a'];
      if (nxt == 0) nxt = newnode();
      cur = nxt;
    }
    ++cnt[cur];
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < A; ++i)
      if (g[0][i]) q.push(g[0][i]);
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int i = 0; i < A; ++i) {
        int nxt = g[cur][i];
        if (nxt == 0) {
          continue;
        }
        q.push(nxt);
        int fa = f[cur];
        while (fa && !g[fa][i]) fa = f[fa];
        f[nxt] = g[fa][i];
        cnt[nxt] += cnt[f[nxt]];
      }
    }
  }
  vector<int> match(char *s) {
    int len = strlen(s);
    vector<int> ret(len);
    for (int cur = 0, i = 0; i < len; ++i) {
      int ch = s[i] - 'a';
      while (cur && !g[cur][ch]) cur = f[cur];
      cur = g[cur][ch];
      ret[i] = cnt[cur];
    }
    return ret;
  }
  void print(int cur = 0) {
    cerr << "cnt " << cur << " = " << cnt[cur] << " fail = " << f[cur] << endl;
    for (int i = 0; i < A; ++i)
      if (g[cur][i]) {
        cerr << "from " << cur << " via " << char(i + 'a') << " to "
             << g[cur][i] << endl;
        print(g[cur][i]);
      }
  }
} left_ac, right_ac;
int match[N];
int main() {
  scanf("%s", s);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", t);
    int len = strlen(t);
    left_ac.insert(t);
    reverse(t, t + len);
    right_ac.insert(t);
  }
  left_ac.build();
  right_ac.build();
  auto left_cnt = left_ac.match(s);
  int len = strlen(s);
  reverse(s, s + len);
  auto right_cnt = right_ac.match(s);
  reverse(right_cnt.begin(), right_cnt.end());
  long long ans = 0;
  for (int i = 1; i < len; ++i) ans += 1ll * left_cnt[i - 1] * right_cnt[i];
  printf("%lld\n", ans);
}

### Prompt

Please provide a CPP coded solution to the problem described below:

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 = 2e5 + 1;
const int A = 26;
char s[N], t[N];
struct AC {
  int tot = 0;
  int g[N][A], f[N], cnt[N];
  inline int newnode() { return ++tot; }
  inline void insert(char *s) {
    int cur = 0;
    for (int i = 0; s[i]; ++i) {
      int &nxt = g[cur][s[i] - 'a'];
      if (nxt == 0) nxt = newnode();
      cur = nxt;
    }
    ++cnt[cur];
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < A; ++i)
      if (g[0][i]) q.push(g[0][i]);
    while (!q.empty()) {
      int cur = q.front();
      q.pop();
      for (int i = 0; i < A; ++i) {
        int nxt = g[cur][i];
        if (nxt == 0) {
          continue;
        }
        q.push(nxt);
        int fa = f[cur];
        while (fa && !g[fa][i]) fa = f[fa];
        f[nxt] = g[fa][i];
        cnt[nxt] += cnt[f[nxt]];
      }
    }
  }
  vector<int> match(char *s) {
    int len = strlen(s);
    vector<int> ret(len);
    for (int cur = 0, i = 0; i < len; ++i) {
      int ch = s[i] - 'a';
      while (cur && !g[cur][ch]) cur = f[cur];
      cur = g[cur][ch];
      ret[i] = cnt[cur];
    }
    return ret;
  }
  void print(int cur = 0) {
    cerr << "cnt " << cur << " = " << cnt[cur] << " fail = " << f[cur] << endl;
    for (int i = 0; i < A; ++i)
      if (g[cur][i]) {
        cerr << "from " << cur << " via " << char(i + 'a') << " to "
             << g[cur][i] << endl;
        print(g[cur][i]);
      }
  }
} left_ac, right_ac;
int match[N];
int main() {
  scanf("%s", s);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", t);
    int len = strlen(t);
    left_ac.insert(t);
    reverse(t, t + len);
    right_ac.insert(t);
  }
  left_ac.build();
  right_ac.build();
  auto left_cnt = left_ac.match(s);
  int len = strlen(s);
  reverse(s, s + len);
  auto right_cnt = right_ac.match(s);
  reverse(right_cnt.begin(), right_cnt.end());
  long long ans = 0;
  for (int i = 1; i < len; ++i) ans += 1ll * left_cnt[i - 1] * right_cnt[i];
  printf("%lld\n", ans);
}

```