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.OutputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.BufferedWriter;
import java.util.Random;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;

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

  static class EVamZadanaStroka {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      if (false) {
        new EVamZadanaStroka.Tester().test();
        return;
      }
      String s = in.next();
      String[] patterns = in.readStringArray(in.readInt());
      long answer = new EVamZadanaStroka.Solve(s, patterns).solve();
      out.print(answer);
    }

    static class Tester {
      Random rnd = new Random(239);

      String randomString(int n, int m) {
        char[] s = new char[n];
        for (int i = 0; i < n; i++) s[i] = (char) ('a' + rnd.nextInt(m));
        return new String(s);
      }

      void test() {
        int n = 10;
        int m = 10;
        for (int t = 0; ; t++) {
          String s = randomString(rnd.nextInt(n) + 1, m);
          int q = rnd.nextInt(5);
          String[] patterns = new String[q];
          for (int i = 0; i < q; i++) patterns[i] = randomString(rnd.nextInt(n) + 1, m);
          boolean fail = false;
          long naive, solve;
          try {
            naive = new EVamZadanaStroka.Naive(s, patterns).solve();
            solve = new EVamZadanaStroka.Solve(s, patterns).solve();
            fail = naive != solve;
          } catch (Exception e) {
            e.printStackTrace();
            fail = true;
          }
          if (fail) {
            System.err.println(s);
            System.err.println(q);
            for (String p : patterns) System.err.println(p);
            return;
          }
        }
      }

    }

    static class Naive {
      String s;
      String[] patterns;

      Naive(String s, String[] patterns) {
        this.s = s;
        this.patterns = patterns;
      }

      long solve() {
        long answer = 0;
        for (String x : patterns) {
          for (String y : patterns) {
            String xy = x + y;
            for (int i = 0; i < s.length(); i++) {
              if (s.substring(i).startsWith(xy)) {
                answer++;
              }
            }
          }
        }
        return answer;
      }

    }

    static class Solve {
      int n;
      char[] s;
      char[][] patterns;
      int[] suffixArray;
      int[] invSuffixArray;
      long[] sum;

      Solve(String s, String[] patterns) {
        this.s = (s + "$").toCharArray();
        this.n = this.s.length;
        this.patterns = new char[patterns.length][];
        for (int i = 0; i < patterns.length; i++) this.patterns[i] = patterns[i].toCharArray();
      }

      long solve() {
        initSuffixArray();
        invSuffixArray = inverse(suffixArray);
        List<IntIntPair>[] queriesByLen = new List[n];
        for (int i = 0; i < n; i++) queriesByLen[i] = new ArrayList<>();
        for (char[] t : patterns) {
          int from = findFirst(t);
          int to = findLast(t);
          if (from <= to) queriesByLen[t.length].add(IntIntPair.makePair(from, to));
        }
        sum = new long[n];
        for (int i = 0; i < n; i++) {
          if (!queriesByLen[i].isEmpty()) {
            processQueries(queriesByLen[i], i);
          }
        }
        for (int i = 1; i < n; i++) sum[i] += sum[i - 1];
        long answer = 0;
        for (int i = 0; i < n; i++) {
          for (IntIntPair p : queriesByLen[i]) {
            int from = p.first;
            int to = p.second;
            long add = sum[to] - sum[from - 1];
            answer += add;
          }
        }
        return answer;
      }

      void processQueries(List<IntIntPair> queries, int shift) {
        int[] delta = new int[n + 1];
        for (IntIntPair p : queries) {
          delta[p.first]++;
          delta[p.second + 1]--;
        }
        for (int i = 0, s = 0; i < n; i++) {
          s += delta[i];
          sum[invSuffixArray[(suffixArray[i] + shift) % n]] += s;
        }
      }

      int[] inverse(int[] a) {
        int n = a.length;
        int[] b = new int[n];
        for (int i = 0; i < n; i++) b[a[i]] = i;
        return b;
      }

      int find(char[] t, int minus) {
        int l = -1;
        int r = s.length;
        while (r - l > 1) {
          int m = l + r >> 1;
          if (compare(suffixArray[m], t) - minus < 0) l = m;
          else r = m;
        }
        return l;
      }

      int findFirst(char[] t) {
        return find(t, 0) + 1;
      }

      int findLast(char[] t) {
        return find(t, 1);
      }

      int compare(int suffixStart, char[] t) {
        for (int i = 0; i < t.length; i++) {
          int c = Character.compare(s[(suffixStart + i) % n], t[i]);
          if (c != 0) return c;
        }
        return 0;
      }

      void countSort(int[] order, int[] type, int typeCount) {
        int[] count = new int[typeCount];
        for (int t : type) count[t]++;
        for (int i = 0, j = 0; i < typeCount; i++) {
          int x = count[i];
          count[i] = j;
          j += x;
        }
        int n = order.length;
        int[] order2 = new int[n];
        for (int x : order) order2[count[type[x]]++] = x;
        System.arraycopy(order2, 0, order, 0, n);
      }

      void initSuffixArray() {
        int n = s.length;
        int[] order = suffixArray = new int[n];
        int[] type = new int[n];
        {
          for (int i = 0; i < n; i++) order[i] = i;
          for (int i = 0; i < n; i++) type[i] = s[i];
          countSort(order, type, 1 << 8);
          type[order[0]] = 0;
          for (int i = 1, j = 0; i < n; i++) {
            if (s[order[i]] != s[order[i - 1]]) j++;
            type[order[i]] = j;
          }
        }
        for (int k = 0; 1 << k < n; k++) {
          int len = 1 << k;
          for (int i = 0; i < n; i++) order[i] = (order[i] - len + n) % n;
          countSort(order, type, n);
          int[] type2 = new int[n];
          type2[order[0]] = 0;
          for (int i = 1, j = 0; i < n; i++) {
            IntIntPair now = IntIntPair.makePair(type[order[i]], type[(order[i] + len) % n]);
            IntIntPair was = IntIntPair.makePair(type[order[i - 1]], type[(order[i - 1] + len) % n]);
            if (!now.equals(was)) j++;
            type2[order[i]] = j;
          }
          System.arraycopy(type2, 0, type, 0, n);
        }
      }

    }

  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void close() {
      writer.close();
    }

    public void print(long i) {
      writer.print(i);
    }

  }

  static class IntIntPair implements Comparable<IntIntPair> {
    public final int first;
    public final int second;

    public static IntIntPair makePair(int first, int second) {
      return new IntIntPair(first, second);
    }

    public IntIntPair(int first, int second) {
      this.first = first;
      this.second = second;
    }

    public boolean equals(Object o) {
      if (this == o) {
        return true;
      }
      if (o == null || getClass() != o.getClass()) {
        return false;
      }

      IntIntPair pair = (IntIntPair) o;

      return first == pair.first && second == pair.second;
    }

    public int hashCode() {
      int result = first;
      result = 31 * result + second;
      return result;
    }

    public String toString() {
      return "(" + first + "," + second + ")";
    }

    public int compareTo(IntIntPair o) {
      int value = Integer.compare(first, o.first);
      if (value != 0) {
        return value;
      }
      return Integer.compare(second, o.second);
    }

  }

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

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

    public String[] readStringArray(int size) {
      String[] array = new String[size];
      for (int i = 0; i < size; i++) {
        array[i] = readString();
      }
      return array;
    }

    public 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 readInt() {
      int c = read();
      while (isSpaceChar(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 (!isSpaceChar(c));
      return res * sgn;
    }

    public String readString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

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

    public String next() {
      return readString();
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);

    }

  }
}