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

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author beginner1010
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        final int Alpha = 27;
        final int SQRT = 447;

        int[] zfunction(String s) {
            int n = s.length();
            int[] z = new int[n];
            int l = 0, r = 0;
            for (int i = 1; i < n; i++) {
                if (i < r) {
                    z[i] = Math.min(z[i - l], r - i);
                }
                while (i + z[i] < n && s.charAt(i + z[i]) == s.charAt(z[i])) {
                    z[i]++;
                }
                if (z[i] + i >= r) {
                    r = z[i] + i;
                    l = i;
                }
            }
            return z;
        }

        String reverese(String s) {
            return new StringBuilder(s).reverse().toString();
        }

        long solve(String t, String[] s) {
            int n = s.length;
            int[][] cnt = new int[2][t.length()];
            for (int rev = 0; rev <= 1; rev++) {

                Trie root = new Trie();
                for (int i = 0; i < n; i++) {
                    if (s[i].length() < SQRT) {
                        root.addWord(s[i]);
                    } else {
                        int[] z = zfunction(s[i].concat(t));
                        for (int idxT = 0; idxT < t.length(); idxT++) {
                            cnt[rev][idxT] += z[idxT + s[i].length()] >= s[i].length() ? 1 : 0;
                        }
                    }
                }

                for (int i = 0; i < t.length(); i++) {
                    cnt[rev][i] += root.count(t, i);
                }

                t = reverese(t);
                for (int i = 0; i < n; i++)
                    s[i] = reverese(s[i]);
            }
            long ans = 0;
            for (int i = 1; i < t.length(); i++) {
                ans += 1L * cnt[1][t.length() - i] * cnt[0][i];
            }
            return ans;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String t = in.nextLine();
            int n = in.nextInt();
            String[] s = new String[n];
            for (int i = 0; i < n; i++) {
                s[i] = in.nextLine();
            }

            long ans = solve(t, s);
            out.println(ans);
        }

        class Trie {
            Trie[] neighbor;
            int count;

            Trie() {
                neighbor = new Trie[Alpha];
            }

            void addWord(String s) {
                Trie current = this;
                for (char ch : s.toCharArray()) {
                    int c = ch - 'a';
                    if (current.neighbor[c] == null) {
                        current.neighbor[c] = new Trie();
                    }
                    current = current.neighbor[c];
                }
                current.count++;
            }

            int count(String s, int start) {
                Trie current = this;
                int res = 0;
                for (int i = start; i < s.length(); i++) {
                    int c = s.charAt(i) - 'a';
                    if (current.neighbor[c] == null) {
                        break;
                    }
                    current = current.neighbor[c];
                    res += current.count;
                }
                return res;
            }

        }

    }

    static class InputReader {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputStream stream;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        private int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isWhitespace(c));
            return res * sgn;
        }

        public String nextLine() {
            int c = read();
            while (isWhitespace(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }

    }
}