#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
const int maxlen = 2e5 + 10;
using namespace std;
int n, cnt = 1;
int to[maxlen][26], siz[maxlen], fail[maxlen], num[maxlen];
long long a[maxlen], b[maxlen];
string t, s[maxn];
long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch <= '9' && ch >= '0');
  return x * f;
}
void add(string s) {
  int now = 1;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    int x = s[i] - 'a';
    if (to[now][x])
      now = to[now][x];
    else
      to[now][x] = ++cnt, now = cnt;
  }
  siz[now]++;
}
void build() {
  queue<int> q;
  for (int i = 0; i < 26; i++) {
    if (to[1][i])
      q.push(to[1][i]), fail[to[1][i]] = 1, num[to[1][i]] = siz[to[1][i]];
    else
      to[1][i] = 1;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (to[u][i])
        fail[to[u][i]] = to[fail[u]][i], q.push(to[u][i]),
        num[to[u][i]] = siz[to[u][i]] + num[fail[to[u][i]]];
      else
        to[u][i] = to[fail[u]][i];
    }
  }
}
void init() {
  cnt = 1;
  memset(num, 0, sizeof(num));
  memset(siz, 0, sizeof(siz));
  memset(to, 0, sizeof(to));
  memset(fail, 0, sizeof(fail));
}
void get(bool fir) {
  int len = t.length();
  int now = 1;
  for (int i = 0; i < len; i++) {
    now = to[now][t[i] - 'a'];
    if (fir)
      a[i] = num[now];
    else
      b[i] = num[now];
  }
}
int main() {
  cin >> t;
  n = read();
  for (int i = 1; i <= n; i++) cin >> s[i], add(s[i]);
  build();
  get(1);
  init();
  reverse(t.begin(), t.end());
  for (int i = 1; i <= n; i++) reverse(s[i].begin(), s[i].end()), add(s[i]);
  build();
  get(0);
  int len = t.length();
  long long ans = 0;
  for (int i = 0; i < len - 1; i++) ans += (a[i] * b[len - 2 - i]);
  cout << ans;
  return 0;
}

### Prompt

In CPP, your task is to solve 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>
const int maxn = 2e5 + 10;
const int maxlen = 2e5 + 10;
using namespace std;
int n, cnt = 1;
int to[maxlen][26], siz[maxlen], fail[maxlen], num[maxlen];
long long a[maxlen], b[maxlen];
string t, s[maxn];
long long read() {
  long long x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - 48;
    ch = getchar();
  } while (ch <= '9' && ch >= '0');
  return x * f;
}
void add(string s) {
  int now = 1;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    int x = s[i] - 'a';
    if (to[now][x])
      now = to[now][x];
    else
      to[now][x] = ++cnt, now = cnt;
  }
  siz[now]++;
}
void build() {
  queue<int> q;
  for (int i = 0; i < 26; i++) {
    if (to[1][i])
      q.push(to[1][i]), fail[to[1][i]] = 1, num[to[1][i]] = siz[to[1][i]];
    else
      to[1][i] = 1;
  }
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < 26; i++) {
      if (to[u][i])
        fail[to[u][i]] = to[fail[u]][i], q.push(to[u][i]),
        num[to[u][i]] = siz[to[u][i]] + num[fail[to[u][i]]];
      else
        to[u][i] = to[fail[u]][i];
    }
  }
}
void init() {
  cnt = 1;
  memset(num, 0, sizeof(num));
  memset(siz, 0, sizeof(siz));
  memset(to, 0, sizeof(to));
  memset(fail, 0, sizeof(fail));
}
void get(bool fir) {
  int len = t.length();
  int now = 1;
  for (int i = 0; i < len; i++) {
    now = to[now][t[i] - 'a'];
    if (fir)
      a[i] = num[now];
    else
      b[i] = num[now];
  }
}
int main() {
  cin >> t;
  n = read();
  for (int i = 1; i <= n; i++) cin >> s[i], add(s[i]);
  build();
  get(1);
  init();
  reverse(t.begin(), t.end());
  for (int i = 1; i <= n; i++) reverse(s[i].begin(), s[i].end()), add(s[i]);
  build();
  get(0);
  int len = t.length();
  long long ans = 0;
  for (int i = 0; i < len - 1; i++) ans += (a[i] * b[len - 2 - i]);
  cout << ans;
  return 0;
}

```