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*31)^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;
			}
		}

	}

}


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*31+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;
			}
		}

	}

}


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

import static java.lang.Math.*;

public class solution {

	final long mod1 = (long)1e9+7, mod2 = (long)1e9+9;

	class Hash {
		long h1, h2;

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + (int) (h1 ^ (h1 >>> 32));
			result = prime * result + (int) (h2 ^ (h2 >>> 32));
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Hash other = (Hash) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (h1 != other.h1)
				return false;
			if (h2 != other.h2)
				return false;
			return true;
		}

		private solution getOuterType() {
			return solution.this;
		}

		Hash add(char ch) {
			long rh1 = (h1*31+ch)%mod1;
			long rh2 = h2*37+ch;
			Hash r = new Hash();
			r.h1 = rh1;
			r.h2 = rh2;
			return r;
		}

		@Override
		public String toString() {
			return "(" + h1 + "," + h2 + ")";
		}
	}

	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<Hash>[] 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++) {
			Hash hash = new Hash();
			int badCnt = 0;
			for(int j = i; j < s.length; j++) {
				if(bad[s[j]-'a']) {
					badCnt++;
				}
				if(badCnt > k) {
					break;
				}
				hash = hash.add(s[j]);
				set[j-i].add(hash);
			}
		}
		long ans = 0;
		for(HashSet<Hash> 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;
			}
		}

	}

}


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*31+s[j])%(long)(1e9);
				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;
			}
		}

	}

}


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

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false,'@');
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			Node n = node.getWithChar(c);
			if (null == n) {
				Node next =new Node(mem[left][right] <= k, c);
				node.addHijo(next);
				node = next;
			}else{
				node = n;
			}
			node.b = mem[left][right] <= k;
			right++;
			if (right < s.length())
				add(node, s, left, right);

		}

		public long total() {
			return total(root);
		}

		private long total(Node node) {
			long ret = 0;
			if (node.b)
				ret++;
			for (Node n : node.hijos)
				ret += total(n);
			return ret;
		}

		private class Node {
			public boolean b;
			public Set<Node> hijos;
			public char c;

			public Node(boolean b, char c) {
				this.b = b;
				this.c = c;
				this.hijos = new TreeSet<Node>();
			}

			public Node getWithChar(char c) {
				Node ret = null;
				for (Node n : hijos)
					if (n.c == c) {
						ret = n;
						break;
					}
				return ret;
			}

			public void addHijo(Node node) {
				hijos.add(node);

			}
		}
	}
}


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

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false);
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			if(node.hijos[c-'a']==null){
				node.hijos[c-'a']= new Node(mem[left][right]<=k);
			}
			node = node.hijos[c-'a'];
			node.b=mem[left][right]<=k;
			right++;
			if(right<s.length())
				add(node,s,left,right);

		}
		public long total() {
			return total(root);
		}

		private long total(Node node) {
			long ret = 0;
			if (node.b)
				ret++;
			for (int i = 0; i < 26; i++)
				if (node.hijos[i] != null)
					ret += total(node.hijos[i]);
			return ret;
		}

		private class Node {
			public boolean b;
			public Node[] hijos;

			public Node(boolean b) {
				this.b = b;
				this.hijos = new Node[26];
			}

		}
	}

}


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

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm =in.readLine();
		int k =Integer.parseInt(in.readLine());
		int[][] mem = new int[n][n];
		for(int i =0;i<n;i++){
			int parcial =0;
			for(int j =i;j<n;j++){
				if(perm.charAt(s.charAt(j)-'a')=='0'){
					parcial++;
				}
				mem[i][j]=parcial;
			}
		}
		long ret =0;
		for(int l=1;l<=n;l++){
			Set<String> set = new TreeSet<String>();
			for(int i =0;i+l<=n;i++)
				if(mem[i][i+l-1]<=k)
					set.add(s.substring(i,i+l));
			ret+=set.size();
		}
		out.println(ret);
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm =in.readLine();
		int k =Integer.parseInt(in.readLine());
		int[][] mem = new int[n][n];
		for(int i =0;i<n;i++){
			int parcial =0;
			for(int j =i;j<n;j++){
				if(perm.charAt(s.charAt(j)-'a')=='0'){
					parcial++;
				}
				mem[i][j]=parcial;
			}
		}
		Set<String> set = new HashSet<String>();
		for(int i =0;i<n;i++){
			for(int j =i;j<n;j++){
				if(mem[i][j]<=k)
					set.add(s.substring(i,j+1));
			}
		}
		out.println(set.size());
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false,'@');
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			Node n = node.getWithChar(c);
			if (null == n) {
				Node next =new Node(mem[left][right] <= k, c);
				node.addHijo(c,next);
				node = next;
			}else{
				node = n;
			}
			node.b = mem[left][right] <= k;
			right++;
			if (right < s.length())
				add(node, s, left, right);

		}

		public long total() {
			return total(root);
		}

		private long total(Node node){
			long ret = 0;
			if (node.b)
				ret++;
			for (Node n : node.hijos.values())
				ret += total(n);
			return ret;
		}

		private class Node  implements Comparable<Node>{
			public boolean b;
			public Map<Character,Node> hijos;
			public char c;

			public Node(boolean b, char c) {
				this.b = b;
				this.c = c;
				this.hijos = new HashMap<Character,Node>();
			}

			public Node getWithChar(char c) {
				Node ret = hijos.get(c);
				return ret;
			}

			public void addHijo(char c,Node node) {
				hijos.put(c,node);

			}

			@Override
			public int compareTo(Node o) {
				return c-o.c;
			}
		}
	}
}


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

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm =in.readLine();
		int k =Integer.parseInt(in.readLine());
		int[][] mem = new int[n][n];
		for(int i =0;i<n;i++){
			int parcial =0;
			for(int j =i;j<n;j++){
				if(perm.charAt(s.charAt(j)-'a')=='0'){
					parcial++;
				}
				mem[i][j]=parcial;
			}
		}
		Set<String> set = new TreeSet<String>();
		for(int i =0;i<n;i++){
			for(int j =i;j<n;j++){
				if(mem[i][j]<=k)
					set.add(s.substring(i,j+1));
			}
		}
		out.println(set.size());
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false,'@');
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			Node n = node.getWithChar(c);
			if (null == n) {
				Node next =new Node(mem[left][right] <= k, c);
				node.addHijo(next);
				node = next;
			}else{
				node = n;
			}
			node.b = mem[left][right] <= k;
			right++;
			if (right < s.length())
				add(node, s, left, right);

		}

		public long total() {
			return total(root);
		}

		private long total(Node node) {
			long ret = 0;
			if (node.b)
				ret++;
			for (Node n : node.hijos)
				ret += total(n);
			return ret;
		}

		private class Node {
			public boolean b;
			public List<Node> hijos;
			public char c;

			public Node(boolean b, char c) {
				this.b = b;
				this.c = c;
				this.hijos = new LinkedList<Node>();
				;
			}

			public Node getWithChar(char c) {
				Node ret = null;
				for (Node n : hijos)
					if (n.c == c) {
						ret = n;
						break;
					}
				return ret;
			}

			public void addHijo(Node node) {
				hijos.add(node);

			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false,'@');
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			Node n = node.getWithChar(c);
			if (null == n) {
				Node next =new Node(mem[left][right] <= k, c);
				node.addHijo(c,next);
				node = next;
			}else{
				node = n;
			}
			node.b = mem[left][right] <= k;
			right++;
			if (right < s.length())
				add(node, s, left, right);

		}

		public long total() {
			return total(root);
		}

		private long total(Node node){
			long ret = 0;
			if (node.b)
				ret++;
			for (Node n : node.hijos.values())
				ret += total(n);
			return ret;
		}

		private class Node  implements Comparable<Node>{
			public boolean b;
			public Map<Character,Node> hijos;
			public char c;

			public Node(boolean b, char c) {
				this.b = b;
				this.c = c;
				this.hijos = new HashMap<Character,Node>();
			}

			public Node getWithChar(char c) {
				Node ret = hijos.get(c);
				return ret;
			}

			public void addHijo(char c,Node node) {
				hijos.put(c,node);

			}

			@Override
			public int compareTo(Node o) {
				return c-o.c;
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static int[][] mem;
	private static int k;

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm = in.readLine();
		k = Integer.parseInt(in.readLine());
		mem = new int[n][n];
		for (int i = 0; i < n; i++) {
			int parcial = 0;
			for (int j = i; j < n; j++) {
				if (perm.charAt(s.charAt(j) - 'a') == '0') {
					parcial++;
				}
				mem[i][j] = parcial;
			}
		}
		Trie t = new Trie();
		for (int l = 0; l < n; l++)
			t.add(s, l);
		out.println(t.total());
	}

	public static class Trie {
		// a-z
		private Node root;

		public Trie() {
			this.root = new Node(false,'@');
		}

		public void add(String s, int l) {
			add(root, s, l, l);
		}

		private void add(Node node, String s, int left, int right) {
			char c = s.charAt(right);
			Node n = node.getWithChar(c);
			if (null == n) {
				Node next =new Node(mem[left][right] <= k, c);
				node.addHijo(c,next);
				node = next;
			}else{
				node = n;
			}
			node.b = mem[left][right] <= k;
			right++;
			if (right < s.length())
				add(node, s, left, right);

		}

		public long total() {
			return total(root);
		}

		private long total(Node node){
			long ret = 0;
			if (node.b)
				ret++;
			for (Node n : node.hijos.values())
				ret += total(n);
			return ret;
		}

		private class Node  implements Comparable<Node>{
			public boolean b;
			public Map<Character,Node> hijos;
			public char c;

			public Node(boolean b, char c) {
				this.b = b;
				this.c = c;
				this.hijos = new TreeMap<Character,Node>();
			}

			public Node getWithChar(char c) {
				Node ret = hijos.get(c);
				return ret;
			}

			public void addHijo(char c,Node node) {
				hijos.put(c,node);

			}

			@Override
			public int compareTo(Node o) {
				return c-o.c;
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class D {
	public static BufferedReader in;
	public static PrintWriter out;

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		boolean showLineError = true;
		if (showLineError) {
			solve();
			out.close();
		} else {
			try {
				solve();
			} catch (Exception e) {
			} finally {
				out.close();
			}
		}

	}

	static void debug(Object... os) {
		out.println(Arrays.deepToString(os));
	}

	private static void solve() throws IOException {
		String s = in.readLine();
		int n = s.length();
		String perm =in.readLine();
		int k =Integer.parseInt(in.readLine());
		int[][] mem = new int[n][n];
		for(int i =0;i<n;i++){
			int parcial =0;
			for(int j =i;j<n;j++){
				if(perm.charAt(s.charAt(j)-'a')=='0'){
					parcial++;
				}
				mem[i][j]=parcial;
			}
		}
		long ret =0;
		for(int l=1;l<=n;l++){
			Set<String> set = new HashSet<String>();
			for(int i =0;i+l<=n;i++)
				if(mem[i][i+l-1]<=k)
					set.add(s.substring(i,i+l));
			ret+=set.size();
		}
		out.println(ret);
	}

}


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

public class CFJava {
    public static void main(String[] args) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i = 0; i < s.length(); i++)
            if (p.charAt(s.charAt(i) - 'a') == '1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        Bor strings = new Bor();
        for (int i = 0; i < s.length(); i++) {
            int ans = 0;
            int j = i;
            while (ans <= k && j < s.length()) {
                ans += isBad[j];
                if (ans<=k)
                    j++;
            }
            if (j > i) {
                //System.out.println(s.substring(i, j));
                strings.add(s.substring(i, j), 0);
            }
        }
        System.out.print(strings.count());

    }
}

class Bor {
    private Bor[] sons = new Bor[26];

    public void add(String substring, int i) {
        if (i < substring.length()) {
            if (sons[((int) substring.charAt(i)) - ((int) 'a')] == null) {
                sons[((int) substring.charAt(i)) - ((int) 'a')] = new Bor();
            }
            sons[((int) substring.charAt(i)) - ((int) 'a')].add(substring, i + 1);

        }
    }

    public Integer count() {
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (sons[i] != null)
                ans += (1 + sons[i].count());
        }
        return ans;
    }

}


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

public class CFJava {
    private static int f(int x) {
        switch (x) {
            case 0:
                return 1;
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 1;
            case 4:
                return 2;
            case 5:
                return 2;
            default:
                return 0;
        }
    }

    public static void main(String[] args) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i = 0; i < s.length(); i++)
            if (p.charAt(s.charAt(i) - 'a') == '1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        Bor strings = new Bor();
        for (int i = 0; i < s.length(); i++) {
            int ans = isBad[i];
            int j = i;
            while (ans <= k && j < s.length()) {
                ans += isBad[j];
                j++;
            }
            if (j > i) {
                System.out.println(s.substring(i, j));
                strings.add(s.substring(i, j), 0);
            }
        }
        System.out.print(strings.count());

    }
}

