#include <bits/stdc++.h>
using namespace std;
const int K = 26;
struct AhoCorasick {
  struct Vertex {
    int next[K];
    int p = -1;
    int cnt = 0;
    char pch;
    int link = -1;
    int go[K];
    Vertex(int p = -1, char ch = '$') : p(p), pch(ch) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Vertex> t;
  AhoCorasick() { t.emplace_back(Vertex()); }
  void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
      int c = (islower(ch) ? ch - 'a' : 26 + ch - 'A');
      if (t[v].next[c] == -1) {
        t[v].next[c] = t.size();
        t.emplace_back(v, ch);
      }
      v = t[v].next[c];
    }
    t[v].cnt++;
  }
  int get_cnt(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else {
        t[v].link = go(get_link(t[v].p), t[v].pch);
        t[v].cnt += get_cnt(t[v].link);
      }
    }
    return t[v].cnt;
  }
  int get_link(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else
        t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
  }
  int go(int v, char ch) {
    int c = (islower(ch) ? ch - 'a' : 26 + ch - 'A');
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
        t[v].go[c] = t[v].next[c];
      else
        t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string t;
  cin >> t;
  AhoCorasick pref, suf;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    pref.add_string(s);
    reverse(s.begin(), s.end());
    suf.add_string(s);
  }
  int idx = 0;
  vector<int> cnt_ending((int)t.size(), 0);
  for (int i = (int)t.size() - 1; i >= 0; --i) {
    idx = suf.go(idx, t[i]);
    cnt_ending[i] = suf.get_cnt(idx);
  }
  idx = 0;
  long long rs = 0;
  for (int i = 0; i + 1 < (int)t.size(); ++i) {
    idx = pref.go(idx, t[i]);
    rs += 1ll * pref.get_cnt(idx) * cnt_ending[i + 1];
  }
  cout << rs << "\n";
}

### Prompt

Your challenge is to write 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 K = 26;
struct AhoCorasick {
  struct Vertex {
    int next[K];
    int p = -1;
    int cnt = 0;
    char pch;
    int link = -1;
    int go[K];
    Vertex(int p = -1, char ch = '$') : p(p), pch(ch) {
      fill(begin(next), end(next), -1);
      fill(begin(go), end(go), -1);
    }
  };
  vector<Vertex> t;
  AhoCorasick() { t.emplace_back(Vertex()); }
  void add_string(string const& s) {
    int v = 0;
    for (char ch : s) {
      int c = (islower(ch) ? ch - 'a' : 26 + ch - 'A');
      if (t[v].next[c] == -1) {
        t[v].next[c] = t.size();
        t.emplace_back(v, ch);
      }
      v = t[v].next[c];
    }
    t[v].cnt++;
  }
  int get_cnt(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else {
        t[v].link = go(get_link(t[v].p), t[v].pch);
        t[v].cnt += get_cnt(t[v].link);
      }
    }
    return t[v].cnt;
  }
  int get_link(int v) {
    if (t[v].link == -1) {
      if (v == 0 || t[v].p == 0)
        t[v].link = 0;
      else
        t[v].link = go(get_link(t[v].p), t[v].pch);
    }
    return t[v].link;
  }
  int go(int v, char ch) {
    int c = (islower(ch) ? ch - 'a' : 26 + ch - 'A');
    if (t[v].go[c] == -1) {
      if (t[v].next[c] != -1)
        t[v].go[c] = t[v].next[c];
      else
        t[v].go[c] = v == 0 ? 0 : go(get_link(v), ch);
    }
    return t[v].go[c];
  }
};
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string t;
  cin >> t;
  AhoCorasick pref, suf;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    pref.add_string(s);
    reverse(s.begin(), s.end());
    suf.add_string(s);
  }
  int idx = 0;
  vector<int> cnt_ending((int)t.size(), 0);
  for (int i = (int)t.size() - 1; i >= 0; --i) {
    idx = suf.go(idx, t[i]);
    cnt_ending[i] = suf.get_cnt(idx);
  }
  idx = 0;
  long long rs = 0;
  for (int i = 0; i + 1 < (int)t.size(); ++i) {
    idx = pref.go(idx, t[i]);
    rs += 1ll * pref.get_cnt(idx) * cnt_ending[i + 1];
  }
  cout << rs << "\n";
}

```