#include <bits/stdc++.h>
using namespace std;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 214748364;
const long long linf = 1e15;
const double PI = acos(-1.0);
long long read() {
  long long t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  return t * f;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline long long C(long long n, long long m, long long ans = 1) {
  for (long long i = 0; i < m; i++) ans *= (n - i);
  for (long long i = m; i; i--) ans /= i;
  return ans;
}
inline long long A(long long n, long long m, long long ans = 1) {
  for (long long i = n; i > n - m; i--) ans *= i;
  return ans;
}
extern const int MAXN = 2e5 + 5;
extern const int N = MAXN + 10;
int n;
long long f[MAXN], g[MAXN], ans = 0;
string str[MAXN], tmp;
namespace ACM {
const int SZ = 26;
int root, cnt;
int nx[N][SZ], fail[N], id[N];
int newnode() {
  cnt++;
  for (int i = 0; i < SZ; i++) nx[cnt][i] = 0;
  fail[cnt] = id[cnt] = 0;
  return cnt;
}
void init() { cnt = 0, root = newnode(); }
void insert(string &s) {
  int n = s.length(), now = root;
  for (int i = 0; i < n; i++) {
    if (!nx[now][s[i] - 'a']) nx[now][s[i] - 'a'] = newnode();
    now = nx[now][s[i] - 'a'];
  }
  id[now]++;
}
void build() {
  queue<int> q;
  fail[root] = root;
  for (int i = 0; i < SZ; i++) {
    if (!nx[root][i])
      nx[root][i] = root;
    else
      fail[nx[root][i]] = root, q.push(nx[root][i]);
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < SZ; i++) {
      if (nx[now][i]) {
        fail[nx[now][i]] = nx[fail[now]][i];
        id[nx[now][i]] += id[fail[nx[now][i]]];
        q.push(nx[now][i]);
      } else
        nx[now][i] = nx[fail[now]][i];
    }
  }
}
void match(string &s, long long f[]) {
  int now = root, n = s.length(), t;
  for (int i = 0; i < n; i++) {
    now = nx[now][s[i] - 'a'], t = now;
    f[i] = id[t];
  }
}
};  // namespace ACM
int work() {
  cin >> tmp >> n;
  ACM::init();
  for (int i = 1; i <= n; i++) cin >> str[i], ACM::insert(str[i]);
  ACM::build(), ACM::match(tmp, f);
  ACM::init();
  for (int i = 1; i <= n; i++)
    reverse(str[i].begin(), str[i].end()), ACM::insert(str[i]);
  ACM::build(), reverse(tmp.begin(), tmp.end()), ACM::match(tmp, g);
  int n = tmp.length();
  for (int i = 0; i < n - 1; i++) ans += f[i] * g[n - i - 2];
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  work();
  return 0;
}

### Prompt

Generate 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;
const int next_x[8] = {0, 1, -1, 0, 1, 1, -1, -1};
const int next_y[8] = {1, 0, 0, -1, 1, -1, -1, 1};
const int inf = 214748364;
const long long linf = 1e15;
const double PI = acos(-1.0);
long long read() {
  long long t = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    t = t * 10 + ch - '0';
    ch = getchar();
  }
  return t * f;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline long long C(long long n, long long m, long long ans = 1) {
  for (long long i = 0; i < m; i++) ans *= (n - i);
  for (long long i = m; i; i--) ans /= i;
  return ans;
}
inline long long A(long long n, long long m, long long ans = 1) {
  for (long long i = n; i > n - m; i--) ans *= i;
  return ans;
}
extern const int MAXN = 2e5 + 5;
extern const int N = MAXN + 10;
int n;
long long f[MAXN], g[MAXN], ans = 0;
string str[MAXN], tmp;
namespace ACM {
const int SZ = 26;
int root, cnt;
int nx[N][SZ], fail[N], id[N];
int newnode() {
  cnt++;
  for (int i = 0; i < SZ; i++) nx[cnt][i] = 0;
  fail[cnt] = id[cnt] = 0;
  return cnt;
}
void init() { cnt = 0, root = newnode(); }
void insert(string &s) {
  int n = s.length(), now = root;
  for (int i = 0; i < n; i++) {
    if (!nx[now][s[i] - 'a']) nx[now][s[i] - 'a'] = newnode();
    now = nx[now][s[i] - 'a'];
  }
  id[now]++;
}
void build() {
  queue<int> q;
  fail[root] = root;
  for (int i = 0; i < SZ; i++) {
    if (!nx[root][i])
      nx[root][i] = root;
    else
      fail[nx[root][i]] = root, q.push(nx[root][i]);
  }
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i < SZ; i++) {
      if (nx[now][i]) {
        fail[nx[now][i]] = nx[fail[now]][i];
        id[nx[now][i]] += id[fail[nx[now][i]]];
        q.push(nx[now][i]);
      } else
        nx[now][i] = nx[fail[now]][i];
    }
  }
}
void match(string &s, long long f[]) {
  int now = root, n = s.length(), t;
  for (int i = 0; i < n; i++) {
    now = nx[now][s[i] - 'a'], t = now;
    f[i] = id[t];
  }
}
};  // namespace ACM
int work() {
  cin >> tmp >> n;
  ACM::init();
  for (int i = 1; i <= n; i++) cin >> str[i], ACM::insert(str[i]);
  ACM::build(), ACM::match(tmp, f);
  ACM::init();
  for (int i = 1; i <= n; i++)
    reverse(str[i].begin(), str[i].end()), ACM::insert(str[i]);
  ACM::build(), reverse(tmp.begin(), tmp.end()), ACM::match(tmp, g);
  int n = tmp.length();
  for (int i = 0; i < n - 1; i++) ans += f[i] * g[n - i - 2];
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  work();
  return 0;
}

```