#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
using namespace std;
const int base =
    chrono::steady_clock::now().time_since_epoch().count() % 1000000000 + 30;
const int mod[] = {
    1018199999, 1027799999, 1031999999, 1047899999, 1062599999,
};
const int hashesUsed = 2;
int modex(int b, int e, int m) {
  int h = 1;
  while (e) {
    if (e & 1) h = (long long)h * b % m;
    b = (long long)b * b % m;
    e >>= 1;
  }
  return h;
}
vector<array<int, hashesUsed> > prec(200001);
char buff[200001];
string readString() {
  scanf("%s", buff);
  return buff;
}
void getRun(const string& s, vector<array<int, hashesUsed> >& out) {
  int n = s.size();
  out.resize(n + 1);
  for (int i = hashesUsed; i--;) {
    out[0][i] = 0;
    for (int j = 0; j < n; j++) {
      out[j + 1][i] = (out[j][i] + (long long)s[j] * prec[j][i]) % mod[i];
    }
  }
}
array<int, hashesUsed> getHash(const vector<array<int, hashesUsed> >& rhash,
                               int l, int r) {
  array<int, hashesUsed> ret;
  for (int i = hashesUsed; i--;)
    ret[i] = (long long)(rhash[r][i] - rhash[l][i] + mod[i]) *
             prec[200000 - l][i] % mod[i];
  return ret;
}
array<int, hashesUsed> getHash(const string& s) {
  array<int, hashesUsed> ret;
  int n = s.size();
  for (int i = hashesUsed; i--;) {
    ret[i] = 0;
    for (int j = 0; j < n; j++) {
      ret[i] = (ret[i] + (long long)s[j] * prec[j][i]) % mod[i];
    }
    ret[i] = (long long)ret[i] * prec[200000][i] % mod[i];
  }
  return ret;
}
int main() {
  for (int i = hashesUsed; i--;) {
    prec[0][i] = 1;
    for (int j = 1; j <= 200000; j++) {
      prec[j][i] = (long long)prec[j - 1][i] * base % mod[i];
    }
  }
  string t = readString();
  vector<array<int, hashesUsed> > runningt;
  getRun(t, runningt);
  int n;
  scanf("%d", &n);
  vector<int> lengths;
  vector<vector<array<int, hashesUsed> > > hashes(t.size() + 1);
  while (n--) {
    string s = readString();
    if (s.size() > t.size()) continue;
    lengths.push_back(s.length());
    hashes[s.size()].push_back(getHash(s));
  }
  sort(lengths.begin(), lengths.end());
  lengths.resize(unique(lengths.begin(), lengths.end()) - lengths.begin());
  vector<int> beginCount(t.size() + 1, 0), endCount(t.size() + 1, 0);
  for (int i : lengths) {
    sort(hashes[i].begin(), hashes[i].end());
    for (int j = 0; j + i <= t.size(); j++) {
      array<int, hashesUsed> toSearch = getHash(runningt, j, j + i);
      int x = upper_bound(hashes[i].begin(), hashes[i].end(), toSearch) -
              lower_bound(hashes[i].begin(), hashes[i].end(), toSearch);
      beginCount[j] += x;
      endCount[j + i] += x;
    }
  }
  long long ans = 0;
  for (int i = 0; i <= t.size(); i++)
    ans += (long long)beginCount[i] * endCount[i];
  printf("%lld\n", ans);
}

### 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>
#pragma gcc optimize("Ofast")
using namespace std;
const int base =
    chrono::steady_clock::now().time_since_epoch().count() % 1000000000 + 30;
const int mod[] = {
    1018199999, 1027799999, 1031999999, 1047899999, 1062599999,
};
const int hashesUsed = 2;
int modex(int b, int e, int m) {
  int h = 1;
  while (e) {
    if (e & 1) h = (long long)h * b % m;
    b = (long long)b * b % m;
    e >>= 1;
  }
  return h;
}
vector<array<int, hashesUsed> > prec(200001);
char buff[200001];
string readString() {
  scanf("%s", buff);
  return buff;
}
void getRun(const string& s, vector<array<int, hashesUsed> >& out) {
  int n = s.size();
  out.resize(n + 1);
  for (int i = hashesUsed; i--;) {
    out[0][i] = 0;
    for (int j = 0; j < n; j++) {
      out[j + 1][i] = (out[j][i] + (long long)s[j] * prec[j][i]) % mod[i];
    }
  }
}
array<int, hashesUsed> getHash(const vector<array<int, hashesUsed> >& rhash,
                               int l, int r) {
  array<int, hashesUsed> ret;
  for (int i = hashesUsed; i--;)
    ret[i] = (long long)(rhash[r][i] - rhash[l][i] + mod[i]) *
             prec[200000 - l][i] % mod[i];
  return ret;
}
array<int, hashesUsed> getHash(const string& s) {
  array<int, hashesUsed> ret;
  int n = s.size();
  for (int i = hashesUsed; i--;) {
    ret[i] = 0;
    for (int j = 0; j < n; j++) {
      ret[i] = (ret[i] + (long long)s[j] * prec[j][i]) % mod[i];
    }
    ret[i] = (long long)ret[i] * prec[200000][i] % mod[i];
  }
  return ret;
}
int main() {
  for (int i = hashesUsed; i--;) {
    prec[0][i] = 1;
    for (int j = 1; j <= 200000; j++) {
      prec[j][i] = (long long)prec[j - 1][i] * base % mod[i];
    }
  }
  string t = readString();
  vector<array<int, hashesUsed> > runningt;
  getRun(t, runningt);
  int n;
  scanf("%d", &n);
  vector<int> lengths;
  vector<vector<array<int, hashesUsed> > > hashes(t.size() + 1);
  while (n--) {
    string s = readString();
    if (s.size() > t.size()) continue;
    lengths.push_back(s.length());
    hashes[s.size()].push_back(getHash(s));
  }
  sort(lengths.begin(), lengths.end());
  lengths.resize(unique(lengths.begin(), lengths.end()) - lengths.begin());
  vector<int> beginCount(t.size() + 1, 0), endCount(t.size() + 1, 0);
  for (int i : lengths) {
    sort(hashes[i].begin(), hashes[i].end());
    for (int j = 0; j + i <= t.size(); j++) {
      array<int, hashesUsed> toSearch = getHash(runningt, j, j + i);
      int x = upper_bound(hashes[i].begin(), hashes[i].end(), toSearch) -
              lower_bound(hashes[i].begin(), hashes[i].end(), toSearch);
      beginCount[j] += x;
      endCount[j + i] += x;
    }
  }
  long long ans = 0;
  for (int i = 0; i <= t.size(); i++)
    ans += (long long)beginCount[i] * endCount[i];
  printf("%lld\n", ans);
}

```