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.*;
import java.math.BigInteger;
import java.util.*;

public class E implements Runnable {
	public static void main (String[] args) {new Thread(null, new E(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		String t = fs.next();
		int n = fs.nextInt();
		String[] pats = new String[n];
		for(int i = 0; i < n; i++) pats[i] = fs.next();
		
		AhoCorasick ac = new AhoCorasick();
		ac.createAhoCorasick(pats);
		
		int m = t.length();
		int[] endsAt = new int[m];
		for(int i = 0, cur = 0; i < m; i++) {
			int let = t.charAt(i)-'a';
			cur = ac.transition[let][cur];
			endsAt[i] = ac.term[cur];
		}
		
		String[] pats2 = new String[n];
		for(int i = 0; i < n; i++) pats2[i] = new StringBuilder(pats[i]).reverse().toString();
		ac.createAhoCorasick(pats2);
		
		int[] startsAt = new int[m];
		for(int i = m-1, cur = 0; i >= 0; i--) {
			int let = t.charAt(i) - 'a';
			cur = ac.transition[let][cur];
			startsAt[i] = ac.term[cur];
		}
		
		long res = 0;
		for(int i = 0; i < m-1; i++) {
			long c1 = endsAt[i];
			c1 *= startsAt[i+1];
			res += c1;
		}
		out.println(res);
		
		out.close();
	}
	
	class AhoCorasick {
		int ALPHA = 26;
		int nodeCount, transition[][];
		int[] term;
		void createAhoCorasick(String[] strs) {
			int maxNodes = 1;
			for(String s : strs) maxNodes += s.length();

			int[][] children = new int[ALPHA][maxNodes];
			int[] leaf = new int[maxNodes];
			nodeCount = 1;
			for(String s : strs) {
				int node = 0;
				for(char ch : s.toCharArray()) {
					int c = ch - 'a';
					if(children[c][node] == 0) children[c][node] = nodeCount++;
					node = children[c][node];
				}
				leaf[node]++;
			}

			transition = new int[ALPHA][nodeCount];
			term = new int[nodeCount];

			ArrayDeque<Integer> queue = new ArrayDeque<>();
			queue.add(0);  queue.add(0);

			while(queue.size() > 0) {
				int node = queue.remove(), suffLink = queue.remove();

				term[node] = leaf[node] + term[suffLink];

				for(int ch = 0; ch < ALPHA; ch++) {
					if(children[ch][node] != 0){
						transition[ch][node] = children[ch][node];
						queue.add(children[ch][node]);
						queue.add(node == 0 ? 0 : transition[ch][suffLink]);
					} else  transition[ch][node] = transition[ch][suffLink];
				}
			}
		}
	}
	
	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}

	}

}