import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main implements Runnable {

	public void solve() throws IOException {
		char[] c = nextToken().toCharArray();
                int N = c.length;
                char[] isok = nextToken().toCharArray();
                boolean[] isbad = new boolean[26];

                for(int i = 0; i  < 26; i++) isbad[i] = isok[i] == '0';
                int MAX = nextInt();

                long MOD = BigInteger.probablePrime(56, new Random()).longValue();
                Set<Long> hs = new HashSet<Long>();

                for(int i = 0; i < N; i++){
                        long hash = 0;
                        int illegal = 0;
                        for(int j = i; j < N; j++){
                                hash = (hash * 31 + (c[j] - 'a' + 1)) % MOD;
                                if(isbad[c[j] - 'a'])illegal++;
                                if(illegal > MAX) break;
                                hs.add(hash);
                        }
                }

                System.out.println(hs.size());
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

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

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

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

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

	BufferedReader in;
	StringTokenizer tok;
}


/**
     * Created with IntelliJ IDEA.
     * User: brzezinsky
     * Date: 12/13/12
     * Time: 5:43 PM
     * To change this template use File | Settings | File Templates.
     */

    import java.io.*;
    import java.math.BigInteger;
    import java.util.*;

    public class A extends Thread {
        public A(String inputFileName, String outputFileName) {
            try {
                if (inputFileName != null) {
                    this.input = new BufferedReader(new FileReader(inputFileName));
                } else {
                    this.input = new BufferedReader(new InputStreamReader(System.in));
                }
                if (outputFileName != null) {
                    this.output = new PrintWriter(outputFileName);
                } else {
                    this.output = new PrintWriter(System.out);
                }
                this.setPriority(Thread.MAX_PRIORITY);
            } catch (Throwable e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
                System.exit(666);
            }
        }

        static class Pair {
            long a, b;
            public Pair(long a, long b) {
                this.a = a;
                this.b = b;
            }

            @Override
            public boolean equals(Object o) {
                if (this == o) return true;
                if (!(o instanceof Pair)) return false;

                Pair pair = (Pair) o;

                if (a != pair.a) return false;
                if (b != pair.b) return false;

                return true;
            }

            @Override
            public int hashCode() {
                int result = (int) (a ^ (a >>> 32));
                result = 31 * result + (int) (b ^ (b >>> 32));
                return result;
            }
        }

        private void solve() throws Throwable {
            char []c = next().toCharArray();
            char []bad = next().toCharArray();
            for (int i = 0; i < bad.length; ++i) bad[i] -= '0';
            int K = nextInt();
            Random rnd = new Random(System.currentTimeMillis());
            long MOD1 = rnd.nextInt(500000000) + 1000000000;
            long MOD2 = rnd.nextInt(500000000) + 1000000000;
            long []p1 = new long[c.length];
            long []p2 = new long[c.length];
            long mul1 = 61;
            long mul2 = 101;
            p1[0] = 1;
            p2[0] = 1;

            for (int i = 1; i < c.length; ++i) {
                p1[i] = (p1[i - 1] * mul1) % MOD1;
                p2[i] = (p2[i - 1] * mul2) % MOD2;
            }
            long hash1[] = new long[c.length];
            long hash2[] = new long[c.length];
            for (int i = 0; i < c.length; ++i) {
                hash1[i] = (p1[i] * (c[i] - 'a' + 1)) % MOD1;
                if (i > 0) hash1[i] = (hash1[i] + hash1[i - 1]) % MOD1;
                hash2[i] = (p2[i] * (c[i] - 'a' + 1)) % MOD2;
                if (i > 0) hash2[i] = (hash2[i] + hash2[i - 1]) % MOD2;
            }
            int cnt = 0;
            int j = 0;
            HashSet<Pair> set = new HashSet<Pair>();
            for (int i = 0; i < c.length; ++i) {
                while (j < c.length && cnt <= K) {
                    if (bad[c[j] - 'a'] == 0) ++cnt;
                    ++j;
                }
                if (j == c.length && cnt <= K) ++j;
                for (int l = i; l + 1 < j; ++l) {
                    long A = hash1[l];
                    if (i > 0) A -= hash1[i - 1];
                    if (A < 0) A += MOD1;
                    long B = hash2[l];
                    if (i > 0) B -= hash2[i - 1];
                    if (B < 0) B += MOD2;
                    A = (A * p1[c.length - l - 1]) % MOD1;
                    B = (B * p2[c.length - l - 1]) % MOD2;
                    set.add(new Pair(A, B));
                }
                if (bad[c[i] - 'a'] == 0) --cnt;
            }
            output.println(set.size());

        }

        public void run() {
            try {
                solve();
            } catch (Throwable e) {
                System.err.println(e.getMessage());
                e.printStackTrace();
                System.exit(666);
            } finally {
                output.close();
            }
        }

        public static void main(String... args) {
            new A(null, null).start();
            //new A("input.txt", "output.txt").start();
        }

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

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

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

        private String next() throws IOException {
            while (tokens == null || !tokens.hasMoreTokens()) {
                tokens = new StringTokenizer(input.readLine());
            }
            return tokens.nextToken();
        }

        private StringTokenizer tokens;
        private BufferedReader input;
        private PrintWriter output;
    }


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.TreeSet;

public class R166qDGoodSubstrings {

	static int p = 1000000;
	static int mod = 1000000007;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    Set<Integer> ans = new TreeSet<Integer>();

	    for(int i=0;i<s.length;i++){
	    	long rabin = 0,bad = 0;
	    	for(int j=i;j<s.length;j++){
	    		if(good[s[j] - 'a'] == '0')
	    			bad++;
	    		if(bad > k)	break;
	    		rabin = (rabin * p + (s[j] - 'a' + 1));
	    		if(rabin >= mod)	rabin %= mod;
	    		ans.add((int)rabin);
	    	}
	    }

	    w.println(ans.size());
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.TreeSet;

public class R166qDGoodSubstrings {

	static int p = 1000000;
	static int mod = 1000000007;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    Set<Long> ans = new TreeSet<Long>();

	    for(int i=0;i<s.length;i++){
	    	long rabin = 0,bad = 0;
	    	for(int j=i;j<s.length;j++){
	    		if(good[s[j] - 'a'] == '0')
	    			bad++;
	    		if(bad > k)	break;
	    		rabin = (rabin * p + (s[j] - 'a' + 1)) % mod;
	    		ans.add(rabin);
	    	}
	    }

	    w.println(ans.size());
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Set;
import java.util.TreeSet;

public class R166qDGoodSubstrings {

	static int p = 1000000;
	static int mod = 1000000007;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    Set<Integer> ans = new TreeSet<Integer>();

	    for(int i=0;i<s.length;i++){
	    	long rabin = 0,bad = 0;
	    	for(int j=i;j<s.length;j++){
	    		if(good[s[j] - 'a'] == '0')
	    			bad++;
	    		if(bad > k)	break;
	    		rabin = (rabin * p + (s[j] - 'a' + 1)) % mod;
	    		ans.add((int)rabin);
	    	}
	    }

	    w.println(ans.size());
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class R166qDGoodSubstrings {

	static int ALPHA = 26;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    int n = s.length;

	    Trie trie = new Trie();

	    for(int i=0;i<n;i++){
	    	int bad = 0;
	    	for(int j=i;j<n;j++){
	    		if(good[s[j]-'a'] == '0')	bad++;
	    		if(bad == k+1){
	    			trie.add(trie.root,s,i,j);
	    			break;
	    		}
	    	}
	    	if(bad != k+1)
	    		trie.add(trie.root,s,i,n);
	    }

	    w.println(trie.unique);
	    w.close();
	}

	static public class Trie{

		int unique;
		TrieNode root;
		Trie(){
			unique = 0;
			root = new TrieNode();
			root.isLeaf = true;
		}

		public void add(TrieNode curr,char a[],int pos,int len){
			if(!curr.isLeaf)	unique++;
			curr.isLeaf = true;
			if(pos == len)	return;
			if(curr.child[a[pos]-'a'] == null)
				curr.child[a[pos]-'a'] = new TrieNode();
			add(curr.child[a[pos]-'a'],a,pos+1,len);
		}

	}

	static public class TrieNode{
		boolean isLeaf;
		TrieNode child[];
		TrieNode(){
			isLeaf = false;
			child = new TrieNode[ALPHA];
		}
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class R166qDGoodSubstrings {

	static int p1 = 31,p2 = 37;
	static int mod = 1000000007;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    int n = s.length;
	    int hash1[] = new int[n*(n+1)/2];
	    int hash2[] = new int[n*(n+1)/2];
	    int c = 0;

	    for(int i=0;i<n;i++){
	    	long rabin1 = 0,rabin2 = 0,bad = 0;
	    	for(int j=i;j<s.length;j++){
	    		if(good[s[j] - 'a'] == '0')
	    			bad++;
	    		if(bad > k)	break;
	    		rabin1 = (rabin1 * p1 + (s[j] - 'a' + 1));
	    		if(rabin1 >= mod)	rabin1 %= mod;
	    		hash1[c] = (int)rabin1;
	    		rabin2 = (rabin2 * p2 + (s[j] - 'a' + 1));
	    		if(rabin2 >= mod)	rabin2 %= mod;
	    		hash2[c++] = (int)rabin2;
	    	}
	    }

	    for(int i=c;i<hash1.length;i++)
	    	hash1[i] = hash2[i] = Integer.MAX_VALUE;
	    Arrays.sort(hash1);
	    Arrays.sort(hash2);

	    int i = 0,ans1 = 0;
	    while(i < hash1.length && hash1[i] != Integer.MAX_VALUE){
	    	int j = i;
	    	while(j < hash1.length && hash1[j] == hash1[i])	j++;
	    	ans1++;
	    	i = j;
	    }

	    i = 0;
	    int ans2 = 0;

	    while(i < hash2.length && hash2[i] != Integer.MAX_VALUE){
	    	int j = i;
	    	while(j < hash2.length && hash2[j] == hash2[i])	j++;
	    	ans2++;
	    	i = j;
	    }

	    w.println(Math.max(ans1,ans2));
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class R166qDGoodSubstrings {

	static int p = 1000000;
	static int mod = 1000000007;

	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    char s[] = br.readLine().toCharArray();
	    char good[] = br.readLine().toCharArray();
	    int k = ip(br.readLine());

	    int n = s.length;
	    int hashes[] = new int[n*(n+1)/2];
	    int c = 0;

	    for(int i=0;i<n;i++){
	    	long rabin = 0,bad = 0;
	    	for(int j=i;j<s.length;j++){
	    		if(good[s[j] - 'a'] == '0')
	    			bad++;
	    		if(bad > k)	break;
	    		rabin = (rabin * p + (s[j] - 'a' + 1));
	    		if(rabin >= mod)	rabin %= mod;
	    		hashes[c++] = (int)rabin;
	    	}
	    }

	    for(int i=c;i<hashes.length;i++)
	    	hashes[i] = Integer.MAX_VALUE;
	    Arrays.sort(hashes);

	    int i = 0,ans = 0;
	    while(i < hashes.length && hashes[i] != Integer.MAX_VALUE){
	    	int j = i;
	    	while(j < hashes.length && hashes[j] == hashes[i])	j++;
	    	ans++;
	    	i = j;
	    }

	    w.println(ans);
	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	/**
	 * @param args
	 */
	static char[] a, f;
	static Node root = new Node();
	static int K;
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);

		a = r.next().toCharArray();
		f = r.next().toCharArray();
		K = r.nextInt();

		for(int i = 0; i < a.length; i++){
			Node t = root;
			for(int j = i; j < a.length; j++){
				if(t.next[a[j] - 'a'] == null)
					t.next[a[j] - 'a'] = new Node();
				t = t.next[a[j] - 'a'];
			}
		}

		int ret = dfs(root, 0);

		System.out.println(ret - 1);
	}

	private static int dfs(Node x, int h) {
		int ret = h <= K ? 1 : 0;
		for(int i = 0; i < 26; i++)if(x.next[i] != null)
			ret += dfs(x.next[i], h + 1 - (f[i] - '0'));

		return ret;
	}

	static class Node{
		Node[] next;
		public Node(){
			next = new Node[26];
		}
	}
	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	/**
	 * @param args
	 */
	static char[] a, f;
	static Node root = new Node();
	static int K;
	public static void main(String[] args) {
		InputReader r = new InputReader(System.in);

		a = r.next().toCharArray();
		f = r.next().toCharArray();
		K = r.nextInt();

		for(int i = 0; i < a.length; i++){
			Node t = root;
			for(int j = i; j < a.length; j++){
				if(t.next[a[j] - 'a'] == null)
					t.next[a[j] - 'a'] = new Node();
				t = t.next[a[j] - 'a'];
			}
		}

		int ret = dfs(root, 0);

		System.out.println(ret - 1);
	}

	private static int dfs(Node x, int h) {
		int ret = h <= K ? 1 : 0;
		for(int i = 0; i < 26; i++)if(x.next[i] != null)
			ret += dfs(x.next[i], h + 1 - (f[i] - '0'));

		return ret;
	}

	static class Node{
		Node[] next;
		public Node(){
			next = new Node[26];
		}
	}
	static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

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

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

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


import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class CF271D{
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String line = scn.nextLine();
            String good = scn.nextLine();
            int k = scn.nextInt();
            scn.nextLine();
            int n = line.length();
            int[] badCnt = new int[n+1];
            badCnt[0] = 0;
            for (int i=1; i<=n; i++){
                int idx = line.charAt(i-1) - 'a';
                if (good.charAt(idx)=='0')
                    badCnt[i] = badCnt[i-1]+1;
                else badCnt[i] = badCnt[i-1];
            }
            Set<String> ans = new HashSet<>();
            for (int l=1; l<=n; l++){
                for (int r=l; r<=n; r++){
                    int bad = badCnt[r]-badCnt[l-1];
                    if (bad>k) continue;
                    String sub = line.substring(l-1, r);
                    ans.add(sub);
                }
            }
            System.out.println(ans.size());
        }
    }
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class CF271D{
    static class SuffixArray {
        public Integer[] sa;
        public int[] rank;
        public int[] height;
        public int n;
        public String str;
        SACmp cmp;

        public SuffixArray(String str){
            this.str = str;
            this.n = str.length();
            sa = new Integer[n+1];
            rank = new int[n+1];
            height = new int[n+1];
            cmp = new SACmp();
            constructSA();
            constructH();
        }

        private void constructSA(){
            for (int i=0; i<=n; i++) {
                rank[i] = i<n?str.charAt(i):-1;
                sa[i] = i;
            }
            int[] tmp = new int[n+1];
            for (int k=1; k<n; k*=2){
                cmp.k = k;
                Arrays.sort(sa, cmp);
                tmp[sa[0]] = 0;
                for (int i=1; i<=n; i++){
                    tmp[sa[i]] = tmp[sa[i-1]]+Math.min(1, cmp.compare(sa[i], sa[i-1]));
                }
                for (int i=0; i<=n; i++) {
                    rank[i] = tmp[i];
                }
            }
            for (int i=0; i<=n; i++){
                rank[sa[i]] = i;
            }
        }

        private void constructH(){
            int h = 0;
            for (int i=0; i<n; i++){
                int j = sa[rank[i]-1];
                if (h>0) h--;
                while (i+h<n&&j+h<n&&str.charAt(i+h)==str.charAt(j+h)){
                    h++;
                }
                height[rank[i]] = h;
            }
        }

        private class SACmp implements Comparator<Integer> {
            public int k;

            @Override
            public int compare(Integer x, Integer y){
                if (rank[x]!=rank[y]) return rank[x]-rank[y];
                else {
                    int rx = x+k<n?rank[x+k]:-1;
                    int ry = y+k<n?rank[y+k]:-1;
                    return rx-ry;
                }
            }
        }
    }

    static int bs(int[] cnt, int k, int l0, int l, int r){
        while (l<r){
            int mid = (l+r)/2;
            if (cnt[mid+1]-cnt[l0]<=k) {
                if (cnt[mid+2]-cnt[l0]<= k)
                    l = mid + 1;
                else return l;
            }
            else r = mid-1;
        }
        return l;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String str = scn.nextLine();
            String map = scn.nextLine();
            int k = scn.nextInt();
            scn.nextLine();
            SuffixArray sa = new SuffixArray(str);
            int len = str.length();
            int[] cnt = new int[len+1];
            cnt[0] = 0;
            for (int i=1; i<=len; i++){
                cnt[i] = cnt[i-1];
                if (map.charAt(str.charAt(i-1)-'a')=='0')
                    cnt[i]++;
            }
            int ans = 0;
            for (int i=1; i<=len; i++){
                if (cnt[sa.sa[i]+sa.height[i]]-cnt[sa.sa[i]]>k) continue;
                int l = bs(cnt, k, sa.sa[i], sa.sa[i]+sa.height[i], len-1);
                ans += l-(sa.sa[i]+sa.height[i])+1;
            }
            System.out.println(ans);
        }
    }
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class CF271D{
    static class SuffixArray {
        public Integer[] sa;
        public int[] rank;
        public int[] height;
        public int n;
        public String str;
        SACmp cmp;

        public SuffixArray(String str){
            this.str = str;
            this.n = str.length();
            sa = new Integer[n+1];
            rank = new int[n+1];
            height = new int[n+1];
            cmp = new SACmp();
            constructSA();
            constructH();
        }

        private void constructSA(){
            for (int i=0; i<=n; i++) {
                rank[i] = i<n?str.charAt(i):-1;
                sa[i] = i;
            }
            int[] tmp = new int[n+1];
            for (int k=1; k<n; k*=2){
                cmp.k = k;
                Arrays.sort(sa, cmp);
                tmp[sa[0]] = 0;
                for (int i=1; i<=n; i++){
                    tmp[sa[i]] = tmp[sa[i-1]]+Math.min(1, cmp.compare(sa[i], sa[i-1]));
                }
                for (int i=0; i<=n; i++) {
                    rank[i] = tmp[i];
                }
            }
            for (int i=0; i<=n; i++){
                rank[sa[i]] = i;
            }
        }

        private void constructH(){
            int h = 0;
            for (int i=0; i<n; i++){
                int j = sa[rank[i]-1];
                if (h>0) h--;
                while (i+h<n&&j+h<n&&str.charAt(i+h)==str.charAt(j+h)){
                    h++;
                }
                height[rank[i]] = h;
            }
        }

        private class SACmp implements Comparator<Integer> {
            public int k;

            @Override
            public int compare(Integer x, Integer y){
                if (rank[x]!=rank[y]) return rank[x]-rank[y];
                else {
                    int rx = x+k<n?rank[x+k]:-1;
                    int ry = y+k<n?rank[y+k]:-1;
                    return rx-ry;
                }
            }
        }
    }

    static int bs(int[] cnt, int k, int l0, int l, int r){
        while (l<r){
            int mid = (l+r)/2;
            if (cnt[mid+1]-cnt[l0]<=k) {
                if (cnt[mid+2]-cnt[l0]<= k)
                    l = mid + 1;
                else return mid;
            }
            else r = mid-1;
        }
        return l;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String str = scn.nextLine();
            String map = scn.nextLine();
            int k = scn.nextInt();
            scn.nextLine();
            SuffixArray sa = new SuffixArray(str);
            int len = str.length();
            int[] cnt = new int[len+1];
            cnt[0] = 0;
            for (int i=1; i<=len; i++){
                cnt[i] = cnt[i-1];
                if (map.charAt(str.charAt(i-1)-'a')=='0')
                    cnt[i]++;
            }
            int ans = 0;
            for (int i=1; i<=len; i++){
                if (cnt[sa.sa[i]+sa.height[i]+1]-cnt[sa.sa[i]]>k) continue;
                int l = bs(cnt, k, sa.sa[i], sa.sa[i]+sa.height[i], len-1);
                ans += l-(sa.sa[i]+sa.height[i])+1;
            }
            System.out.println(ans);
        }
    }
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class CF271D{
    static class SuffixArray {
        public Integer[] sa;
        public int[] rank;
        public int[] height;
        public int n;
        public String str;
        SACmp cmp;

        public SuffixArray(String str){
            this.str = str;
            this.n = str.length();
            sa = new Integer[n+1];
            rank = new int[n+1];
            height = new int[n+1];
            cmp = new SACmp();
            constructSA();
            constructH();
        }

        private void constructSA(){
            for (int i=0; i<=n; i++) {
                rank[i] = i<n?str.charAt(i):-1;
                sa[i] = i;
            }
            sa[0] = 1;
            sa[n] = 0;
            int[] tmp = new int[n+1];
            for (int k=1; k<n; k*=2){
                cmp.k = k;
                Arrays.sort(sa, cmp);
                tmp[sa[0]] = 0;
                for (int i=1; i<=n; i++){
                    tmp[sa[i]] = tmp[sa[i-1]]+Math.min(1, cmp.compare(sa[i], sa[i-1]));
                }
                for (int i=0; i<=n; i++) {
                    rank[i] = tmp[i];
                }
            }
            for (int i=0; i<=n; i++){
                rank[sa[i]] = i;
            }
        }

        private void constructH(){
            int h = 0;
            for (int i=0; i<n; i++){
                int j = sa[rank[i]-1];
                if (h>0) h--;
                while (i+h<n&&j+h<n&&str.charAt(i+h)==str.charAt(j+h)){
                    h++;
                }
                height[rank[i]] = h;
            }
        }

        private class SACmp implements Comparator<Integer> {
            public int k;

            @Override
            public int compare(Integer x, Integer y){
                if (rank[x]!=rank[y]) return rank[x]-rank[y];
                else {
                    int rx = x+k<n?rank[x+k]:-1;
                    int ry = y+k<n?rank[y+k]:-1;
                    return rx-ry;
                }
            }
        }
    }

    static int bs(int[] cnt, int k, int l0, int l, int r){
        while (l<r){
            int mid = (l+r)/2;
            if (cnt[mid+1]-cnt[l0]<=k) {
                if (cnt[mid+2]-cnt[l0]<= k)
                    l = mid + 1;
                else return mid;
            }
            else r = mid-1;
        }
        return l;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String str = scn.nextLine();
            String map = scn.nextLine();
            int k = scn.nextInt();
            scn.nextLine();
            SuffixArray sa = new SuffixArray(str);
            int len = str.length();
            int[] cnt = new int[len+1];
            cnt[0] = 0;
            for (int i=1; i<=len; i++){
                cnt[i] = cnt[i-1];
                if (map.charAt(str.charAt(i-1)-'a')=='0')
                    cnt[i]++;
            }
            int ans = 0;
            for (int i=1; i<=len; i++){
                if (cnt[sa.sa[i]+sa.height[i]+1]-cnt[sa.sa[i]]>k) continue;
                int l = bs(cnt, k, sa.sa[i], sa.sa[i]+sa.height[i], len-1);
                ans += l-(sa.sa[i]+sa.height[i])+1;
            }
            System.out.println(ans);
        }
    }
}


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class CF271D{
    static class SuffixArray {
        public Integer[] sa;
        public int[] rank;
        public int[] height;
        public int n;
        public String str;
        SACmp cmp;

        public SuffixArray(String str){
            this.str = str;
            this.n = str.length();
            sa = new Integer[n+1];
            rank = new int[n+1];
            height = new int[n+1];
            cmp = new SACmp();
            constructSA();
            constructH();
        }

        private void constructSA(){
            for (int i=0; i<=n; i++) {
                rank[i] = i<n?str.charAt(i):-1;
                sa[i] = i;
            }
           Arrays.sort(sa, cmp);
            int[] tmp = new int[n+1];
            for (int k=1; k<n; k*=2){
                cmp.k = k;
                Arrays.sort(sa, cmp);
                tmp[sa[0]] = 0;
                for (int i=1; i<=n; i++){
                    tmp[sa[i]] = tmp[sa[i-1]]+Math.min(1, cmp.compare(sa[i], sa[i-1]));
                }
                for (int i=0; i<=n; i++) {
                    rank[i] = tmp[i];
                }
            }
            for (int i=0; i<=n; i++){
                rank[sa[i]] = i;
            }
        }

        private void constructH(){
            int h = 0;
            for (int i=0; i<n; i++){
                int j = sa[rank[i]-1];
                if (h>0) h--;
                while (i+h<n&&j+h<n&&str.charAt(i+h)==str.charAt(j+h)){
                    h++;
                }
                height[rank[i]] = h;
            }
        }

        private class SACmp implements Comparator<Integer> {
            public int k;

            @Override
            public int compare(Integer x, Integer y){
                if (rank[x]!=rank[y]) return rank[x]-rank[y];
                else {
                    int rx = x+k<n?rank[x+k]:-1;
                    int ry = y+k<n?rank[y+k]:-1;
                    return rx-ry;
                }
            }
        }
    }

    static int bs(int[] cnt, int k, int l0, int l, int r){
        while (l<r){
            int mid = (l+r)/2;
            if (cnt[mid+1]-cnt[l0]<=k) {
                if (cnt[mid+2]-cnt[l0]<= k)
                    l = mid + 1;
                else return mid;
            }
            else r = mid-1;
        }
        return l;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        while (scn.hasNext()){
            String str = scn.nextLine();
            String map = scn.nextLine();
            int k = scn.nextInt();
            scn.nextLine();
            SuffixArray sa = new SuffixArray(str);
            int len = str.length();
            int[] cnt = new int[len+1];
            cnt[0] = 0;
            for (int i=1; i<=len; i++){
                cnt[i] = cnt[i-1];
                if (map.charAt(str.charAt(i-1)-'a')=='0')
                    cnt[i]++;
            }
            int ans = 0;
            for (int i=1; i<=len; i++){
                if (cnt[sa.sa[i]+sa.height[i]+1]-cnt[sa.sa[i]]>k) continue;
                int l = bs(cnt, k, sa.sa[i], sa.sa[i]+sa.height[i], len-1);
                ans += l-(sa.sa[i]+sa.height[i])+1;
            }
            System.out.println(ans);
        }
    }
}


import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Random;

/**
 * Actual solution is at the top, in class Solver
 */
final public class Main implements Runnable {
	private static String[] args;

	public static void main(String[] args) {
		Main.args = args;
		new Thread(null, new Main(), "MyRunThread", 1 << 27).start();
	}

	@Override
	public void run() {
		long time_beg = -1;
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		if (args.length > 0 && args[0].equals("outside")) {
			time_beg = System.currentTimeMillis();
			try {
				inputStream = new FileInputStream("IO/in.txt");
//				outputStream = new FileOutputStream("IO/out.txt");
			} catch (Exception e) {
				System.err.println(e);
				System.exit(1);
			}
		} else {
			try {
//				inputStream = new FileInputStream("IO/in.txt");
//				outputStream = new FileOutputStream("IO/out.txt");
			} catch (Exception e) {
				System.err.println(e);
				System.exit(1);
			}
		}

		Solver s = new Solver();
		s.in = new InputReader(inputStream);
		s.out = new OutputWriter(outputStream);
		if (args.length > 0 && args[0].equals("outside")) {
			s.dout = new DebugWriter(s.out);
		}

		s.solve();

		if (args.length > 0 && args[0].equals("outside")) {
			s.dout.printFormat("*** Total time: %.3f ***\n", (System.currentTimeMillis() - time_beg) / 1000.0);
		}

		s.out.close();
	}
}

final class Solver {
	InputReader in;
	OutputWriter out;
	DebugWriter dout;

	public void solve() {
		String s = in.readString();

		boolean[] good = new boolean[26];
		String ss = in.readString();
		for (int i = 0; i < 26; ++i)
			good[i] = ss.charAt(i) == '1' ? true : false;

		int k = in.readInt();

		HashSet<Long> set = new HashSet<Long>();

		int n = s.length();

		StringHashGenerator sg = new StringHashGenerator(26);
		StringHash hash = new StringHash(sg, s);

		for (int j = 0; j < n; ++j) {
			int count = 0;
			for (int i = j; i < n; ++i) {
				if (!good[s.charAt(i) - 'a']) ++count;
				if (count > k) break;
				set.add(hash.getHash(j, i));
			}
		}

		out.printLine(set.size());
	}
}

final class InputReader {
	private boolean finished = false;

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

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

	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 int peek() {
		if (numChars == -1)
			return -1;
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				return -1;
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar];
	}

	public int readInt() {
		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;
	}

	public long readLong() {
		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 String readString() {
		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 static boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private String readLine0() {
		StringBuilder buf = new StringBuilder();
		int c = read();
		while (c != '\n' && c != -1) {
			if (c != '\r')
				buf.appendCodePoint(c);
			c = read();
		}
		return buf.toString();
	}

	public String readLine() {
		String s = readLine0();
		while (s.trim().length() == 0)
			s = readLine0();
		return s;
	}

	public String readLine(boolean ignoreEmptyLines) {
		if (ignoreEmptyLines)
			return readLine();
		else
			return readLine0();
	}

	public BigInteger readBigInteger() {
		try {
			return new BigInteger(readString());
		} catch (NumberFormatException e) {
			throw new InputMismatchException();
		}
	}

	public char readCharacter() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		return (char) c;
	}

	public double readDouble() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		double res = 0;
		while (!isSpaceChar(c) && c != '.') {
			if (c == 'e' || c == 'E')
				return res * Math.pow(10, readInt());
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		}
		if (c == '.') {
			c = read();
			double m = 1;
			while (!isSpaceChar(c)) {
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, readInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				m /= 10;
				res += (c - '0') * m;
				c = read();
			}
		}
		return res * sgn;
	}

	public boolean isExhausted() {
		int value;
		while (isSpaceChar(value = peek()) && value != -1)
			read();
		return value == -1;
	}
}

final class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object... objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object... objects) {
		print(objects);
		writer.println();
	}

	public void printFormat(String format, Object... objects) {
		writer.printf(format, objects);
	}

	public void print(char[] objects) {
		writer.print(objects);
	}

	public void printLine(char[] objects) {
		writer.println(objects);
	}

	public void printLine(char[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(int[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(int[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(int[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(short[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(short[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(short[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(long[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(long[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(long[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(double[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(double[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(double[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(byte[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(byte[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(byte[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void print(boolean[] objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(boolean[] objects) {
		print(objects);
		writer.println();
	}

	public void printLine(boolean[][] objects) {
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
	}

	public void close() {
		writer.close();
	}

	public void flush() {
		writer.flush();
	}
}

final class DebugWriter {
	private final OutputWriter writer;

	public DebugWriter(OutputWriter writer) {
		this.writer = writer;
	}

	private void printDebugMessage() {
		writer.print("DEBUG:\t");
	}

	public void printLine(Object... objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printFormat(String format, Object... objects) {
		flush();
		printDebugMessage();
		writer.printFormat(format, objects);
		flush();
	}

	public void printLine(char[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(char[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(double[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(double[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(int[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(int[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(short[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(short[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(long[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(long[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(byte[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(byte[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void printLine(boolean[] objects) {
		flush();
		printDebugMessage();
		writer.printLine(objects);
		flush();
	}

	public void printLine(boolean[][] objects) {
		flush();
		for (int i = 0; i < objects.length; ++i)
			printLine(objects[i]);
		flush();
	}

	public void flush() {
		writer.flush();
	}
}

abstract class IntegerUtils {
	public final static boolean isPrime(long value) {
		if (value < 2) return false;
		for (long divisor = 2; divisor * divisor <= value; ++divisor)
			if (value % divisor == 0)
				return false;
		return true;
	}

	public final static long nextPrime(long from) {
		if (from < 2) return 2;
		from += 1 - (from & 1);
		while (!isPrime(from))
			from += 2;
		return from;
	}

	public final static long power(long value, long exponent, final long MOD) {
		long res = 1;
		while (exponent > 0) {
			if ((exponent & 1) == 1)
				res = (res * value) % MOD;
			exponent /= 2;
			value = (value * value) % MOD;
		}
		return res;
	}

	public final static long power(long value, long exponent) {
		long res = 1;
		while (exponent > 0) {
			if ((exponent & 1) == 1)
				res *= value;
			exponent /= 2;
			value *= value;
		}
		return res;
	}

	public final static double power(double value, long exponent) {
		double res = 1.0;
		while (exponent > 0) {
			if ((exponent & 1) == 1)
				res *= value;
			exponent /= 2;
			value *= value;
		}
		return res;
	}

	public final static long gcd(long a, long b) {
		while (b > 0) {
			a %= b;
			long tmp = a;
			a = b;
			b = tmp;
		}
		return a;
	}

	public final static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}

	/**
	 * a * X[0] + b * X[1] = gcd(a, b)
	 */
	public final static long gcd(long a, long b, long[] X) {
		if (b == 0) {
			X[0] = 1;
			X[1] = 0;
			return a;
		}

		long[] nextX = new long[2];
		long g = gcd(b, a % b, nextX);

		X[0] = nextX[1];
		X[1] = nextX[0] - a / b * nextX[1];

		return g;
	}

	public final static long inverse(long value, final long MOD) {
		long[] X = new long[2];
		long g = gcd(value, MOD, X);

		if (g != 1) return -1;
		X[0] %= MOD;
		if (X[0] < 0) X[0] += MOD;
		return X[0];
	}

	public final static Pair<Long[], Integer[]> factorize(long value) {
		ArrayList<Long> prime = new ArrayList<Long>();
		ArrayList<Integer> power = new ArrayList<Integer>();

		for (long divisor = 2; divisor * divisor <= value; ++divisor)
			if (value % divisor == 0) {
				int p = 0;
				while (value % divisor == 0) {
					++p;
					value /= divisor;
				}

				prime.add(divisor);
				power.add(p);
			}

		if (value > 1) {
			prime.add(value);
			power.add(1);
		}

		return new Pair<Long[], Integer[]>(prime.toArray(new Long[1]), power.toArray(new Integer[1]));
	}

	public final static Pair<Long[], Integer[]> factorize(int value, int[] sieve) {
		if (value >= sieve.length) throw new IllegalArgumentException();
		ArrayList<Long> prime = new ArrayList<Long>();
		ArrayList<Integer> power = new ArrayList<Integer>();

		while (value > 1) {
			int pow = 0;
			int divisor = sieve[value];
			while (sieve[value] == divisor) {
				++pow;
				value /= sieve[value];
			}
			prime.add(Long.valueOf(divisor));
			power.add(pow);
		}
		return new Pair<Long[], Integer[]>(prime.toArray(new Long[1]), power.toArray(new Integer[1]));
	}

	public final static long eulerFunction(long value) {
		long phi = value;
		for (long divisor = 2; divisor * divisor <= value; ++divisor)
			if (value % divisor == 0) {
				while (value % divisor == 0) value /= divisor;
				phi -= phi / divisor;
			}

		if (value > 1) {
			phi -= phi / value;
		}

		return phi;
	}

	public final static long eulerFunction(long value, long[] factors) {
		long phi = value;

		for (long x : factors)
			phi -= phi / x;

		return phi;
	}

	public final static long eulerFunction(long value, int[] sieve) {
		if (value >= sieve.length) throw new IllegalArgumentException();

		long phi = value;

		while (value != 1) {
			int p = sieve[(int) value];
			phi -= phi / p;
			while (sieve[(int) value] == p) value /= p;
		}

		return phi;
	}

	public final static boolean[] sieve(int length) {
		boolean[] sieve = new boolean[length];

		ArrayFiller.fill(sieve, true);
		sieve[0] = sieve[1] = false;

		for (int prime = 2; prime * prime < length; ++prime)
			if (sieve[prime])
				for (int divisor = prime * prime; divisor < length; divisor += prime)
					sieve[divisor] = false;

		return sieve;
	}

	public final static int[] sieveWithSmallestPrimes(int length) {
		int[] sieve = new int[length];

		for (int i = 0; i < length; ++i)
			sieve[i] = i;

		for (int prime = 2; prime * prime < length; ++prime)
			if (sieve[prime] == prime)
				for (int divisor = prime * prime; divisor < length; divisor += prime)
					if (sieve[divisor] == divisor)
						sieve[divisor] = prime;

		return sieve;
	}

	public final static int[] sieveWithBiggestPrimes(int length) {
		int[] sieve = new int[length];

		for (int i = 0; i < length; ++i)
			sieve[i] = i;

		for (int prime = 2; prime * prime < length; ++prime)
			if (sieve[prime] == prime)
				for (int divisor = prime * prime; divisor < length; divisor += prime)
					sieve[divisor] = prime;

		return sieve;
	}
}

abstract class ArrayFiller {
	// fill int array
	public final static void fill(int[] array, int value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(int[][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(int[][][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(int[][][][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(int[][][][][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(int[][][][][][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(int[][][][][][][] array, int value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill short array
	public final static void fill(short[] array, short value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(short[][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(short[][][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(short[][][][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(short[][][][][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(short[][][][][][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(short[][][][][][][] array, short value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill long array
	public final static void fill(long[] array, long value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(long[][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(long[][][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(long[][][][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(long[][][][][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(long[][][][][][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(long[][][][][][][] array, long value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill double array
	public final static void fill(double[] array, double value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(double[][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(double[][][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(double[][][][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(double[][][][][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(double[][][][][][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(double[][][][][][][] array, double value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill boolean array
	public final static void fill(boolean[] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(boolean[][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(boolean[][][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(boolean[][][][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(boolean[][][][][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(boolean[][][][][][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(boolean[][][][][][][] array, boolean value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill byte array
	public final static void fill(byte[] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(byte[][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(byte[][][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(byte[][][][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(byte[][][][][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(byte[][][][][][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(byte[][][][][][][] array, byte value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill char array
	public final static void fill(char[] array, char value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(char[][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(char[][][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(char[][][][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(char[][][][][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(char[][][][][][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(char[][][][][][][] array, char value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	// fill String array
	public final static void fill(String[] array, String value) {
		for (int i = 0; i < array.length; ++i)
			array[i] = value;
	}

	public final static void fill(String[][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(String[][][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(String[][][][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(String[][][][][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(String[][][][][][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}

	public final static void fill(String[][][][][][][] array, String value) {
		for (int i = 0; i < array.length; ++i)
			fill(array[i], value);
	}
}

final class Pair<F, S> {
	public F first;
	public S second;

	public Pair(F first, S second) {
		this.first = first;
		this.second = second;
	}

	@Override
	public int hashCode() {
		int hFirst = first != null ? first.hashCode() : 0;
		int hSecond = second != null ? second.hashCode() : 0;
		return 31 * hFirst + hSecond;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Pair pair = (Pair) o;

		return (first != null ? first.equals(pair.first) : pair.first == null) &&
				(second != null ? second.equals(pair.second) : pair.second == null);
	}

	@Override
	protected Object clone() throws CloneNotSupportedException {
		return new Pair<F, S>(first, second);
	}

	@Override
	public String toString() {
		return "(" + first + ", " + second + ")";
	}
}

final class StringHashGenerator {
	int[] firstReversePower;
	int[] secondReversePower;

	long FIRST_MOD;
	long SECOND_MOD;

	long multiplier;
	long firstReverseMultiplier;
	long secondReverseMultiplier;

	public StringHashGenerator(int alphabetLength) {
		Random rnd = new Random(System.nanoTime());
		FIRST_MOD = IntegerUtils.nextPrime(1000000000 + rnd.nextInt(1000000000));
		SECOND_MOD = IntegerUtils.nextPrime(1000000000 + rnd.nextInt(1000000000));

		multiplier = IntegerUtils.nextPrime(alphabetLength + 1);
		firstReverseMultiplier = IntegerUtils.inverse(multiplier, FIRST_MOD);
		secondReverseMultiplier = IntegerUtils.inverse(multiplier, SECOND_MOD);

		firstReversePower = new int[1];
		secondReversePower = new int[1];

		firstReversePower[0] = 1;
		secondReversePower[0] = 1;
	}

	public void ensureCapacity(int length) {
		if (firstReversePower.length >= length) return;
		int[] oldFirst = firstReversePower;
		int[] oldSecond = secondReversePower;
		firstReversePower = new int[length];
		secondReversePower = new int[length];
		for (int i = 0; i < oldFirst.length; ++i) {
			firstReversePower[i] = oldFirst[i];
			secondReversePower[i] = oldSecond[i];
		}
		for (int i = oldFirst.length; i < length; ++i) {
			firstReversePower[i] = (int) (firstReversePower[i - 1] * firstReverseMultiplier % FIRST_MOD);
			secondReversePower[i] = (int) (secondReversePower[i - 1] * secondReverseMultiplier % SECOND_MOD);
		}
	}
}

final class StringHash {
	private int[] firstHash;
	private int[] secondHash;

	StringHashGenerator generator;

	public StringHash(StringHashGenerator generator, CharSequence string) {
		this.generator = generator;
		generator.ensureCapacity(string.length());

		firstHash = new int[string.length()];
		secondHash = new int[string.length()];

		firstHash[0] = string.charAt(0) + 1;
		secondHash[0] = string.charAt(0) + 1;

		long firstMultiplier = generator.multiplier;
		long secondMultiplier = generator.multiplier;

		for (int i = 1; i < string.length(); ++i) {
			firstHash[i] = (int) ((firstHash[i - 1] + (string.charAt(i) + 1) * firstMultiplier) % generator.FIRST_MOD);
			firstMultiplier = firstMultiplier * generator.multiplier % generator.FIRST_MOD;

			secondHash[i] = (int) ((secondHash[i - 1] + (string.charAt(i) + 1) * secondMultiplier) % generator.SECOND_MOD);
			secondMultiplier = secondMultiplier * generator.multiplier % generator.SECOND_MOD;
		}
	}

	public long getHash() {
		return getHash(0, firstHash.length - 1);
	}

	public long getHash(int startIndex, int endIndex) {
		long hash1 = firstHash[endIndex];
		long hash2 = secondHash[endIndex];

		if (startIndex > 0) {
			hash1 += -firstHash[startIndex - 1] + generator.FIRST_MOD;
			hash1 = hash1 * generator.firstReversePower[startIndex] % generator.FIRST_MOD;

			hash2 += -secondHash[startIndex - 1] + generator.SECOND_MOD;
			hash2 = hash2 * generator.secondReversePower[startIndex] % generator.SECOND_MOD;
		}

		return (hash1 << 32) | hash2;
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	class Pair {

		int a, b;

		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int hashCode() {
			return a * 31 + b;
		}

		@Override
		public boolean equals(Object arg0) {
			Pair arg = (Pair) arg0;
			return a == arg.a && b == arg.b;
		}

	}

	static final int MODULES = 2;

	int modulo [] = {1000000007, 1000000009};
	int prime [] = {41, 43};

	int n, k;
	int bads[];
	long hash[][];
	long p[][];

	boolean isGood (int l, int r) {
		int sum = bads[r];
		if (l > 0) sum -= bads[l - 1];
		return sum <= k;
	}

	int getHash (int j, int l, int r) {
		long h = hash[j][r];
		if (l > 0) h = (h - hash[j][l - 1] + modulo[j]) % modulo[j];
		h *= p[j][n - l - 1];
		h %= modulo[j];
		return (int) h;
	}

	Pair getHash (int l, int r) {
		return new Pair (getHash(0, l, r), getHash(1, l, r));
	}

	public void solve () throws Exception {
		char s [] = in.readLine().toCharArray();
		char bad [] = in.readLine().toCharArray();
		k = sc.nextInt();

		n = s.length;
		bads = new int [n];
		for (int i = 0; i < n; i++) {
			if (i > 0) bads[i] = bads[i - 1];
			if (bad[s[i] - 'a'] == '0') bads[i]++;
		}

		p = new long [2][n + 1];
		for (int j = 0; j < MODULES; j++) {
			p[j][0] = 1;
			for (int i = 1; i <= n; i++) {
				p[j][i] = p[j][i - 1] * prime[j];
				p[j][i] %= modulo[j];
			}
		}

		hash = new long [2][n + 1];
		for (int j = 0; j < MODULES; j++) {
			for (int i = 0; i < n; i++) {
				if (i > 0) hash[j][i] = hash[j][i - 1];
				hash[j][i] += p[j][i] * (s[i] - 'a' + 1);
				hash[j][i] %= modulo[j];
			}
		}

		int ans = 0;
		for (int len = 1; len <= n; len++) {
			HashSet<Pair> set = new HashSet<>();
			for (int j = 0; j + len - 1 < n; j++) {
				if (isGood(j, j + len - 1)) {
					set.add(getHash(j, j + len - 1));
				}
			}
			ans += set.size();
		}

		out.println(ans);
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Solution.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Solution(), "", (1 << 26));
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

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

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

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

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

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

public class Solution implements Runnable {

	class Pair {

		int a, b;

		public Pair(int a, int b) {
			this.a = a;
			this.b = b;
		}

		@Override
		public int hashCode() {
			return a * 31 + b;
		}

		@Override
		public boolean equals(Object arg0) {
			Pair arg = (Pair) arg0;
			return a == arg.a && b == arg.b;
		}

	}

	static final int MODULES = 2;

	int modulo [] = {1000000007, 1000000009};
	int prime [] = {41, 43};

	int n, k;
	int bads[];
	long hash[][];
	long p[][];

	boolean isGood (int l, int r) {
		int sum = bads[r];
		if (l > 0) sum -= bads[l - 1];
		return sum <= k;
	}

	int getHash (int j, int l, int r) {
		long h = hash[j][r];
		if (l > 0) h = (h - hash[j][l - 1] + modulo[j]) % modulo[j];
		h *= p[j][n - l - 1];
		h %= modulo[j];
		return (int) h;
	}

	Pair getHash (int l, int r) {
		return new Pair (getHash(0, l, r), getHash(1, l, r));
	}

	public void solve () throws Exception {
		char s [] = in.readLine().toCharArray();
		char bad [] = in.readLine().toCharArray();
		k = sc.nextInt();

		n = s.length;
		bads = new int [n];
		for (int i = 0; i < n; i++) {
			if (i > 0) bads[i] = bads[i - 1];
			if (bad[s[i] - 'a'] == '0') bads[i]++;
		}

		p = new long [2][n + 1];
		for (int j = 0; j < MODULES; j++) {
			p[j][0] = 1;
			for (int i = 1; i <= n; i++) {
				p[j][i] = p[j][i - 1] * prime[j];
				p[j][i] %= modulo[j];
			}
		}

		hash = new long [2][n + 1];
		for (int j = 0; j < MODULES; j++) {
			for (int i = 0; i < n; i++) {
				if (i > 0) hash[j][i] = hash[j][i - 1];
				hash[j][i] += p[j][i] * (s[i] - 'a' + 1);
				hash[j][i] %= modulo[j];
			}
		}

		int ans = 0;
		for (int len = 1; len < n; len++) {
			HashSet<Pair> set = new HashSet<>();
			for (int j = 0; j + len - 1 < n; j++) {
				if (isGood(j, j + len - 1)) {
					set.add(getHash(j, j + len - 1));
				}
			}
			ans += set.size();
		}

		out.println(ans);
	}

	BufferedReader in;
	PrintWriter out;
	FastScanner sc;

	static Throwable uncaught;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			sc = new FastScanner(in);
			solve();
		} catch (Throwable t) {
			Solution.uncaught = t;
		} finally {
			out.close();
		}
	}

	public static void main(String[] args) throws Throwable {
		Thread t = new Thread(null, new Solution(), "", (1 << 26));
		t.start();
		t.join();
		if (uncaught != null) {
			throw uncaught;
		}
	}

}

class FastScanner {

	BufferedReader reader;
	StringTokenizer strTok;

	public FastScanner(BufferedReader reader) {
		this.reader = reader;
	}

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

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

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

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

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class GoodSubstrings {
    public static void main(String[]args) throws IOException{

        boolean[]bad = new boolean[26];
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String s = r.readLine();
        String ss = r.readLine();
        int B = 1007;
        int max = Integer.parseInt(r.readLine());
        for(int i = 0 ; i<ss.length() ; i++)bad[i] = ss.charAt(i)=='1'?false:true;

        HashSet<Long>set = new HashSet<Long>();
        int[][]dp = new int[s.length()][s.length()];
        long[][]val = new long[s.length()][s.length()];
        for(int i = 0 ; i < s.length() ; i++){
            long h = 0;
            for(int j = i ; j < s.length() ; j++){
                h = (s.charAt(j)-'a'+1 + (h*B));
                val[i][j]= h;
            }
        }
        dp[0][0]= bad[s.charAt(0)-'a']? 1:0;
        for(int i = 1 ; i < s.length() ; i++){
            dp[0][i] = bad[s.charAt(i)-'a']? dp[0][i-1]+1 : dp[0][i-1];
        }

        for(int i  = 1; i < s.length() ; i++){
            for(int j = i ; j<s.length() ; j++){
                dp[i][j]= bad[s.charAt(i-1)-'a']? dp[i-1][j]-1:dp[i-1][j];
            }
        }

        for(int i = 0 ; i < s.length() ; i++){
            for(int j = i ; j < s.length() ;j++){

                if(dp[i][j]<=max){

                    set.add(val[i][j]);
    //          System.out.println(i+" "+j+" "+dp[i][j]+" "+s.substring(i,j+1)+" "+set.size()+" "+val[i][j]);
                }
            }
        }
        System.out.println(set.size());

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;

public class GoodSubstrings {
    public static void main(String[]args) throws IOException{

        boolean[]bad = new boolean[26];
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String s = r.readLine();
        String ss = r.readLine();
        int B = 1007;
        long M = 1000000000000037L;
        int max = Integer.parseInt(r.readLine());
        for(int i = 0 ; i<ss.length() ; i++)bad[i] = ss.charAt(i)=='1'?false:true;

        HashSet<Long>set = new HashSet<Long>();
        int[][]dp = new int[s.length()][s.length()];
        long[][]val = new long[s.length()][s.length()];
        for(int i = 0 ; i < s.length() ; i++){
            long h = 0;
            for(int j = i ; j < s.length() ; j++){
                h = (s.charAt(j)-'a'+1 + (h*B)%M)%M;
                val[i][j]= h;
            }
        }
        dp[0][0]= bad[s.charAt(0)-'a']? 1:0;
        for(int i = 1 ; i < s.length() ; i++){
            dp[0][i] = bad[s.charAt(i)-'a']? dp[0][i-1]+1 : dp[0][i-1];
        }

        for(int i  = 1; i < s.length() ; i++){
            for(int j = i ; j<s.length() ; j++){
                dp[i][j]= bad[s.charAt(i-1)-'a']? dp[i-1][j]-1:dp[i-1][j];
            }
        }

        for(int i = 0 ; i < s.length() ; i++){
            for(int j = i ; j < s.length() ;j++){

                if(dp[i][j]<=max){

                    set.add(val[i][j]);
    //          System.out.println(i+" "+j+" "+dp[i][j]+" "+s.substring(i,j+1)+" "+set.size()+" "+val[i][j]);
                }
            }
        }
        System.out.println(set.size());

    }
}


import java.util.*;
public class Main {
public static void main(String [] args){
	Scanner in=new Scanner(System.in);
	String str=in.next();
	String a=in.next();
	boolean decide[]=new boolean[26];
	for(int i=0;i<26;i++)
		if(a.charAt(i)=='1')
		decide[i]=true;

	int k=in.nextInt();
	HashSet<String>hs=new HashSet<String>();
	long ans=0;
	for(int i=0;i<str.length();i++){
		int bad=0;
		StringBuilder sb=new StringBuilder();
		for(int j=i;j<str.length();j++){
			if(!decide[str.charAt(j)-'a'])
			bad++;
			sb.append(str.charAt(j));
			if(bad <= k && !hs.contains(sb.toString())){
				ans++;
				//System.out.println(sb);
				hs.add(sb.toString());
			}
			if(bad > k)
				break;
		}
	}
	System.out.print(ans);
}
}


import java.util.*;
public class Main {
static class Node{
	boolean good;
	Node [] node = new Node[26];
	public  Node(boolean flag){
	good = flag;
	}
	public Node doEverything(char z){
		if(node[z - 'a'] == null)
			node[z - 'a'] = new Node(false);
			return node[z - 'a'];
	}
}
public static void main(String [] args){
	Scanner in=new Scanner(System.in);
	String str=in.next();
	String good=in.next();
	int array[]=new int[26];
	for(int i=0;i<good.length();i++)
	array[i]= 1-(good.charAt(i)-'0');
	int k=in.nextInt();
    int ans=0;

    Node start = new Node(false);
    for(int i=0;i<str.length();i++){
    	int bad=0;
    	Node curr=start;
          for(int j=i;j<str.length();j++){
          	bad+=array[str.charAt(j)-'a'];
          	curr = curr.doEverything(str.charAt(j));
          	if(!curr.good && bad <= k){
          	ans++;
          	curr.good = true;
          	}
          }
    }
    System.out.print(ans);
}
}


import java.util.*;
public class Main {
static class Node{
	boolean good;
	Node [] node = new Node[26];
	public  Node(boolean flag){
	good = flag;
	}
	public Node doEverything(char z){
		if(node[z - 'a'] == null)
			node[z - 'a'] = new Node(false);
			return node[z - 'a'];
	}
}
public static void main(String [] args){
	Scanner in=new Scanner(System.in);
	String str=in.next();
	String good=in.next();
	int array[]=new int[26];
	for(int i=0;i<good.length();i++)
	array[i]= 1-(good.charAt(i)-'0');
	int k=in.nextInt();
    int ans=0;

    Node start = new Node(false);
    for(int i=0;i<str.length();i++){
    	int bad=0;
    	Node curr=start;
          for(int j=i;j<str.length();j++){
          	bad+=array[str.charAt(j)-'a'];
          	curr = curr.doEverything(str.charAt(j));
          	if(!curr.good && bad > k){
          	curr.good = true;
          	}
          	if(!curr.good && bad <= k){
          	curr.good = true;
          	ans++;
          	}
          }
    }
    System.out.print(ans);
}
}


import java.util.*;
import java.io.*;
public class cadenasmaricas{
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tmp = lector.readLine();
boolean ta[] = new boolean[26];
String t = lector.readLine();
for(int n= 0;n<t.length();n++)
ta[n]=(t.charAt(n)=='1');
int c = Integer.parseInt(lector.readLine());
int freq[] = new int[tmp.length()];
long hash[] = new long[freq.length];
long num = 1000000003;
long pot[]=new long[freq.length];
pot[0]=1L;
for(int n =1;n<pot.length;n++)
pot[n]=(pot[n-1]*29L)%num;
freq[0]=ta[(int)(tmp.charAt(0)-'a')]?0:1;
hash[0]=(long)(tmp.charAt(0)-'a'+1);
HashSet<Long> aver = new HashSet<Long>();
if(freq[0]<=c)
aver.add(hash[0]);//aver.add(""+tmp.charAt(0));
for(int n = 1;n<freq.length;n++){
hash[n]=(29L*hash[n-1]+(long)(tmp.charAt(n)-'a'+1))%num;
freq[n]=(ta[(int)(tmp.charAt(n)-'a')]?0:1)+freq[n-1];
for(int m = 0;m<=n;m++)
if(freq[n]-(m==0?0:freq[m-1])<=c){
long tt = (hash[n]-(m==0?0:hash[m-1]*pot[n-m+1]))%num;
while(tt<0)tt+=num;
aver.add(tt);//aver.add(tmp.substring(m,n+1));
}
}
System.out.println(aver.size());
}
}


import java.util.*;
import java.io.*;
public class cadenasmaricas{
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tmp = lector.readLine();
boolean ta[] = new boolean[26];
String t = lector.readLine();
for(int n= 0;n<t.length();n++)
ta[n]=(t.charAt(n)=='1');
int c = Integer.parseInt(lector.readLine());
int freq[] = new int[tmp.length()];
freq[0]=ta[(int)(tmp.charAt(0)-'a')]?0:1;
HashSet<String> aver = new HashSet<String>();
if(freq[0]<=c)aver.add(""+tmp.charAt(0));
for(int n = 1;n<freq.length;n++){
freq[n]=(ta[(int)(tmp.charAt(n)-'a')]?0:1)+freq[n-1];
for(int m = 0;m<=n;m++)if(freq[n]-(m==0?0:freq[m-1])<=c)aver.add(tmp.substring(m,n+1));
}
System.out.println(aver.size());
}
}


import java.util.*;
import java.io.*;
public class cadenasmaricas{
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tmp = lector.readLine();
boolean ta[] = new boolean[26];
String t = lector.readLine();
for(int n= 0;n<t.length();n++)
ta[n]=(t.charAt(n)=='1');
int c = Integer.parseInt(lector.readLine());
int freq[] = new int[tmp.length()];
long hash[] = new long[freq.length];
//long num = 9000000007;
long pot[]=new long[freq.length];
pot[0]=1L;
for(int n =1;n<pot.length;n++)
pot[n]=pot[n-1]*29L;
freq[0]=ta[(int)(tmp.charAt(0)-'a')]?0:1;
hash[0]=(long)(tmp.charAt(0)-'a'+1);
HashSet<Long> aver = new HashSet<Long>();
if(freq[0]<=c)
aver.add(hash[0]);//aver.add(""+tmp.charAt(0));
for(int n = 1;n<freq.length;n++){
hash[n]=(29L*hash[n-1]+(long)(tmp.charAt(n)-'a'+1));
freq[n]=(ta[(int)(tmp.charAt(n)-'a')]?0:1)+freq[n-1];
for(int m = 0;m<=n;m++)
if(freq[n]-(m==0?0:freq[m-1])<=c){
long tt = (hash[n]-(m==0?0:hash[m-1]*pot[n-m+1]));
//while(tt<0)tt+=num;
aver.add(tt);//aver.add(tmp.substring(m,n+1));
}
}
System.out.println(aver.size());
}
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.io.BufferedWriter;
import java.util.Locale;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.math.BigInteger;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Jacob Jiang
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char[] s = in.nextCharArray();
        boolean[] isBad = new boolean[26];
        for (int i = 0; i < 26; i++) {
            isBad[i] = in.nextChar() == '0';
        }
        int maxAcceptBad = in.nextInt();
        long prime = BigInteger.probablePrime(56, new Random()).longValue();
        Set<Long> answer = new HashSet<Long>();
        for (int i = 0; i < s.length; i++) {
            long hash = 0;
            int badCount = 0;
            for (int j = i; j < s.length; j++) {
                hash = (hash * 31 + (s[j] - 'a' + 1)) % prime;
                if (isBad[s[j] - 'a']) badCount++;
                if (badCount > maxAcceptBad) break;
                answer.add(hash);
            }
        }
        out.println(answer.size());
    }
}

class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

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

    public 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 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 & 15;
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String next() {
        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 static boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public char nextChar() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        return (char) c;
    }

    public char[] nextCharArray() {
        return next().toCharArray();
    }

    }

class OutputWriter {
    private PrintWriter writer;

    public OutputWriter(OutputStream stream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void println(int i) {
        writer.println(i);
    }

    public void close() {
        writer.close();
    }

    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author vadimmm
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

    private String string;
    private boolean[] letters;
    private int counter;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        string = in.next();
        String s = in.next();
        letters = new boolean[26];
        for (int i = 0; i < 26; ++i)
            letters[i] = (s.charAt(i) == '1');
        counter = in.nextInt();
        SuffixTree bor = new SuffixTree(string, letters, counter);
        out.println(bor.getAnswer());
    }

}

class SuffixTree {

    private String string;
    private int length, counter;
    private ArrayList<Edge> start;
    private boolean[] letters;

    public SuffixTree(String string, boolean[] letters, int counter) {
        this.string = string;
        this.letters = letters;
        this.counter = counter;
        length = string.length();
        start = new ArrayList<Edge>();
        this.build();
    }

    private void build() {
        Edge current, temp = null;
        boolean contains;
        for (int i = 0; i < length; ++i) {
            contains = false;
            current = null;
            for (Edge e : start)
                if (e.letter == string.charAt(i)) {
                    current = e;
                    contains = true;
                    break;
                }
            if (!contains) {
                current = new Edge(string.charAt(i), new ArrayList<Edge>());
                start.add(current);
                for (int k = i + 1; k < length; ++k) {
                    temp = new Edge(string.charAt(k), new ArrayList<Edge>());
                    current.next.add(temp);
                    current = temp;
                }
            } else {
                for (int j = i + 1; j < length; ++j) {
                    if (contains) {
                        contains = false;
                        for (Edge e : current.next) {
                            if (e.letter == string.charAt(j)) {
                                contains = true;
                                current = e;
                                break;
                            }
                        }
                    }
                    if (!contains) {
                        temp = new Edge(string.charAt(j), new ArrayList<Edge>());
                        current.next.add(temp);
                        current = temp;
                    }
                }
            }
        }
    }

    public int getAnswer() {
        int result = 0;
        for (Edge edge : start) {
            bad = 0;
            count = 0;
            dfs(edge);
            result += count;
        }
        return result;
    }

    private int count, bad;
    private void dfs(Edge edge) {
        if (!letters[edge.letter - 'a'])
            ++bad;
        if (bad > counter) {
            --bad;
            return;
        }
        ++count;
        for (Edge e : edge.next)
            dfs(e);
        if (!letters[edge.letter - 'a'])
            --bad;
    }

    static class Edge {

        public ArrayList<Edge> next;
        public char letter;

        public Edge(char letter, ArrayList<Edge> next) {
            this.letter = letter;
            this.next = next;
        }
    }

}

class InputReader {

    private static BufferedReader bufferedReader;
    private static StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        stringTokenizer = null;
    }

    public String next() {
        while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringTokenizer.nextToken();
    }

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

    }


import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author vadimmm
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskD {

    private String string;
    private boolean[] letters;
    private int counter;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        string = in.next();
        String s = in.next();
        letters = new boolean[26];
        for (int i = 0; i < 26; ++i)
            letters[i] = (s.charAt(i) == '1');
        counter = in.nextInt();
        SuffixTree bor = new SuffixTree(string, letters, counter);
        out.println(bor.getAnswer());
    }

}

class SuffixTree {

    private String string;
    private int length, counter;
    private ArrayList<Edge> start;
    private boolean[] letters;

    public SuffixTree(String string, boolean[] letters, int counter) {
        this.string = string;
        this.letters = letters;
        this.counter = counter;
        length = string.length();
        start = new ArrayList<Edge>();
        this.build();
    }

    private void build() {
        for (int i = 0; i < length; ++i) {
            for (int j = i; j < length; ++j) {
                boolean contains = false;
                for (Edge e : start)
                    if (e.letter == string.charAt(j)) {
                        Edge current = e;
                        int depth = j + 1;
                        while (depth < length) {
                            contains = false;
                            for (int k = 0; k < current.next.size(); ++k) {
                                if (current.next.get(k).letter == string.charAt(depth)) {
                                    contains = true;
                                    current = current.next.get(k);
                                    ++depth;
                                }
                                if (contains)
                                    break;
                            }
                            if (!contains) {
                                for (int index = depth; index < length; ++index) {
                                    current.next.add(new Edge(string.charAt(index), new ArrayList<Edge>()));
                                    current = current.next.get(current.next.size() - 1);
                                }
                                break;
                            }
                        }
                        contains = true;
                        break;
                    }
                if (!contains) {
                    start.add(new Edge(string.charAt(j), new ArrayList<Edge>()));
                    Edge current = start.get(start.size() - 1);
                    for (int k = j + 1; k < length; ++k) {
                        current.next.add(new Edge(string.charAt(k), new ArrayList<Edge>()));
                        current = current.next.get(current.next.size() - 1);
                    }
                    break;
                }
            }
        }
    }

    public int getAnswer() {
        int result = 0;
        for (Edge edge : start) {
            bad = 0;
            count = 0;
            dfs(edge);
            result += count;
        }
        return result;
    }

    private int count, bad;
    private void dfs(Edge edge) {
        if (!letters[edge.letter - 'a'])
            ++bad;
        if (bad > counter) {
            --bad;
            return;
        }
        ++count;
        for (Edge e : edge.next)
            dfs(e);
        if (!letters[edge.letter - 'a'])
            --bad;
    }

    static class Edge {

        public ArrayList<Edge> next;
        public char letter;

        public Edge(char letter, ArrayList<Edge> next) {
            this.letter = letter;
            this.next = next;
        }
    }

}

class InputReader {

    private static BufferedReader bufferedReader;
    private static StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        stringTokenizer = null;
    }

    public String next() {
        while(stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            try {
                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringTokenizer.nextToken();
    }

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

    }


import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class solution {

	void solve() throws IOException {
		char[] s = readString().toCharArray();
		String bb = readString();
		int k = readInt();
		boolean[] bad = new boolean[26];
		for(int i = 0; i < 26; i++) {
			bad[i] = (bb.charAt(i) == '0');
		}
		HashSet<Long>[] set = new HashSet[s.length];
		for(int i = 0; i < set.length; i++) {
			set[i] = new HashSet();
		}
		for(int i = 0; i < s.length; i++) {
			long hash = 0;
			int badCnt = 0;
			for(int j = i; j < s.length; j++) {
				if(bad[s[j]-'a']) {
					badCnt++;
				}
				if(badCnt > k) {
					break;
				}
				hash = (hash*131)^s[j];
				set[j-i].add(hash);
			}
		}
		long ans = 0;
		for(HashSet<Long> hs : set) {
			ans += hs.size();
		}
		out.print(ans);
	}

	//-------------------------------------------------

	final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok;

	public void run() {
		try {
			long startTime = System.currentTimeMillis();
			Locale.setDefault(Locale.US);
			if (ONLINE_JUDGE) {
				in = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				in = new BufferedReader(new FileReader("input.txt"));
				out = new PrintWriter("output.txt");
			}
			tok = new StringTokenizer("");
			solve();
			in.close();
			out.close();
			long endTime = System.currentTimeMillis();
			long totalMemory = Runtime.getRuntime().totalMemory();
			long freeMemory = Runtime.getRuntime().freeMemory();
			System.err.println("Time = " + (endTime - startTime) + " ms");
			System.err.println("Memory = " + ((totalMemory - freeMemory) / 1024) + " KB");
		} catch (Throwable e) {
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) return null;
			tok = new StringTokenizer(line);
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	void debug(Object... o) {
		if (!ONLINE_JUDGE) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static void main(String[] args) {
		new solution().run();
	}

//------------------------------------------------------------------------------
	static class Mergesort {

		private Mergesort() {}

		public static void sort(int[] a) {
			mergesort(a, 0, a.length - 1);
		}

		public static void sort(long[] a) {
			mergesort(a, 0, a.length - 1);
		}

		public static void sort(double[] a) {
			mergesort(a, 0, a.length - 1);
		}

		private static final int MAGIC_VALUE = 42;

		private static void mergesort(int[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void mergesort(long[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void mergesort(double[] a, int leftIndex, int rightIndex) {
			if (leftIndex < rightIndex) {
				if (rightIndex - leftIndex <= MAGIC_VALUE) {
					insertionSort(a, leftIndex, rightIndex);
				} else {
					int middleIndex = (leftIndex + rightIndex) / 2;
					mergesort(a, leftIndex, middleIndex);
					mergesort(a, middleIndex + 1, rightIndex);
					merge(a, leftIndex, middleIndex, rightIndex);
				}
			}
		}

		private static void merge(int[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			int[] leftArray = new int[length1];
			int[] rightArray = new int[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void merge(long[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			long[] leftArray = new long[length1];
			long[] rightArray = new long[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void merge(double[] a, int leftIndex, int middleIndex, int rightIndex) {
			int length1 = middleIndex - leftIndex + 1;
			int length2 = rightIndex - middleIndex;
			double[] leftArray = new double[length1];
			double[] rightArray = new double[length2];
			System.arraycopy(a, leftIndex, leftArray, 0, length1);
			System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
			for (int k = leftIndex, i = 0, j = 0; k <= rightIndex; k++) {
				if (i == length1) {
					a[k] = rightArray[j++];
				} else if (j == length2) {
					a[k] = leftArray[i++];
				} else {
					a[k] = leftArray[i] <= rightArray[j] ? leftArray[i++] : rightArray[j++];
				}
			}
		}

		private static void insertionSort(int[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				int current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

		private static void insertionSort(long[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				long current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

		private static void insertionSort(double[] a, int leftIndex, int rightIndex) {
			for (int i = leftIndex + 1; i <= rightIndex; i++) {
				double current = a[i];
				int j = i - 1;
				while (j >= leftIndex && a[j] > current) {
					a[j + 1] = a[j];
					j--;
				}
				a[j + 1] = current;
			}
		}

	}

}