#include <bits/stdc++.h>
using namespace std;
using ll = long long;
inline int read();
const int M = 200016, MOD = 1000000007;
struct Aho_Corasick_Automaton {
  int sz = 0;
  int ch[M][26], end[M], fail[M];
  int init(int id = 0) {
    memset(ch[id], 0, sizeof(ch[0]));
    end[id] = fail[id] = 0;
    return sz = id;
  }
  int insert(const char *s) {
    int u = 0;
    for (int i = 0; s[i]; i++) {
      int &v = ch[u][s[i] - 'a'];
      if (!v) v = init(sz + 1);
      u = v;
    }
    ++end[u];
    return u;
  }
  void build() {
    queue<int> q;
    for (int v : ch[0])
      if (v) fail[v] = 0, q.push(v);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int &v = ch[u][i];
        if (v) {
          q.push(v);
          fail[v] = ch[fail[u]][i];
          end[v] += end[fail[v]];
        } else
          v = ch[fail[u]][i];
      }
    }
  }
  int query(int &now, char c) {
    now = ch[now][c - 'a'];
    return end[now];
  }
} AC1, AC2;
char tex[M], tmp[M];
int st[M], ed[M];
int main(void) {
  scanf("%s", tex);
  int n = read();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", tmp);
    AC1.insert(tmp);
    int l = strlen(tmp);
    reverse(tmp, tmp + l);
    AC2.insert(tmp);
  }
  AC1.build();
  AC2.build();
  int len = strlen(tex);
  for (int i = 0, now = 0; tex[i]; ++i) ed[i] = AC1.query(now, tex[i]);
  for (int i = len - 1, now = 0; i >= 0; --i) st[i] = AC2.query(now, tex[i]);
  ll ans = 0;
  for (int i = 0; tex[i + 1]; ++i) ans += 1ll * ed[i] * st[i + 1];
  printf("%I64d\n", ans);
  return 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

### 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;
using ll = long long;
inline int read();
const int M = 200016, MOD = 1000000007;
struct Aho_Corasick_Automaton {
  int sz = 0;
  int ch[M][26], end[M], fail[M];
  int init(int id = 0) {
    memset(ch[id], 0, sizeof(ch[0]));
    end[id] = fail[id] = 0;
    return sz = id;
  }
  int insert(const char *s) {
    int u = 0;
    for (int i = 0; s[i]; i++) {
      int &v = ch[u][s[i] - 'a'];
      if (!v) v = init(sz + 1);
      u = v;
    }
    ++end[u];
    return u;
  }
  void build() {
    queue<int> q;
    for (int v : ch[0])
      if (v) fail[v] = 0, q.push(v);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < 26; i++) {
        int &v = ch[u][i];
        if (v) {
          q.push(v);
          fail[v] = ch[fail[u]][i];
          end[v] += end[fail[v]];
        } else
          v = ch[fail[u]][i];
      }
    }
  }
  int query(int &now, char c) {
    now = ch[now][c - 'a'];
    return end[now];
  }
} AC1, AC2;
char tex[M], tmp[M];
int st[M], ed[M];
int main(void) {
  scanf("%s", tex);
  int n = read();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", tmp);
    AC1.insert(tmp);
    int l = strlen(tmp);
    reverse(tmp, tmp + l);
    AC2.insert(tmp);
  }
  AC1.build();
  AC2.build();
  int len = strlen(tex);
  for (int i = 0, now = 0; tex[i]; ++i) ed[i] = AC1.query(now, tex[i]);
  for (int i = len - 1, now = 0; i >= 0; --i) st[i] = AC2.query(now, tex[i]);
  ll ans = 0;
  for (int i = 0; tex[i + 1]; ++i) ans += 1ll * ed[i] * st[i + 1];
  printf("%I64d\n", ans);
  return 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}

```