class Bor {
    private Bor[] sons = new Bor[26];

    public void add(String substring, int i) {
        if (i < substring.length()) {
            if (sons[((int) substring.charAt(i)) - ((int) 'a')] == null) {
                sons[((int) substring.charAt(i)) - ((int) 'a')] = new Bor();
            }
            sons[((int) substring.charAt(i)) - ((int) 'a')].add(substring, i + 1);

        }
    }

    public Integer count() {
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (sons[i] != null)
                ans += (1 + sons[i].count());
        }
        return ans;
    }

}


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

public class CFJava {
    public static void main(String[] args) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i = 0; i < s.length(); i++)
            if (p.charAt(s.charAt(i) - 'a') == '1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        Bor strings = new Bor();
        for (int i = 0; i < s.length(); i++) {
            int ans = 0;
            int j = i;
            while (ans <= k && j < s.length()) {
                ans += isBad[j];
                if (ans<=k)
                    j++;
            }
            if (j > i) {
                //System.out.println(s.substring(i, j));
                strings.add(s.substring(i, j), 0);
            }
        }
        System.out.print(strings.count());

    }
}

class Bor {
    private Bor[] sons = new Bor[26];

    public void add(String substring, int i) {
        if (i < substring.length()) {
            if (sons[((int) substring.charAt(i)) - ((int) 'a')] == null) {
                sons[((int) substring.charAt(i)) - ((int) 'a')] = new Bor();
            }
            sons[((int) substring.charAt(i)) - ((int) 'a')].add(substring, i + 1);

        }
    }

