#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long MODpow(long long input, long long n, long long difference) {
  long long res = 1, y = input;
  while (n > 0) {
    if (n & 1) res = (res * y) % difference;
    y = (y * y) % difference;
    n /= 2;
  }
  return res % difference;
}
template <class T>
T _abs(T n) {
  return (n < 0 ? -n : n);
}
template <class T>
T _max(T input, T b) {
  return (!(input < b) ? input : b);
}
template <class T>
T _min(T input, T b) {
  return (input < b ? input : b);
}
template <class T>
T gcd(T input, T b) {
  return (b != 0 ? gcd<T>(b, input % b) : input);
}
template <class T>
T lcm(T input, T b) {
  return (input / gcd<T>(input, b) * b);
}
inline int fi() {
  int n = 0;
  int ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  return n;
}
inline void fo(int input) {
  char snum[20];
  int iterator = 0;
  do {
    snum[iterator++] = input % 10 + 48;
    input = input / 10;
  } while (input != 0);
  iterator = iterator - 1;
  while (iterator >= 0) putchar(snum[iterator--]);
  putchar('\n');
}
int MOD = 1e9 + 7, INF = 1e9;
long long INFLL = 1e18;
long long unsigned INFLLU = 18446744073709551615ULL;
long double EPS = 1e-12;
inline int inv(int input, int p = MOD) { return MODpow(input, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline void addMOD(int& input, int val, int p = MOD) {
  if ((input = (input + val)) >= p) input -= p;
}
inline void subMOD(int& input, int val, int p = MOD) {
  if ((input = (input - val)) < 0) input += p;
}
struct AhoCorasick {
  static const int N = 26;
  static const char A = 'a';
  struct Node {
    int ch[N];
    int fail, cnt;
    Node() {
      fill(ch, ch + N, 0);
      fail = 0;
      cnt = 0;
    }
  };
  vector<Node> t;
  AhoCorasick() {
    t.reserve(200005);
    t.emplace_back();
  }
  void add(const string& p) {
    int x = 0;
    for (char c : p) {
      int k = c - A;
      if (!t[x].ch[k]) {
        t[x].ch[k] = t.size();
        t.emplace_back();
      }
      x = t[x].ch[k];
    }
    t[x].cnt++;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < N; i++) {
      if (t[0].ch[i]) q.push(t[0].ch[i]);
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < N; i++) {
        int v = t[u].ch[i];
        if (!v) continue;
        q.push(v);
        int f = t[u].fail;
        while (f && !t[f].ch[i]) {
          f = t[f].fail;
        }
        f = t[v].fail = t[f].ch[i];
        t[v].cnt += t[f].cnt;
      }
    }
  }
  vector<int> query(const string& s) {
    int n = s.size();
    vector<int> res(n);
    int x = 0;
    for (int i = 0; i < n; i++) {
      int k = s[i] - A;
      while (x && !t[x].ch[k]) {
        x = t[x].fail;
      }
      x = t[x].ch[k];
      res[i] = t[x].cnt;
    }
    return res;
  }
};
void solve() {
  AhoCorasick pre, suf;
  string T;
  cin >> T;
  int n;
  cin >> n;
  for (int _ = 0; _ < n; _++) {
    string s;
    cin >> s;
    pre.add(s);
    reverse(s.begin(), s.end());
    suf.add(s);
  }
  pre.build();
  suf.build();
  auto f = pre.query(T);
  reverse(T.begin(), T.end());
  auto g = suf.query(T);
  reverse(g.begin(), g.end());
  long long res = 0;
  for (int i = 0; i < (int)T.size() - 1; i++) {
    res += (long long)f[i] * g[i + 1];
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}

### 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;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long MODpow(long long input, long long n, long long difference) {
  long long res = 1, y = input;
  while (n > 0) {
    if (n & 1) res = (res * y) % difference;
    y = (y * y) % difference;
    n /= 2;
  }
  return res % difference;
}
template <class T>
T _abs(T n) {
  return (n < 0 ? -n : n);
}
template <class T>
T _max(T input, T b) {
  return (!(input < b) ? input : b);
}
template <class T>
T _min(T input, T b) {
  return (input < b ? input : b);
}
template <class T>
T gcd(T input, T b) {
  return (b != 0 ? gcd<T>(b, input % b) : input);
}
template <class T>
T lcm(T input, T b) {
  return (input / gcd<T>(input, b) * b);
}
inline int fi() {
  int n = 0;
  int ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  return n;
}
inline void fo(int input) {
  char snum[20];
  int iterator = 0;
  do {
    snum[iterator++] = input % 10 + 48;
    input = input / 10;
  } while (input != 0);
  iterator = iterator - 1;
  while (iterator >= 0) putchar(snum[iterator--]);
  putchar('\n');
}
int MOD = 1e9 + 7, INF = 1e9;
long long INFLL = 1e18;
long long unsigned INFLLU = 18446744073709551615ULL;
long double EPS = 1e-12;
inline int inv(int input, int p = MOD) { return MODpow(input, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline void addMOD(int& input, int val, int p = MOD) {
  if ((input = (input + val)) >= p) input -= p;
}
inline void subMOD(int& input, int val, int p = MOD) {
  if ((input = (input - val)) < 0) input += p;
}
struct AhoCorasick {
  static const int N = 26;
  static const char A = 'a';
  struct Node {
    int ch[N];
    int fail, cnt;
    Node() {
      fill(ch, ch + N, 0);
      fail = 0;
      cnt = 0;
    }
  };
  vector<Node> t;
  AhoCorasick() {
    t.reserve(200005);
    t.emplace_back();
  }
  void add(const string& p) {
    int x = 0;
    for (char c : p) {
      int k = c - A;
      if (!t[x].ch[k]) {
        t[x].ch[k] = t.size();
        t.emplace_back();
      }
      x = t[x].ch[k];
    }
    t[x].cnt++;
  }
  void build() {
    queue<int> q;
    for (int i = 0; i < N; i++) {
      if (t[0].ch[i]) q.push(t[0].ch[i]);
    }
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int i = 0; i < N; i++) {
        int v = t[u].ch[i];
        if (!v) continue;
        q.push(v);
        int f = t[u].fail;
        while (f && !t[f].ch[i]) {
          f = t[f].fail;
        }
        f = t[v].fail = t[f].ch[i];
        t[v].cnt += t[f].cnt;
      }
    }
  }
  vector<int> query(const string& s) {
    int n = s.size();
    vector<int> res(n);
    int x = 0;
    for (int i = 0; i < n; i++) {
      int k = s[i] - A;
      while (x && !t[x].ch[k]) {
        x = t[x].fail;
      }
      x = t[x].ch[k];
      res[i] = t[x].cnt;
    }
    return res;
  }
};
void solve() {
  AhoCorasick pre, suf;
  string T;
  cin >> T;
  int n;
  cin >> n;
  for (int _ = 0; _ < n; _++) {
    string s;
    cin >> s;
    pre.add(s);
    reverse(s.begin(), s.end());
    suf.add(s);
  }
  pre.build();
  suf.build();
  auto f = pre.query(T);
  reverse(T.begin(), T.end());
  auto g = suf.query(T);
  reverse(g.begin(), g.end());
  long long res = 0;
  for (int i = 0; i < (int)T.size() - 1; i++) {
    res += (long long)f[i] * g[i + 1];
  }
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}

```