#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar((x % 10) ^ 48);
}
inline void writen(long long x) {
  write(x);
  puts("");
}
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
const long long inf = 0x3f3f3f3f;
const long long INF = 2147483647;
const double PI = acos(-1);
struct AC_automaton {
  long long fail[N], tr[N][26];
  long long tot, tag[N];
  inline void insert(char* str) {
    long long u = 0;
    for (long long i = 1; str[i]; i++) {
      if (!tr[u][str[i] - 'a']) tr[u][str[i] - 'a'] = ++tot;
      u = tr[u][str[i] - 'a'];
    }
    tag[u]++;
    return;
  }
  queue<long long> q;
  inline void build(void) {
    for (long long i = 0; i < 26; i++)
      if (tr[0][i]) q.push(tr[0][i]);
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      for (long long i = 0; i < 26; i++) {
        if (tr[u][i]) {
          fail[tr[u][i]] = tr[fail[u]][i];
          tag[tr[u][i]] += tag[fail[tr[u][i]]];
          q.push(tr[u][i]);
        } else
          tr[u][i] = tr[fail[u]][i];
      }
    }
    return;
  }
  inline void solve(char* t, long long* f) {
    long long u = 0;
    for (long long i = 1; t[i]; i++) {
      u = tr[u][t[i] - 'a'];
      f[i] = tag[u];
    }
    return;
  }
} pos, neg;
long long f1[N], f2[N], ans;
char a[N], b[N];
signed main() {
  scanf("%s", a + 1);
  long long n = read();
  for (long long i = 1; i <= n; i++) {
    scanf("%s", b + 1);
    pos.insert(b);
    long long len = strlen(b + 1);
    reverse(b + 1, b + len + 1);
    neg.insert(b);
  }
  pos.build();
  neg.build();
  pos.solve(a, f1);
  long long len = strlen(a + 1);
  reverse(a + 1, a + len + 1);
  neg.solve(a, f2);
  for (long long i = 1; i <= len; i++) ans += f1[i] * f2[len - i];
  writen(ans);
  return 0;
}

### Prompt

Construct a Cpp code solution to the problem outlined:

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;
inline long long read() {
  long long a = 0, f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) a = (a << 3) + (a << 1) + ch - '0';
  return a * f;
}
void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) write(x / 10);
  putchar((x % 10) ^ 48);
}
inline void writen(long long x) {
  write(x);
  puts("");
}
const long long mod = 1e9 + 7;
const long long N = 2e5 + 5;
const long long inf = 0x3f3f3f3f;
const long long INF = 2147483647;
const double PI = acos(-1);
struct AC_automaton {
  long long fail[N], tr[N][26];
  long long tot, tag[N];
  inline void insert(char* str) {
    long long u = 0;
    for (long long i = 1; str[i]; i++) {
      if (!tr[u][str[i] - 'a']) tr[u][str[i] - 'a'] = ++tot;
      u = tr[u][str[i] - 'a'];
    }
    tag[u]++;
    return;
  }
  queue<long long> q;
  inline void build(void) {
    for (long long i = 0; i < 26; i++)
      if (tr[0][i]) q.push(tr[0][i]);
    while (!q.empty()) {
      long long u = q.front();
      q.pop();
      for (long long i = 0; i < 26; i++) {
        if (tr[u][i]) {
          fail[tr[u][i]] = tr[fail[u]][i];
          tag[tr[u][i]] += tag[fail[tr[u][i]]];
          q.push(tr[u][i]);
        } else
          tr[u][i] = tr[fail[u]][i];
      }
    }
    return;
  }
  inline void solve(char* t, long long* f) {
    long long u = 0;
    for (long long i = 1; t[i]; i++) {
      u = tr[u][t[i] - 'a'];
      f[i] = tag[u];
    }
    return;
  }
} pos, neg;
long long f1[N], f2[N], ans;
char a[N], b[N];
signed main() {
  scanf("%s", a + 1);
  long long n = read();
  for (long long i = 1; i <= n; i++) {
    scanf("%s", b + 1);
    pos.insert(b);
    long long len = strlen(b + 1);
    reverse(b + 1, b + len + 1);
    neg.insert(b);
  }
  pos.build();
  neg.build();
  pos.solve(a, f1);
  long long len = strlen(a + 1);
  reverse(a + 1, a + len + 1);
  neg.solve(a, f2);
  for (long long i = 1; i <= len; i++) ans += f1[i] * f2[len - i];
  writen(ans);
  return 0;
}

```