    public Integer count() {
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (sons[i] != null)
                ans += (1 + sons[i].count());
        }
        return ans;
    }

}

/*class MyScanner{
    private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    private String[] buffer;
    private int pos = 0;

    public Integer nextInt() throws IOException {
        if(buffer == null){
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        if(buffer.length <= pos){
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        pos++;
        return Integer.parseInt(buffer[pos-1]);
    }

    public String nextString() throws IOException {
        if(buffer == null){
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        if(buffer.length <= pos){
            buffer = in.readLine().split(" ");
            pos = 0;
        }
        pos++;
        return buffer[pos-1];
    }

}*/


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

public class CFJava {
    private static int f(int x) {
        switch (x) {
            case 0:
                return 1;
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 1;
            case 4:
                return 2;
            case 5:
                return 2;
            default:
                return 0;
        }
    }

    public static void main(String[] args) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i = 0; i < s.length(); i++)
            if (p.charAt(s.charAt(i) - 'a') == '1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        Bor strings = new Bor();
        for (int i = 0; i < s.length(); i++) {
            int ans = isBad[i];
            int j = i;
            while (ans <= k && j < s.length()) {
                ans += isBad[j];
                j++;
            }
            if (j > i) {
                strings.add(s.substring(i, j), 0);
            }
        }
        System.out.print(strings.count());

    }
}

class Bor {
    private Bor[] sons = new Bor[26];

    public void add(String substring, int i) {
        if (i < substring.length()) {
            if (sons[((int) substring.charAt(i)) - ((int) 'a')] == null) {
                sons[((int) substring.charAt(i)) - ((int) 'a')] = new Bor();
            }
            sons[((int) substring.charAt(i)) - ((int) 'a')].add(substring, i + 1);

        }
    }

    public Integer count() {
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (sons[i] != null)
                ans += (1 + sons[i].count());
        }
        return ans;
    }

}


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

public class CFJava {
    private static int f(int x){
        switch (x){
            case 0: return 1;
            case 1: return 1;
            case 2: return 2;
            case 3:return 1;
            case 4:return 2;
            case 5:return 2;
            default: return 0;
        }
    }

    public static void main( String[] args ) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set  = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i=0;i<s.length();i++)
            if (p.charAt(s.charAt(i)-'a')=='1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        int[][] sum = new int[s.length()][s.length()];
        int ans= 0;
        for (int i=0;i<s.length();i++){
            sum[i][i] = isBad[i];
            if (isBad[i]<=k && !set.contains(s.substring(i,i+1))){
                set.add(s.substring(i,i+1));
                ans++;
            }
        }
        for (int i=0;i<s.length();i++)
            for (int j=i+1;j<s.length() ;j++){
                sum[i][j] = sum[i][j-1] + isBad[j];
                if (sum[i][j]<=k&& !set.contains(s.substring(i,j+1))){
                    ans++;
                    set.add(s.substring(i,j+1));
                }

        }
        System.out.print(ans);

    }
}


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

public class CFJava {
    public static void main(String[] args) throws IOException {
        Scanner ss = new Scanner(System.in);
        Set<String> set = new HashSet<String>();
        String s = ss.nextLine();
        String p = ss.nextLine();
        Integer k = ss.nextInt();
        int[] isBad = new int[s.length()];
        for (int i = 0; i < s.length(); i++)
            if (p.charAt(s.charAt(i) - 'a') == '1')
                isBad[i] = 0;
            else
                isBad[i] = 1;
        Bor strings = new Bor();
        for (int i = 0; i < s.length(); i++) {
            int ans = isBad[i];
            int j = i;
            while (ans <= k && j < s.length()) {
                ans += isBad[j];
                if (ans<=k)
                    j++;
            }
            if (j > i) {

                strings.add(s.substring(i, j), 0);
            }
        }
        System.out.print(strings.count());

    }
}

