You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.

A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string  slsl + 1...sr.

The substring s[l...r] is good, if among the letters  sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).

Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] ≠ s[p...q].

Input

The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.

The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.

The third line of the input consists a single integer k (0 ≤ k ≤ |s|) — the maximum acceptable number of bad characters in a good substring.

Output

Print a single integer — the number of distinct good substrings of string s.

Examples

Input

ababab
01000000000000000000000000
1


Output

5


Input

acbacbacaa
00000000000000000000000000
2


Output

8

Note

In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".

In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * 
 * @author Saju
 *
 */

public class Main {

	static int[] dx = { 0, 1, 0, -1 };
	static int[] dy = { -1, 0, 1, 0 };

	static final int MOD = 1000000007;
	static final int MAX = 100000007;

	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);

		String str = in.next();
		
		String goodbads = in.next();
		for (int i = 0; i < 26; i++) {
			int val = goodbads.charAt(i) - '0';
			checker[i] = val;
		}

		 k = in.nextInt();

		Trie trie = new Trie();

		char[] cha = str.toCharArray();

		int len = cha.length;
		for (int i = 0; i < len; i++) {
			
			int count = 0;
			boolean isOk = true;
			String st = "";
			TrieNode current = trie.root;
			for(int j = i; j < len; j++){
				int ch = cha[j] - 'a';
				if(checker[ch] == 0){
					count++;
				}
				if(count > k){
					isOk = false;
					break;
				}
				
				if (current.children[ch] == null) {
                    ans++;
                    current.children[ch] = new TrieNode();
                }
                current = current.children[ch];
//				st += String.valueOf(cha[j]);
////				 trie.insert(cha, i, trie.root);
//				trie.insert(trie.root, st);
			}
			
		
			
		}

