#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = getchar();
  }
  x *= f;
}
const int maxlen = 2e5 + 50;
int n, m;
int a[maxlen], b[maxlen];
char t[maxlen];
string s[maxlen];
namespace AC {
int all;
int sum[maxlen];
int fail[maxlen];
int ch[maxlen][26];
inline void newnode(int &u) {
  u = ++all;
  sum[u] = 0;
  memset(ch[u], 0, sizeof(ch[u]));
}
void init() {
  all = 0;
  sum[0] = 0;
  memset(ch[0], 0, sizeof(ch[0]));
}
void insert(string &s, int n) {
  int u = 0;
  for (int i = 0; i <= n - 1; ++i) {
    int c = ((s[i]) - 'a');
    if (!ch[u][c]) newnode(ch[u][c]);
    u = ch[u][c];
  }
  ++sum[u];
}
void getfail() {
  static int q[maxlen], hd, tl;
  hd = tl = 0;
  fail[0] = 0;
  for (int c = 0; c <= 25; ++c) {
    int u = ch[0][c];
    if (u) fail[u] = 0, q[tl++] = u;
  }
  while (hd < tl) {
    int r = q[hd++];
    for (int c = 0; c <= 25; ++c) {
      int u = ch[r][c];
      if (!u) {
        ch[r][c] = ch[fail[r]][c];
        continue;
      }
      q[tl++] = u;
      int v = fail[r];
      while (v && !ch[v][c]) v = fail[v];
      fail[u] = ch[v][c];
      sum[u] += sum[fail[u]];
    }
  }
}
void find(char *s, int n, int *a) {
  int u = 0;
  for (int i = 0; i <= n - 1; ++i) {
    int c = ((s[i]) - 'a');
    u = ch[u][c];
    a[i] = sum[u];
  }
}
}  // namespace AC
void work(int *a) {
  AC::init();
  for (int i = 1; i <= n; ++i) AC::insert(s[i], s[i].length());
  AC::getfail();
  AC::find(t, m, a);
}
long long solve() {
  long long an = 0;
  work(a);
  reverse(t, t + m);
  for (int i = 1; i <= n; ++i) reverse(s[i].begin(), s[i].end());
  work(b);
  for (int i = 0; i <= m - 2; ++i) an += (long long)a[i] * b[m - i - 2];
  return an;
}
int main() {
  scanf("%s", t), m = strlen(t);
  read(n);
  for (int i = 1; i <= n; ++i) {
    static char tmp[maxlen];
    scanf("%s", tmp);
    s[i] = tmp;
  }
  printf("%I64d\n", solve());
  return 0;
}

### Prompt

Please formulate 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;
template <class T>
void read(T &x) {
  x = 0;
  int f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 - '0' + ch;
    ch = getchar();
  }
  x *= f;
}
const int maxlen = 2e5 + 50;
int n, m;
int a[maxlen], b[maxlen];
char t[maxlen];
string s[maxlen];
namespace AC {
int all;
int sum[maxlen];
int fail[maxlen];
int ch[maxlen][26];
inline void newnode(int &u) {
  u = ++all;
  sum[u] = 0;
  memset(ch[u], 0, sizeof(ch[u]));
}
void init() {
  all = 0;
  sum[0] = 0;
  memset(ch[0], 0, sizeof(ch[0]));
}
void insert(string &s, int n) {
  int u = 0;
  for (int i = 0; i <= n - 1; ++i) {
    int c = ((s[i]) - 'a');
    if (!ch[u][c]) newnode(ch[u][c]);
    u = ch[u][c];
  }
  ++sum[u];
}
void getfail() {
  static int q[maxlen], hd, tl;
  hd = tl = 0;
  fail[0] = 0;
  for (int c = 0; c <= 25; ++c) {
    int u = ch[0][c];
    if (u) fail[u] = 0, q[tl++] = u;
  }
  while (hd < tl) {
    int r = q[hd++];
    for (int c = 0; c <= 25; ++c) {
      int u = ch[r][c];
      if (!u) {
        ch[r][c] = ch[fail[r]][c];
        continue;
      }
      q[tl++] = u;
      int v = fail[r];
      while (v && !ch[v][c]) v = fail[v];
      fail[u] = ch[v][c];
      sum[u] += sum[fail[u]];
    }
  }
}
void find(char *s, int n, int *a) {
  int u = 0;
  for (int i = 0; i <= n - 1; ++i) {
    int c = ((s[i]) - 'a');
    u = ch[u][c];
    a[i] = sum[u];
  }
}
}  // namespace AC
void work(int *a) {
  AC::init();
  for (int i = 1; i <= n; ++i) AC::insert(s[i], s[i].length());
  AC::getfail();
  AC::find(t, m, a);
}
long long solve() {
  long long an = 0;
  work(a);
  reverse(t, t + m);
  for (int i = 1; i <= n; ++i) reverse(s[i].begin(), s[i].end());
  work(b);
  for (int i = 0; i <= m - 2; ++i) an += (long long)a[i] * b[m - i - 2];
  return an;
}
int main() {
  scanf("%s", t), m = strlen(t);
  read(n);
  for (int i = 1; i <= n; ++i) {
    static char tmp[maxlen];
    scanf("%s", tmp);
    s[i] = tmp;
  }
  printf("%I64d\n", solve());
  return 0;
}

```