class Bor {
    private Bor[] sons = new Bor[26];

    public void add(String substring, int i) {
        if (i < substring.length()) {
            if (sons[((int) substring.charAt(i)) - ((int) 'a')] == null) {
                sons[((int) substring.charAt(i)) - ((int) 'a')] = new Bor();
            }
            sons[((int) substring.charAt(i)) - ((int) 'a')].add(substring, i + 1);

        }
    }

    public Integer count() {
        int ans = 0;
        for (int i = 0; i < 26; i++) {
            if (sons[i] != null)
                ans += (1 + sons[i].count());
        }
        return ans;
    }

}


import java.util.Scanner;
public class Code {

	public Code(){}

	public static class Globals{
		public static int [][] edge=new int [2000000][28];
		public static int [] t=new int [28];
		public static int ans;
		public static int k;
		public static int N;
		public static int n;
	}

	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String st=input.nextLine();
		String ch=input.nextLine();
		Globals.k=input.nextInt();
		Globals.n=st.length();
		Initialize(0);
		for (int i=0;i<26;i++) Globals.t[i]=Math.abs((ch.charAt(i)-'0')-1);
		for (int i=0;i<Globals.n;i++) AddWord(0,st.substring(i,Globals.n));
		for (int i=0;i<26;i++) dfs(Globals.edge[0][i],Globals.t[i]);
		System.out.println(Globals.ans);
	}

	public static void dfs(int v,int cnt){
		if (v==-1) return;
		if (cnt<=Globals.k) Globals.ans++;
		for (int i=0;i<26;i++) dfs(Globals.edge[v][i],cnt+Globals.t[i]);
	}

	public static void AddWord(int vertex,String w){
		if (w.length()==0) return;
		int K=w.charAt(0)-'a';
		if (Globals.edge[vertex][K]==-1) {Initialize(Globals.N+1);Globals.N++;Globals.edge[vertex][K]=Globals.N;}
		AddWord(Globals.edge[vertex][K],w.substring(1,w.length()));
	}

	public static void Initialize(int vertex){
		for (int i=0;i<26;i++) Globals.edge[vertex][i]=-1;
	}

}


import java.util.Scanner;
public class Code {

	public Code(){}

	public static class Globals{
		public static int [][] edge=new int [2000000][28];
		public static int [] t=new int [28];
		public static int ans;
		public static int k;
		public static int N=0;
		public static int n;
		public static String ST;
	}

	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String st=input.nextLine();
		String ch=input.nextLine();
		Globals.k=input.nextInt();
		Globals.n=st.length();
		//Initialize(0);
		for (int i=0;i<26;i++) Globals.t[i]=Math.abs((ch.charAt(i)-'0')-1);
		for (int i=0;i<Globals.n;i++) {Globals.ST=st.substring(i,Globals.n);AddWord(0,0);}
		for (int i=0;i<26;i++) dfs(Globals.edge[0][i],Globals.t[i]);
		System.out.println(Globals.ans);
	}

	public static void dfs(int v,int cnt){
		if (v==0) return;
		if (cnt<=Globals.k) Globals.ans++;
		for (int i=0;i<26;i++) dfs(Globals.edge[v][i],cnt+Globals.t[i]);
	}

	public static void AddWord(int vertex,int w){
		if (w==Globals.ST.length()) return;
		int K=Globals.ST.charAt(w)-'a';
		if (Globals.edge[vertex][K]==0) {/*Initialize(Globals.N+1);*/Globals.N++;Globals.edge[vertex][K]=Globals.N;}
		AddWord(Globals.edge[vertex][K],w+1);
	}

	/*public static void Initialize(int vertex){
		for (int i=0;i<26;i++) Globals.edge[vertex][i]=-1;
	}*/

}


import java.util.Scanner;
public class Code {

	public Code(){}

	public static class Globals{
		public static int [][] edge=new int [2000000][28];
		public static int [] t=new int [28];
		public static int ans;
		public static int k;
		public static int N=0;
		public static int n;
	}

	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		String st=input.nextLine();
		String ch=input.nextLine();
		Globals.k=input.nextInt();
		Globals.n=st.length();
		//Initialize(0);
		for (int i=0;i<26;i++) Globals.t[i]=Math.abs((ch.charAt(i)-'0')-1);
		for (int i=0;i<Globals.n;i++) AddWord(0,st.substring(i,Globals.n));
		for (int i=0;i<26;i++) dfs(Globals.edge[0][i],Globals.t[i]);
		System.out.println(Globals.ans);
	}

	public static void dfs(int v,int cnt){
		if (v==0) return;
		if (cnt<=Globals.k) Globals.ans++;
		for (int i=0;i<26;i++) dfs(Globals.edge[v][i],cnt+Globals.t[i]);
	}

	public static void AddWord(int vertex,String w){
		if (w.length()==0) return;
		int K=w.charAt(0)-'a';
		if (Globals.edge[vertex][K]==0) {/*Initialize(Globals.N+1);*/Globals.N++;Globals.edge[vertex][K]=Globals.N;}
		AddWord(Globals.edge[vertex][K],w.substring(1,w.length()));
	}

	/*public static void Initialize(int vertex){
		for (int i=0;i<26;i++) Globals.edge[vertex][i]=-1;
	}*/

}


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

