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

public class Solution {
	
	static InputReader in = new InputReader();
	static PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		String s = in.nextString();;
		int N = s.length();
		String g = in.nextLine();
		boolean[] isBad = new boolean[26];
		for(int i=0; i<26; i++){
			isBad[i] = g.charAt(i)=='0';
		}
		
		int[] badCum = new int[N+1];
		badCum[0] = 0;
		for(int i=1; i<=N; i++){
			badCum[i] = badCum[i-1];
			if(isBad[s.charAt(i-1)-'a']) badCum[i]++;
		}
		
		int k = in.nextInt();

		int[][] M = suffixMat(s);
		int[] sfx = new int[N];
		
		int last = M.length-1;
		for(int i=0; i<N; i++){
			sfx[M[last][i]] = i;
		}

		int result = findLastIndex(badCum,sfx[0],k)-sfx[0];
		for(int j=1; j<N; j++){
			int lul = findLastIndex(badCum, sfx[j], k);
			int increase = lul-sfx[j]-lcp(M, sfx[j], sfx[j-1]);
			if(increase>0) result += increase;
		}
		
		out.println(result);
		out.flush();
	}  
	private static void printArray(int[] array){
		for(int i=0; i<array.length; i++){
			System.err.print(array[i] + " ");
		}
		System.err.println();
	}
	
	private static int findLastIndex(int[] badCum, int i, int k) {
		// TODO Auto-generated method stub
		int lo = i;
		int hi = badCum.length-1;
		int t = badCum[i]+k;
		while(lo<hi){
			int mid = lo + (hi-lo+1)/2;
			if(badCum[mid]>t){
				hi = mid-1;
			} else {
				lo = mid;
			}
		}
		return lo;
	}

	private static int[][] suffixMat(String s){
		char[] c = s.toCharArray();
		int size = 33-Integer.numberOfLeadingZeros(c.length-1);
		int[][] M = new int[size][c.length];
		
		for(int i=0; i<c.length; i++){
			M[0][i] = c[i] - 'a';
		}
		
		int step = 1;
		for(int i=1;i<size; i++){
			Suffix[] L = new Suffix[c.length];
			for(int j=0; j<c.length; j++){
				L[j] = new Suffix(M[i-1][j], j+step<c.length ? M[i-1][j+step] : -1, j);
			}
			Arrays.sort(L);
			M[i][L[0].index] = 0;
			for(int j=1; j<c.length; j++){
				M[i][L[j].index] = (L[j].x == L[j-1].x && L[j].y == L[j-1].y) ? M[i][L[j-1].index] : j;
			}
			step <<= 1;
		}
		
		return M;
	}
	
	private static Suffix[] radixSort(Suffix[] L){
		return countingSort(countingSort(L, false), true);
	}
	
	private static Suffix[] countingSort(Suffix[] L, boolean x){
		int N = L.length;
		int[] count = new int[Math.max(203,N+1)];
		for(int i=0; i<N; i++){
			if(x)
				count[L[i].x+1]++;
			else
				count[L[i].y+1]++;
		}
		
		for(int i=1; i<count.length; i++){
			count[i] += count[i-1];
		}
		
		Suffix[] o1 = new Suffix[N];
		for(int i=N-1; i>=0; i--){
			if(x)
				o1[--count[L[i].x+1]] = L[i];
			else
				o1[--count[L[i].y+1]] = L[i];
		}
		return o1;
	}
	
	private static int lcp(int[][] m, int i, int j){
		int res = 0;
		int val = (1 << m.length-1);
		for(int step=m.length-1; step>=0; step--){
			if(m[step][i]==m[step][j]){
				res += val;
				i += val;
				j += val;
				if(i>=m[0].length || j>=m[0].length) return res; //probably not necessary, check!
			}
			val >>= 1;
		}
		
		return res;
	}
	
	
	private static class Suffix implements Comparable<Suffix>{
		int x; int y; int index;
		Suffix(int x, int y, int index){
			this.x = x; this.y = y; this.index = index;
		}
		@Override
		public int compareTo(Suffix L) {
			if(this.x==L.x) return this.y-L.y;
			return this.x-L.x;
		}
		@Override
		public String toString() {
			return "Suffix [x=" + x + ", y=" + y + ", index=" + index + "]";
		}
	}

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

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

			private 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 String nextLine() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				StringBuilder res = new StringBuilder();
				do {
					res.appendCodePoint(c);
					c = read();
				} while (!isEndOfLine(c));
				return res.toString();
			}

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

			public long nextLong() {
				int c = read();
				while (isSpaceChar(c))
					c = read();
				int sgn = 1;
				if (c == '-') {
					sgn = -1;
					c = read();
				}
				long 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 int nextInt() {
				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;
			}

			private boolean isSpaceChar(int c) {
				return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
			}

			private boolean isEndOfLine(int c) {
				return c == '\n' || c == '\r' || c == -1;
			}
			
			private int[] nextArray(int N){
				int[] a = new int[N];
				for(int i=0; i<N; i++)
					a[i] = nextInt();
				return a;
			}
		}
}