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

public class D_271 {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		char[] s = sc.next().toCharArray();
		String bad = sc.next();
		int k = sc.nextInt();
		
		int n = s.length;
		
		int[] pre = new int[n];
		pre[0] = bad.charAt(s[0] - 'a') == '0' ? 1 : 0;
		for(int i = 1; i < n; i++)
			pre[i] = pre[i - 1] + (bad.charAt(s[i] - 'a') == '0' ? 1 : 0);
		
		int m1 = (int)1e9+7, m2 = 1000002449;
		int[] p1 = new int[n];
		p1[0] = 1;
		for(int i = 1; i < n; i++)
			p1[i] = (int)((1l * p1[i - 1] * 31) % m1);
		int[] p2 = new int[n];
		p2[0] = 1;
		for(int i = 1; i < n; i++)
			p2[i] = (int)((1l * p2[i - 1] * 41) % m2);
		
		int[] hash1 = new int[n];
		hash1[0] = s[0] - 'a' + 1;
		for(int i = 1; i < n; i++)
			hash1[i] = (int)((1l * hash1[i - 1] + ((1l * (s[i] - 'a' + 1) * p1[i]) % m1)) % m1);
		
		int[] hash2 = new int[n];
		hash2[0] = s[0] - 'a' + 1;
		for(int i = 1; i < n; i++)
			hash2[i] = (int)((1l * hash2[i - 1] + ((1l * (s[i] - 'a' + 1) * p2[i]) % m2)) % m2);
		
		int cnt = 0;
		TreeSet<Pair> set;
		for(int l = 1; l <= n; l++) {
			set = new TreeSet<>();
			for(int i = 0; i <= n - l; i++) {
				int j = i + l - 1;
				int x = pre[j] - (i == 0 ? 0 : pre[i - 1]);
				if(x <= k) {
					int diff = n - l - i;
					int h1 = (int)((1l * (hash1[j] - (i == 0 ? 0 : hash1[i - 1])) * p1[diff]) % m1);
					h1 = ((h1 % m1) + m1) % m1;
					
					int h2 = (int)((1l * (hash2[j] - (i == 0 ? 0 : hash2[i - 1])) * p2[diff]) % m2);
					h2 = ((h2 % m2) + m2) % m2;
					
					set.add(new Pair(h1, h2));
				}
			}
			cnt += set.size();
		}
		
		pw.println(cnt);
		pw.flush();
	}
	
	public static class Pair implements Comparable<Pair> {
		int h1, h2;
		
		public Pair(int h1, int h2) {
			this.h1 = h1;
			this.h2 = h2;
		}
		
		public int compareTo(Pair p) {
			if(this.h1 == p.h1)
				return this.h2 - p.h2;
			return this.h1 - p.h1;
		}
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

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

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

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

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

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

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}