public class GoodSubstrings {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char[] str = in.readLine().toCharArray();
        char[] good = in.readLine().toCharArray();
        int k = Integer.parseInt(in.readLine());
        int[][] dp = new int[str.length + 1][str.length + 1];
        for (int i = str.length - 1; i >= 0; i--)
            for (int j = str.length - 1; j >= 0; j--)
                dp[i][j] = (str[i] == str[j]) ? 1 + dp[i + 1][j + 1] : 0;
        int[] max = new int[str.length];
        for (int i = 0; i < str.length; i++)
            for (int j = 0; j < i; j++)
                max[i] = Math.max(max[i], dp[i][j]);
        int count = 0;
        for (int i = 0; i < str.length; i++) {
            int bad = 0;
            for (int j = 0; j < max[i]; j++)
                bad += good[str[i + j] - 'a'] == '0' ? 1 : 0;
            for (int j = max[i]; j + i < str.length && bad <= k; j++) {
                bad += good[str[i + j] - 'a'] == '0' ? 1 : 0;
                if (bad <= k)
                    count++;
            }
        }
        System.out.println(count);
    }
}


import java.io.IOException;
import java.io.InputStreamReader;
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 sheep
 */
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 {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        String s = in.next();
        String mask = in.next();
        int limit = in.nextInt();

        int intStr[] = new int[s.length()];
        for (int i = 0; i < s.length(); ++i) {
            intStr[i] = s.charAt(i);
        }

        int sa[] = SuffixArray.makeSA(intStr);
        int rank[] = SuffixArray.makeRank(sa);
        int height[] = SuffixArray.makeHeight(intStr, sa, rank);

        int radius[] = new int[s.length()];
        for (int i = 0; i < s.length(); ++i) {
            int badCount = 0;
            for (int j = i; badCount <= limit && j < s.length(); ++j) {
                if (mask.charAt(s.charAt(j) - 'a') == '0') {
                    ++badCount;
                }

                if (badCount <= limit) {
                    ++radius[i];
                }
            }
        }

        int ans = 0;
        for (int i = 0; i < s.length(); ++i) {
            int offer = radius[sa[i]];
            int cut = height[i];
            if (offer > cut) {
                ans += offer - cut;
            }
        }

        out.println(ans);
    }
}

class SuffixArray {

    static boolean cmp(int[] r, int a, int b, int l, int n) {
        int la = r[a], lb = r[b], ra, rb;
        ra = a + l < n ? r[a + l] : -1;
        rb = b + l < n ? r[b + l] : -1;
        return la == lb && ra == rb;
    }

    static int[] makeSA(int s[]) {
        int n = s.length;
        int alphaSize = 1;
        for (int i = 0; i < n; ++i) {
            alphaSize = Math.max(alphaSize, s[i] + 1);
        }

        int[] wa = new int[Math.max(n, alphaSize) + 10];
        int[] wb = new int[Math.max(n, alphaSize) + 10];
        int[] wc = new int[Math.max(n, alphaSize) + 10];
        int[] wd = new int[Math.max(n, alphaSize) + 10];
        int[] sa = new int[n];

        int[] x = wa, y = wb;
        for (int i = 0; i < n; ++i)
            ++wc[x[i] = s[i]];
        for (int i = 1; i < alphaSize; ++i)
            wc[i] += wc[i - 1];
        for (int i = n - 1; i >= 0; --i)
            sa[--wc[x[i]]] = i;
        for (int tot = 0, p = 1; tot + 1 < n; p <<= 1, alphaSize = tot + 1) {
            tot = 0;
            for (int i = n - p; i < n; ++i)
                y[tot++] = i;
            for (int i = 0; i < n; ++i) {
                if (sa[i] >= p) {
                    y[tot++] = sa[i] - p;
                }
            }
            for (int i = 0; i < n; ++i)
                wd[i] = x[y[i]];
            for (int i = 0; i < alphaSize; ++i)
                wc[i] = 0;
            for (int i = 0; i < n; ++i)
                ++wc[wd[i]];
            for (int i = 1; i < alphaSize; ++i)
                wc[i] += wc[i - 1];
            for (int i = n - 1; i >= 0; --i)
                sa[--wc[wd[i]]] = y[i];
            int[] t = x; x = y; y = t;
            x[sa[0]] = tot = 0;
            for (int i = 1; i < n; ++i)
                x[sa[i]] = cmp(y, sa[i - 1], sa[i], p, n) ? tot : ++tot;
        }

        return sa;
    }

    static int[] makeRank(int sa[]) {
        int rank[] = new int[sa.length];
        for (int i = 0; i < sa.length; ++i) {
            rank[sa[i]] = i;
        }

        return rank;
    }

    static int[] makeHeight(int s[], int sa[], int rank[]) {
        int n = s.length;
        int height[] = new int[n];
        for (int i = 0; i < n; ++i) {

            if (0 == rank[i]) {
                continue;
            }

            if (i > 0) {
                height[rank[i]] = Math.max(0, height[rank[i - 1]] - 1);
            }

            for (; i + height[rank[i]] < s.length && sa[rank[i] - 1] + height[rank[i]] < s.length && s[i + height[rank[i]]] == s[sa[rank[i] - 1] + height[rank[i]]]; ++ height[rank[i]]);
        }

        return height;
    }
}

class InputReader {
    BufferedReader reader;
    StringTokenizer tokenizer;

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

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

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

    }


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

public class GoodSubstrings {
    static int K;
    static char[] good;

    static class Node {
        Node next[] = new Node[26];
    }

    static class Trie {
        Node root = new Node();
        int res = 0;

        public void add(String s) {
            Node node = root;
            int k = 0;
            for (int i = 0; i < s.length() && k <= K; i++) {
                int j = s.charAt(i) - 'a';
                if (good[j] == '0')
                    k++;
                if (k <= K) {
                    if (node.next[j] == null) {
                        node.next[j] = new Node();
                        res++;
                    }
                    node = node.next[j];
                }
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s = bf.readLine();
        good = bf.readLine().toCharArray();
        K = Integer.parseInt(bf.readLine());
        Trie t = new Trie();
        for (int i = 0; i < s.length(); i++) {
            t.add(s.substring(i));
        }
        System.out.println(t.res);
    }

}


import static java.lang.Math.*;
import java.util.*;
import java.io.*;

public class D {