//		trie.query(0, trie.root);
//		System.out.println(ans - 1);
		System.out.println(ans);
		

	}

	static int ans = 0;
	static int k = 0;
	static int checker[] = new int[30];

	private static class Trie {
		private TrieNode root;

		int count;
		public Trie() {
			root = new TrieNode();
			count = 0;
		}

		void insert(char[] str, int i, TrieNode root){
			if(i == str.length){
				return;
			}
			
			
	        int id= str[i] - 'a';

	        if(root.children[id]==null){
	            TrieNode tn = new TrieNode();
	            root.children[id]= tn;
	            count++;
	        }

	        insert(str,i+1,root.children[id]);
	    }
		
		public void insert(TrieNode current, String value) {

			for (char c : value.toCharArray()) {
				int index = c - 'a';

				if (current.children[index] == null) {
					current.children[index] = new TrieNode();
					count++;
				}

				current = current.children[index];
			}
		}

		void query(int cnt, TrieNode root) {
		
			if (root == null){
				return;
			}
			
			if (cnt > k){
				return;
			}
			ans++;

			for (int i = 0; i < 26; i++) {
				if (root.children[i] == null) {
					continue;
				}
				query(cnt + 1 - checker[i], root.children[i]);
			}

		}

	}

	private static class TrieNode {

		TrieNode[] children;

		TrieNode() {
			this.children = new TrieNode[26];
//			Arrays.fill(children, null);
		}

	}

	/*
	 * static void primeFactorization(int n) {
	 * 
	 * for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { int count =
	 * 0; while (n % i == 0) { count++; n = n / i; } System.out.println("i: " +
	 * i + ", count: " + count);
	 * 
	 * }
	 * 
	 * } if (n != 1) { System.out.println(n); }
	 * 
	 * }
	 * 
	 * static int counter[] = new int[MAX];
	 * 
	 * private static void calculateSumOfDivisor(Map<Integer, Integer> map, int
	 * n) { int sum = 1; for(Integer key : map.keySet()){ int count =
	 * map.get(key); sum *= ((Math.pow(key, count + 1) - 1) / (key - 1)); }
	 * if(sum < MAX){ if(counter[sum] < n){ // System.out.println("H");
	 * counter[sum] = n; }
	 * 
	 * }
	 * 
	 * // System.out.println(sum); }
	 * 
	 * 
	 * 
	 * static int phi[] = new int[MAX]; static int phiStepCount[] = new
	 * int[MAX]; static void computeTotient() {
	 * 
	 * // Create and initialize an array to store // phi or totient values for
	 * (int i = 1; i < MAX; i++) { phi[i] = i; // indicates not evaluated yet //
	 * and initializes for product // formula. }
	 * 
	 * // Compute other Phi values for (int p = 2; p < MAX; p++) {
	 * 
	 * // If phi[p] is not computed already, // then number p is prime if
	 * (phi[p] == p) {
	 * 
	 * // Phi of a prime number p is // always equal to p-1. phi[p] = p - 1;
	 * 
	 * // Update phi values of all // multiples of p for (int i = 2 * p; i <
	 * MAX; i += p) {
	 * 
	 * // Add contribution of p to its // multiple i by multiplying with // (1 -
	 * 1/p) phi[i] = (phi[i] / p) * (p - 1); }
	 * 
	 * // for (int i = p; i < MAX; i += p) { // // phi[i] -= (phi[i] / p); // }
	 * 
	 * } phiStepCount[p] = phiStepCount[phi[p]] + 1; }
	 * 
	 * for(int i = 1; i < MAX; i++){ phiStepCount[i] += phiStepCount[i - 1]; } }
	 * 
	 * public static BigInteger floorOfNthRoot(BigInteger x, int n) { int sign =
	 * x.signum(); if (n <= 0 || (sign < 0)) throw new
	 * IllegalArgumentException(); if (sign == 0) return BigInteger.ZERO; if (n
	 * == 1) return x; BigInteger a; BigInteger bigN = BigInteger.valueOf(n);
	 * BigInteger bigNMinusOne = BigInteger.valueOf(n - 1); BigInteger b =
	 * BigInteger.ZERO.setBit(1 + x.bitLength() / n); do { a = b; b =
	 * a.multiply(bigNMinusOne).add(x.divide(a.pow(n - 1))).divide(bigN); }
	 * while (b.compareTo(a) == -1); return a; }
	 * 
	 * // O(log(max(A, B))). static long gcd(long a, long b) { if (b == 0)
	 * return a; return gcd(b, a % b); }
	 * 
	 * 
	 * private static double getDistance(double x1, double y1, double x2, double
	 * y2) {
	 * 
	 * return Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2); }
	 * 
	 * private static int getDecimal(String str) { int val = 0;
	 * 
	 * for (int i = str.length() - 1, j = 0; i >= 0; i--, j++) { if
	 * (str.charAt(i) == '1') { val += Math.pow(2, j); } } return val; }
	 * 
	 * private static int call(int i, int j, int[][] colors) {
	 * 
	 * if (i >= colors.length) { return 0; }
	 * 
	 * if (dp[i][j] != -1) { return dp[i][j];
	 * 
	 * }
	 * 
	 * int result = Integer.MAX_VALUE;
	 * 
	 * for (int k = 0; k < 3; k++) { if (k == j) { continue; } else { result =
	 * Math.min(result, call(i + 1, k, colors) + colors[i][j]); } }
	 * 
	 * return dp[i][j] = result; }
	 * 
	 * static int dp[][];
	 * 
	 * private static class Graph {
	 * 
	 * List<Edge> adjList[]; int v; boolean visited[]; int first[]; int
	 * second[];
	 * 
	 * Graph(int n) { this.v = n; adjList = new ArrayList[n]; visited = new
	 * boolean[n]; first = new int[n]; second = new int[n];
	 * 
	 * for (int i = 0; i < n; i++) { adjList[i] = new ArrayList<>(); } }
	 * 
	 * public void addEdge(int u, int v, int w) { adjList[u].add(new Edge(u, v,
	 * w)); adjList[v].add(new Edge(v, u, w)); }
	 * 
	 * private void bfsAnother(int source) { Arrays.fill(visited, false);
	 * visited[source] = true; Queue<Integer> queue = new LinkedList<>();
	 * queue.add(source); second[source] = 0;
	 * 
	 * while (!queue.isEmpty()) { int u = queue.remove();
	 * 
	 * for (Edge e : adjList[u]) { if (!visited[e.v]) { queue.add(e.v);
	 * visited[e.v] = true; second[e.v] = second[u] + e.w; } } } }
	 * 
	 * int firstFarthest;
	 * 
	 * private void bfs(int source) { Arrays.fill(visited, false);
	 * visited[source] = true; Queue<Integer> queue = new LinkedList<>();
	 * queue.add(source); int max = 0; first[source] = 0;
	 * 
	 * while (!queue.isEmpty()) { int u = queue.remove(); if (first[u] > max) {
	 * max = first[u]; firstFarthest = u; } for (Edge e : adjList[u]) { if
	 * (!visited[e.v]) { queue.add(e.v); visited[e.v] = true; first[e.v] =
	 * first[u] + e.w; } } } }
	 * 
	 * public int dfs(int source) {
	 * 
	 * visited[source] = true; int val = 0; int max = 0; for (Edge e :
	 * adjList[source]) { val = 0; if (!visited[e.v]) { val += (e.w + dfs(e.v));
	 * } max = Math.max(val, max); }
	 * 
	 * return max; } }
	 * 
	 * private static class Edge { int u; int v; int w;
	 * 
	 * Edge(int u, int v, int w) { this.u = u; this.v = v; this.w = w; } }
	 * 
	 * private static BigInteger fac(int n, int mod) {
	 * 
	 * if (n <= 0) { return BigInteger.ONE; } return
	 * BigInteger.valueOf(n).multiply(fac(n - 1, mod)); }
	 * 
	 * private static long bigMod(long n, long k, long m) {
	 * 
	 * long ans = 1; while (k > 0) { if ((k & 1) == 1) { ans = (ans * n) % m; }
	 * n = (n * n) % m; k >>= 1; } return ans; }
	 * 
	 * private static int upperBound(long[] arr, long num) {
	 * 
	 * int start = 0; int end = arr.length;
	 * 
	 * int mid = 0; int index = 0; while (true) {
	 * 
	 * if (start > end) { break; } mid = (start + end) / 2; if (arr[mid] > num)
	 * { end = mid - 1;
	 * 
	 * } else if (arr[mid] < num) { start = mid + 1; } else { return mid; }
	 * 
	 * }
	 * 
	 * // System.out.println(mid); if (arr[mid] < num) { index = mid + 1; } else
	 * { index = mid; } return index; }
	 */

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}

		public String next() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());

				}
			} catch (IOException e) {
				return null;
			}
			return tokenizer.nextToken();
		}

		public String nextLine() {
			String line = null;
			try {
				tokenizer = null;
				line = reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return line;
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public boolean hasNext() {
			try {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					tokenizer = new StringTokenizer(reader.readLine());
				}
			} catch (Exception e) {
				return false;
			}
			return true;
		}
	}
}