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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Round166D {

	public static class HashingUtility {
		//If tle comes we can reduce number of hashes to even two...
		//Utilities
		final int[] m = new int[] { (int) 1e9 + 7, (int) 982451653, (int) 2038074743 };
		final int[] p = new int[] { (int) 3571, (int) 7919, (int) 541 };
		public int max;
		long[][] pre;
		long[][] invpre;
		int primes;
		String main_str;

		public long fast(long a, long n, long mod) { // used for inverse calculation and power calculation
			if (n == 0) {
				return 1;
			} else if (n == 1) {
				return a % mod;
			}
			long ans = fast(a, n / 2, mod);
			ans = ans * ans;
			ans %= mod;
			if ((n & 1) == 1) {
				ans = ans * (a % mod);
				ans %= mod;
			}
			return ans;
		}

		public HashingUtility(int primes, int max) {
			this.max = max;
			this.primes = primes;
			pre = new long[max][primes];
			invpre = new long[max][primes];
			PreCompute();
		}

		public void PreCompute() {
			//creates powers and inverse powers for each hash
			for (int i = 0; i < primes; i++) {
				long val = p[i];
				pre[0][i] = 1;
				invpre[0][i] = 1;
				long invval = fast(p[i], m[i] - 2, m[i]);
				long mod = m[i];
				for (int j = 1; j < max; j++) {
					pre[j][i] = (pre[j - 1][i] * val) % mod;
					invpre[j][i] = (invpre[j - 1][i] * invval) % mod;
				}
			}
		}

	}

	public static class HashingTemplate {
		HashingUtility utis;
		int[][] prefix;
		int[][] suffix;
		String str;
		int primes;
		int n;

		public HashingTemplate(HashingUtility utis, String str, int primes) {
			this.str = str;
			this.utis = utis;
			this.n = str.length();
			this.primes = primes;
			prefix = new int[n][primes];
			suffix = new int[n][primes];
			PREFIX();
			SUFFIX();
		}

		public int add(int a, int b, int mod) {
			long ans = (long) a + (long) b;
			if (ans >= mod) {
				ans -= mod;
			}
			return (int) ans;
		}

		public int mul(int a, int b, int mod) {
			long ans = (long) a * (long) b;
			if (ans >= mod) {
				ans %= mod;
			}
			return (int) ans;
		}

		public int get(char cc) {
			if (cc >= 'a' && cc <= 'z') {
				return cc - 'a' + 1;
			}
			//Considering only capital letters 
			return cc - 'A' + 'z' - 'a' + 2;
		}

		public void PREFIX() {
			for (int j = 0; j < primes; j++) {
				prefix[0][j] = get(str.charAt(0));
				int mod = utis.m[j];
				for (int i = 1; i < n; i++) {
					prefix[i][j] = add(prefix[i - 1][j], mul(get(str.charAt(i)), (int) utis.pre[i][j], mod), mod);
				}
			}
		}

		public void SUFFIX() {
			for (int j = 0; j < primes; j++) {
				suffix[n - 1][j] = get(str.charAt(n - 1));
				int mod = utis.m[j];
				for (int i = n - 2; i >= 0; i--) {
					suffix[i][j] = add(suffix[i + 1][j], mul(get(str.charAt(i)), (int) utis.pre[n - i - 1][j], mod),
							mod);
				}
			}
		}

		public int[] RangeHash_Prefix(int start, int end) {// here start refers to left and end refers to right
			int[] hashes = new int[primes];
			for (int i = 0; i < primes; i++) {
				long curr = (prefix[end][i] - (start == 0 ? 0 : prefix[start - 1][i]));
				if (curr < 0) {
					curr += utis.m[i];
				}
				curr *= utis.invpre[start][i];
				curr %= utis.m[i];
				hashes[i] = (int) curr;
			}
			return hashes;
		}

		public int[] RangeHash_Suffix(int start, int end) { // here start refers to left and end refers to right
			int[] hashes = new int[primes];
			for (int i = 0; i < primes; i++) {
				long curr = (suffix[start][i] - (end == n - 1 ? 0 : suffix[end + 1][i]));
				if (curr < 0) {
					curr += utis.m[i];
				}
				curr *= utis.invpre[n - end - 1][i];
				curr %= utis.m[i];
				hashes[i] = (int) curr;
			}
			return hashes;
		}

		public boolean check(int[] hash1, int[] hash2) {
			int n = hash1.length;
			for (int i = 0; i < n; i++) {
				if (hash1[i] != hash2[i]) {
					return false;
				}
			}
			return true;
		}
	}

	
	public static void solve() {
		HashingUtility utis = new HashingUtility(2, 1510);
		String str = s.next();
		HashingTemplate hash = new HashingTemplate(utis, str, 2);
		String judge = s.next();	
		int k = s.nextInt();
		int n = str.length();
		int count = 0;
		for(int i = 1; i <= n; i++) {
			HashSet<Pair> check = new HashSet<Pair>();
			int countbad = 0;
			for(int j = 0; j < i; j++) {
				if(judge.charAt(str.charAt(j) - 'a') == '0') {
					countbad++;
				}
			}
			for(int j = i - 1; j < n; j++) {
				if(countbad <= k) {
					int[] hashes = hash.RangeHash_Prefix(j - i + 1, j);
					check.add(new Pair(hashes[0], hashes[1]));
				}
				if(j != n - 1) {
					int start = j - i + 1;
					if(judge.charAt(str.charAt(start) - 'a') == '0') {
						countbad--;
					}
					if(judge.charAt(str.charAt(j + 1) - 'a') == '0') {
						countbad++;
					}
				}
			}
			count += check.size();
		}
		out.println(count);
	}
	
	public static class Pair implements Comparable<Pair> {
		long x;
		long y;

		public Pair(long x, long y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(Pair x) {
			//ascending order
			if (this.x == x.x) {
				return Long.compare(this.y, x.y);
			} else {
				return Long.compare(this.x, x.x);
			}
			//descending order
			//		if(this.x==x.x) {
			//			return Long.compare(x.y, this.y);
			//		}else {
			//			return Long.compare(x.x, this.x);
			//		}
		}

		//Use it rarely because it has about 0.115% collision rate which is quite 
		//and hence it will constantly keep go into equal function and hence slow
		public int hashCode() {
			return Long.hashCode(x) ^ Long.hashCode(y);
		}

		public boolean equals(Object o) {
			if (!(o instanceof Pair)) {
				return false;
			}
			Pair x = (Pair) o;
			if (x.x == this.x && x.y == this.y) {
				return true;
			} else {
				return false;
			}
		}
	}

	public static void main(String[] args) {
		out = new PrintWriter(new BufferedOutputStream(System.out));
		s = new FastReader();
		solve();
		out.close();
	}

	public static FastReader s;
	public static PrintWriter out;

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	
}