	public void solve() throws Exception {

		char[] s = nextLine().toCharArray();
		int n = s.length;
		String badTmp = nextLine();
		boolean bad[] = new boolean[26];
		for (int i=0; i<26; ++i) bad[i] = badTmp.charAt(i)=='0';
		int k = nextInt();

//		long t = System.currentTimeMillis();

		int[][] dp = new int[n][n];
		for (int i=0; i<n; ++i) if (bad[s[i]-'a']) dp[i][i] = 1;
		for (int i=2; i<=n; ++i) for (int j=i-1; j<n; ++j) {
			dp[j-i+1][j] = dp[j-i+1][j-1] + (bad[s[j]-'a'] ? 1:0);
		}

//		debug(System.currentTimeMillis() - t);

		int res = 0;
		for (int i=1; i<=n; ++i) {
			HashSet<String> set = new HashSet<String>();
			for (int j=0; j<n-i+1; ++j) if (dp[j][j+i-1]<=k) {
				String stmp = new String(s, j, i);
				if (!set.contains(stmp)) {
					set.add(stmp);
					res++;
				}
			}
		}

		println(res);

//		debug(System.currentTimeMillis() - t);

	}

	////////////////////////////////////////////////////////////////////////////

	boolean showDebug = true;
	static boolean useFiles = false;
	static String inFile = "input.txt";
	static String outFile = "output.txt";

	double EPS = 1e-7;
	int INF = Integer.MAX_VALUE;
	long INFL = Long.MAX_VALUE;
	double INFD = Double.MAX_VALUE;

	int absPos(int num) {
		return num<0 ? 0:num;
	}
	long absPos(long num) {
		return num<0 ? 0:num;
	}
	double absPos(double num) {
		return num<0 ? 0:num;
	}

	int min(int... nums) {
		int r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	int max(int... nums) {
		int r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}
	long minL(long... nums) {
		long r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	long maxL(long... nums) {
		long r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}
	double minD(double... nums) {
		double r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	double maxD(double... nums) {
		double r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}

	long sumArr(int[] arr) {
		long res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}
	long sumArr(long[] arr) {
		long res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}
	double sumArr(double[] arr) {
		double res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}

	long partsFitCnt(long partSize, long wholeSize) {
		return (partSize+wholeSize-1)/partSize;
	}

	boolean odd(long num) {
		return (num&1)==1;
	}

	boolean hasBit(int num, int pos) {
		return (num&(1<<pos))>0;
	}

	boolean isLetter(char c) {
		return (c>='a' && c<='z') || (c>='A' && c<='Z');
	}
	boolean isLowercase(char c) {
		return (c>='a' && c<='z');
	}
	boolean isUppercase(char c) {
		return (c>='A' && c<='Z');
	}
	boolean isDigit(char c) {
		return (c>='0' && c<='9');
	}

	boolean charIn(String chars, String s) {
		if (s==null) return false;
		if (chars==null || chars.equals("")) return true;
		for (int i=0; i<s.length(); ++i)
			for (int j=0; j<chars.length(); ++j)
				if (chars.charAt(j)==s.charAt(i)) return true;
		return false;
	}

	String stringn(String s, int n) {
		if (n<1 || s==null) return "";
		StringBuilder sb = new StringBuilder(s.length()*n);
		for (int i=0; i<n; ++i) sb.append(s);
		return sb.toString();
	}
	String str(Object o) {
		if (o==null) return "";
		return o.toString();
	}

	long timer = System.currentTimeMillis();
	void startTimer() {
		timer = System.currentTimeMillis();
	}
	void stopTimer() {
		System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
	}

	static class InputReader {
		private byte[] buf;
		private int bufPos = 0, bufLim = -1;
		private InputStream stream;
		public InputReader(InputStream stream, int size) {
			buf = new byte[size];
			this.stream = stream;
		}
		private void fillBuf() throws IOException {
			bufLim = stream.read(buf);
			bufPos = 0;
		}
		char read() throws IOException {
			if (bufPos>=bufLim) fillBuf();
			return (char)buf[bufPos++];
		}
		boolean hasInput() throws IOException {
			if (bufPos>=bufLim) fillBuf();
			return bufPos<bufLim;
		}
	}

	static InputReader inputReader;
	static BufferedWriter outputWriter;

	char nextChar() throws IOException {
		return inputReader.read();
	}
	char nextNonWhitespaceChar() throws IOException {
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		return c;
	}
	String nextWord() throws IOException {
		StringBuilder sb = new StringBuilder();
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		while (c>' ') {
			sb.append(c);
			c = inputReader.read();
		}
		return new String(sb);
	}
	String nextLine() throws IOException {
		StringBuilder sb = new StringBuilder();
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		while (c!='\n' && c!='\r') {
			sb.append(c);
			c = inputReader.read();
		}
		return new String(sb);
	}
	int nextInt() throws IOException {
		int r = 0;
		char c = nextNonWhitespaceChar();
		boolean neg = false;
		if (c=='-') neg=true;
		else r=c-48;
		c = nextChar();
		while (c>='0' && c<='9') {
			r*=10;
			r+=c-48;
			c=nextChar();
		}
		return neg ? -r:r;
	}
	long nextLong() throws IOException {
		long r = 0;
		char c = nextNonWhitespaceChar();
		boolean neg = false;
		if (c=='-') neg=true;
		else r = c-48;
		c = nextChar();
		while (c>='0' && c<='9') {
			r*=10L;
			r+=c-48L;
			c=nextChar();
		}
		return neg ? -r:r;
	}
	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextWord());
	}
	int[] nextArr(int size) throws NumberFormatException, IOException {
		int[] arr = new int[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextInt();
		return arr;
	}
	long[] nextArrL(int size) throws NumberFormatException, IOException {
		long[] arr = new long[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextLong();
		return arr;
	}
	double[] nextArrD(int size) throws NumberFormatException, IOException {
		double[] arr = new double[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextDouble();
		return arr;
	}
	String[] nextArrS(int size) throws NumberFormatException, IOException {
		String[] arr = new String[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextWord();
		return arr;
	}
	char[] nextArrCh(int size) throws IOException {
		char[] arr = new char[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextNonWhitespaceChar();
		return arr;
	}
	char[][] nextArrCh(int rows, int columns) throws IOException {
		char[][] arr = new char[rows][columns];
		for (int i=0; i<rows; ++i)
			for (int j=0; j<columns; ++j)
				arr[i][j] = nextNonWhitespaceChar();
		return arr;
	}
	char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {
		char[][] arr = new char[rows+2][columns+2];
		for (int i=1; i<=rows; ++i)
			for (int j=1; j<=columns; ++j)
				arr[i][j] = nextNonWhitespaceChar();
		for (int i=0; i<columns+2; ++i) {
			arr[0][i] = border;
			arr[rows+1][i] = border;
		}
		for (int i=0; i<rows+2; ++i) {
			arr[i][0] = border;
			arr[i][columns+1] = border;
		}
		return arr;
	}

	void printf(String format, Object... args) throws IOException {
		outputWriter.write(String.format(format, args));
	}
	void print(Object o) throws IOException {
		outputWriter.write(o.toString());
	}
	void println(Object o) throws IOException {
		outputWriter.write(o.toString());
		outputWriter.newLine();
	}
	void print(Object... o) throws IOException {
		for (int i=0; i<o.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(o[i].toString());
		}
	}
	void println(Object... o) throws IOException {
		print(o);
		outputWriter.newLine();
	}
	void printn(Object o, int n) throws IOException {
		String s = o.toString();
		for (int i=0; i<n; ++i) {
			outputWriter.write(s);
			if (i!=n-1) outputWriter.write(' ');
		}
	}
	void printnln(Object o, int n) throws IOException {
		printn(o, n);
		outputWriter.newLine();
	}
	void printArr(int[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Integer.toString(arr[i]));
		}
	}
	void printArr(long[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Long.toString(arr[i]));
		}
	}
	void printArr(double[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Double.toString(arr[i]));
		}
	}
	void printArr(String[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(arr[i]);
		}
	}
	void printlnArr(int[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(long[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(double[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(String[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void halt(Object... o) throws IOException {
		if (o.length!=0) println(o);
		outputWriter.flush(); outputWriter.close();
		System.exit(0);
	}

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

	public static void main(String[] args) throws Exception {
		Locale.setDefault(Locale.US);
		if (!useFiles) {
			inputReader = new InputReader(System.in, 1<<16);
			outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);
		} else {
			inputReader = new InputReader(new FileInputStream(new File(inFile)), 1<<16);
			outputWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outFile))), 1<<16);
		}
		new D().solve();
		outputWriter.flush(); outputWriter.close();
	}
}


import static java.lang.Math.*;
import java.util.*;
import java.io.*;

public class D {

	public void solve() throws Exception {

		char[] s = nextLine().toCharArray();
		int n = s.length;
		String badTmp = nextLine();
		boolean bad[] = new boolean[26];
		for (int i=0; i<26; ++i) bad[i] = badTmp.charAt(i)=='0';
		int k = nextInt();

//		long t = System.currentTimeMillis();

		int[][] dp = new int[n][n];
		for (int i=0; i<n; ++i) if (bad[s[i]-'a']) dp[i][i] = 1;
		for (int i=2; i<=n; ++i) for (int j=i-1; j<n; ++j) {
			dp[j-i+1][j] = dp[j-i+1][j-1] + (bad[s[j]-'a'] ? 1:0);
		}

//		debug(System.currentTimeMillis() - t);

		int res = 0;
		for (int i=1; i<=n; ++i) {
			TreeSet<String> set = new TreeSet<String>();
			for (int j=0; j<n-i+1; ++j) if (dp[j][j+i-1]<=k) {
				String stmp = new String(s, j, i);
				if (!set.contains(stmp)) {
					set.add(stmp);
					res++;
				}
			}
		}

		println(res);

//		debug(System.currentTimeMillis() - t);

	}

	////////////////////////////////////////////////////////////////////////////

	boolean showDebug = true;
	static boolean useFiles = false;
	static String inFile = "input.txt";
	static String outFile = "output.txt";

	double EPS = 1e-7;
	int INF = Integer.MAX_VALUE;
	long INFL = Long.MAX_VALUE;
	double INFD = Double.MAX_VALUE;

	int absPos(int num) {
		return num<0 ? 0:num;
	}
	long absPos(long num) {
		return num<0 ? 0:num;
	}
	double absPos(double num) {
		return num<0 ? 0:num;
	}

	int min(int... nums) {
		int r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	int max(int... nums) {
		int r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}
	long minL(long... nums) {
		long r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	long maxL(long... nums) {
		long r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}
	double minD(double... nums) {
		double r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]<r) r=nums[i];
		return r;
	}
	double maxD(double... nums) {
		double r = nums[0];
		for (int i=1; i<nums.length; ++i)
			if (nums[i]>r) r=nums[i];
		return r;
	}

	long sumArr(int[] arr) {
		long res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}
	long sumArr(long[] arr) {
		long res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}
	double sumArr(double[] arr) {
		double res = 0;
		for (int i=0; i<arr.length; ++i)
			res+=arr[i];
		return res;
	}

	long partsFitCnt(long partSize, long wholeSize) {
		return (partSize+wholeSize-1)/partSize;
	}

	boolean odd(long num) {
		return (num&1)==1;
	}

	boolean hasBit(int num, int pos) {
		return (num&(1<<pos))>0;
	}

	boolean isLetter(char c) {
		return (c>='a' && c<='z') || (c>='A' && c<='Z');
	}
	boolean isLowercase(char c) {
		return (c>='a' && c<='z');
	}
	boolean isUppercase(char c) {
		return (c>='A' && c<='Z');
	}
	boolean isDigit(char c) {
		return (c>='0' && c<='9');
	}

	boolean charIn(String chars, String s) {
		if (s==null) return false;
		if (chars==null || chars.equals("")) return true;
		for (int i=0; i<s.length(); ++i)
			for (int j=0; j<chars.length(); ++j)
				if (chars.charAt(j)==s.charAt(i)) return true;
		return false;
	}

	String stringn(String s, int n) {
		if (n<1 || s==null) return "";
		StringBuilder sb = new StringBuilder(s.length()*n);
		for (int i=0; i<n; ++i) sb.append(s);
		return sb.toString();
	}
	String str(Object o) {
		if (o==null) return "";
		return o.toString();
	}

	long timer = System.currentTimeMillis();
	void startTimer() {
		timer = System.currentTimeMillis();
	}
	void stopTimer() {
		System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0);
	}

	static class InputReader {
		private byte[] buf;
		private int bufPos = 0, bufLim = -1;
		private InputStream stream;
		public InputReader(InputStream stream, int size) {
			buf = new byte[size];
			this.stream = stream;
		}
		private void fillBuf() throws IOException {
			bufLim = stream.read(buf);
			bufPos = 0;
		}
		char read() throws IOException {
			if (bufPos>=bufLim) fillBuf();
			return (char)buf[bufPos++];
		}
		boolean hasInput() throws IOException {
			if (bufPos>=bufLim) fillBuf();
			return bufPos<bufLim;
		}
	}

	static InputReader inputReader;
	static BufferedWriter outputWriter;

	char nextChar() throws IOException {
		return inputReader.read();
	}
	char nextNonWhitespaceChar() throws IOException {
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		return c;
	}
	String nextWord() throws IOException {
		StringBuilder sb = new StringBuilder();
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		while (c>' ') {
			sb.append(c);
			c = inputReader.read();
		}
		return new String(sb);
	}
	String nextLine() throws IOException {
		StringBuilder sb = new StringBuilder();
		char c = inputReader.read();
		while (c<=' ') c=inputReader.read();
		while (c!='\n' && c!='\r') {
			sb.append(c);
			c = inputReader.read();
		}
		return new String(sb);
	}
	int nextInt() throws IOException {
		int r = 0;
		char c = nextNonWhitespaceChar();
		boolean neg = false;
		if (c=='-') neg=true;
		else r=c-48;
		c = nextChar();
		while (c>='0' && c<='9') {
			r*=10;
			r+=c-48;
			c=nextChar();
		}
		return neg ? -r:r;
	}
	long nextLong() throws IOException {
		long r = 0;
		char c = nextNonWhitespaceChar();
		boolean neg = false;
		if (c=='-') neg=true;
		else r = c-48;
		c = nextChar();
		while (c>='0' && c<='9') {
			r*=10L;
			r+=c-48L;
			c=nextChar();
		}
		return neg ? -r:r;
	}
	double nextDouble() throws NumberFormatException, IOException {
		return Double.parseDouble(nextWord());
	}
	int[] nextArr(int size) throws NumberFormatException, IOException {
		int[] arr = new int[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextInt();
		return arr;
	}
	long[] nextArrL(int size) throws NumberFormatException, IOException {
		long[] arr = new long[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextLong();
		return arr;
	}
	double[] nextArrD(int size) throws NumberFormatException, IOException {
		double[] arr = new double[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextDouble();
		return arr;
	}
	String[] nextArrS(int size) throws NumberFormatException, IOException {
		String[] arr = new String[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextWord();
		return arr;
	}
	char[] nextArrCh(int size) throws IOException {
		char[] arr = new char[size];
		for (int i=0; i<size; ++i)
			arr[i] = nextNonWhitespaceChar();
		return arr;
	}
	char[][] nextArrCh(int rows, int columns) throws IOException {
		char[][] arr = new char[rows][columns];
		for (int i=0; i<rows; ++i)
			for (int j=0; j<columns; ++j)
				arr[i][j] = nextNonWhitespaceChar();
		return arr;
	}
	char[][] nextArrChBorders(int rows, int columns, char border) throws IOException {
		char[][] arr = new char[rows+2][columns+2];
		for (int i=1; i<=rows; ++i)
			for (int j=1; j<=columns; ++j)
				arr[i][j] = nextNonWhitespaceChar();
		for (int i=0; i<columns+2; ++i) {
			arr[0][i] = border;
			arr[rows+1][i] = border;
		}
		for (int i=0; i<rows+2; ++i) {
			arr[i][0] = border;
			arr[i][columns+1] = border;
		}
		return arr;
	}

	void printf(String format, Object... args) throws IOException {
		outputWriter.write(String.format(format, args));
	}
	void print(Object o) throws IOException {
		outputWriter.write(o.toString());
	}
	void println(Object o) throws IOException {
		outputWriter.write(o.toString());
		outputWriter.newLine();
	}
	void print(Object... o) throws IOException {
		for (int i=0; i<o.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(o[i].toString());
		}
	}
	void println(Object... o) throws IOException {
		print(o);
		outputWriter.newLine();
	}
	void printn(Object o, int n) throws IOException {
		String s = o.toString();
		for (int i=0; i<n; ++i) {
			outputWriter.write(s);
			if (i!=n-1) outputWriter.write(' ');
		}
	}
	void printnln(Object o, int n) throws IOException {
		printn(o, n);
		outputWriter.newLine();
	}
	void printArr(int[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Integer.toString(arr[i]));
		}
	}
	void printArr(long[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Long.toString(arr[i]));
		}
	}
	void printArr(double[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(Double.toString(arr[i]));
		}
	}
	void printArr(String[] arr) throws IOException {
		for (int i=0; i<arr.length; ++i) {
			if (i!=0) outputWriter.write(' ');
			outputWriter.write(arr[i]);
		}
	}
	void printlnArr(int[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(long[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(double[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void printlnArr(String[] arr) throws IOException {
		printArr(arr);
		outputWriter.newLine();
	}
	void halt(Object... o) throws IOException {
		if (o.length!=0) println(o);
		outputWriter.flush(); outputWriter.close();
		System.exit(0);
	}

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

	public static void main(String[] args) throws Exception {
		Locale.setDefault(Locale.US);
		if (!useFiles) {
			inputReader = new InputReader(System.in, 1<<16);
			outputWriter = new BufferedWriter(new OutputStreamWriter(System.out), 1<<16);
		} else {
			inputReader = new InputReader(new FileInputStream(new File(inFile)), 1<<16);
			outputWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(outFile))), 1<<16);
		}
		new D().solve();
		outputWriter.flush(); outputWriter.close();
	}
}