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();

		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);
		}

		long res = 0;
		Trie trie = new Trie();
		for (int i=0; i<n; ++i) for (int j=i; j<n; ++j) if (dp[i][j]<=k) {
			if (trie.insert(s,i,j+1)) res++;
		}
		println(res);

	}

	class Trie {

		int elementCnt = 26;
		Trie[] sons;
		boolean term = false;

		public Trie() {
			sons = new Trie[elementCnt];
		}

		public boolean contains(String s) {
			return contains(s.toCharArray(), 0, s.length());
		}

		public boolean contains(String s, int from, int to) {
			return contains(s.toCharArray(), from, to);
		}

		public boolean contains(char[] s) {
			return contains(s, 0, s.length);
		}

		public boolean contains(char[] s, int from, int to) {
			if (from==to) return term;
			if (sons[s[from]-'a']==null) return false;
			return sons[s[from]-'a'].contains(s, from+1, to);
		}

		public boolean insert(String s) {
			return insert(s.toCharArray(), 0, s.length());
		}

		public boolean insert(String s, int from, int to) {
			return insert(s.toCharArray(), from, to);
		}

		public boolean insert(char[] s) {
			return insert(s, 0, s.length);
		}

		public boolean insert(char[] s, int from, int to) {
			if (from==to) {
				boolean addedNew = !term;
				term = true;
				return addedNew;
			}
			if (sons[s[from]-'a']==null) {
				sons[s[from]-'a'] = new Trie();
			}
			return sons[s[from]-'a'].insert(s, from+1, to);
		}
	}

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

	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(dp);

		long res = 0;
		initHash(s, 37);
		TreeSet<Long> h = new TreeSet<Long>();
		for (int i=0; i<n; ++i) for (int j=i; j<n; ++j) if (dp[i][j]<=k) {
			long hash = getHash(i, j+1);
			debug(i,j,hash);
			if (!h.contains(hash)) {
//				debug(s.substring(i, j+1));
				h.add(hash);
				res++;
			}
		}

		debug(System.currentTimeMillis()-t);
		println(res);

	}

	long[] hash;
	long[] hashPowers;
	void initHash(char[] s, int p) {
		hash = new long[s.length];
		hashPowers = new long[s.length+1];
		hash[0] = s[0];
		hashPowers[0] = 1;
		for (int i=1; i<s.length; ++i) {
			hash[i] = hash[i-1]*p + s[i];
			hashPowers[i] = hashPowers[i-1]*p;
		}
		hashPowers[hashPowers.length-1]=hashPowers[hashPowers.length-2]*p;
	}
	long getHash(int start, int end) {
		return hashPowers[hash.length-(end-start)] * (hash[end-1]-(start==0?0:hash[start-1])*hashPowers[end-start]);
	}

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

	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';
		k = nextInt();

//		long t = System.currentTimeMillis();

		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);

		Trie trie = new Trie();
		for (int i=0; i<n; ++i) trie.insert(s,i,n);

		println(res);

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

	}

	int k;
	int res = 0;
	int[][] dp;

	class Trie {

		int elementCnt = 26;
		Trie[] sons;

		public Trie() {
			sons = new Trie[elementCnt];
		}

		public void insert(char[] s, int from, int to) {
			Trie node = this;
			for (int i=from; i<to && dp[from][i]<=k; ++i) {
				if (node.sons[s[i]-'a']==null) {
					node.sons[s[i]-'a'] = new Trie();
					res++;
				}
				node = node.sons[s[i]-'a'];
			}
		}
	}

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

	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 java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.FileReader;
import java.io.BufferedWriter;
import java.util.Set;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.File;
import java.io.Writer;
import java.util.StringTokenizer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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) {
        String s = in.next();
        String alpha = in.next();
        int k = in.nextInt();
        Set<Character> bad = new HashSet<Character>();
        for (int i = 0; i < 26; ++i)
            if (alpha.charAt(i) == '0')
                bad.add((char) ('a' + i));
        int n = s.length();
        int[] cntbad = new int[n];
        cntbad[0] = bad.contains(s.charAt(0)) ? 1 : 0;
        for (int i = 1; i < n; ++i)
            cntbad[i] = cntbad[i - 1] + (bad.contains(s.charAt(i)) ? 1 : 0);
        int[] a = StringUtils.suffixArray(s);
        int[] lcp = StringUtils.lcp(a, s);
        long ans = 0L;
        for (int i = 0; i < a.length; ++i)
            for (int l = i == 0 ? 1 : lcp[i - 1] + 1; a[i] + l <= n; ++l)
                if (cntbad[a[i] + l - 1] - cntbad[a[i]] + (bad.contains(s.charAt(a[i])) ? 1 : 0) <= k) ++ans;
        out.print(ans);

    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader(File f) {
        try {
            br = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public InputReader(InputStream f) {
        br = new BufferedReader(new InputStreamReader(f));
    }

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

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

    }

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 close() {
        writer.close();
    }
}

class StringUtils {

    public static int[] suffixArray(CharSequence str) {
        int n = str.length();
        int[] sa = new int[n];
        int[] rank = new int[n];
        int maxlen = n;
        for (int i = 0; i < n; i++) {
            rank[i] = str.charAt(i);
            maxlen = Math.max(maxlen, str.charAt(i) + 1);
        }

        int[] cnt = new int[maxlen];
        for (int i = 0; i < n; i++)
            ++cnt[rank[i]];
        for (int i = 1; i < cnt.length; i++)
            cnt[i] += cnt[i - 1];
        for (int i = 0; i < n; i++)
            sa[--cnt[rank[i]]] = i;

        for (int len = 1; len < n; len *= 2) {
            int[] r = rank.clone();
            rank[sa[0]] = 0;
            for (int i = 1; i < n; i++) {
                int s1 = sa[i - 1];
                int s2 = sa[i];
                rank[s2] = r[s1] == r[s2] && Math.max(s1, s2) + len < n && r[s1 + len / 2] == r[s2 + len / 2] ? rank[s1] : i;
            }
            for (int i = 0; i < n; i++)
                cnt[i] = i;
            int[] s = sa.clone();
            for (int i = 0; i < n; i++) {
                int s1 = s[i] - len;
                if (s1 >= 0)
                    sa[cnt[rank[s1]]++] = s1;
            }
        }
        return sa;
    }

    public static int[] lcp(int[] sa, String s) {
        int n = sa.length;
        int[] rank = new int[n];
        for (int i = 0; i < n; i++)
            rank[sa[i]] = i;
        int[] lcp = new int[n - 1];
        for (int i = 0, h = 0; i < n; i++) {
            if (rank[i] < n - 1) {
                for (int j = sa[rank[i] + 1]; Math.max(i, j) + h < s.length() && s.charAt(i + h) == s.charAt(j + h); ++h)
                    ;
                lcp[rank[i]] = h;
                if (h > 0)
                    --h;
            }
        }
        return lcp;
    }
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

   private void solve() throws IOException {
      String str = nextToken();
      char[] good = nextToken().toCharArray();
      int k = nextInt();
      int len = str.length();
      int ks[] = new int[len];
      for (int i = 0; i < len; ++i)
         ks[i] = good[str.charAt(i) - 'a'] == '0' ? 1 : 0;
      int tree[][] = new int[1500 * 750][26];
      long ans = 0;
      int ptr = 1;
      for (int i = 0; i < len; ++i) {
         int ck = 0;
         int pos = 0;
         for (int j = i; j < len; ++j) {
            ck += ks[j];
            if (ck > k)
               break;
            int let = str.charAt(j) - 'a';
            if (tree[pos][let] == 0) {
               ++ans;
               tree[pos][let] = ptr;
               pos = ptr;
               ++ptr;
            } else
               pos = tree[pos][let];
         }

      }

      println(ans);
   }

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

   public void run() {
      try {
         if (isFileIO) {
            pw = new PrintWriter(new File("cake_cutting.out"));
            br = new BufferedReader(new FileReader("cake_cutting.txt"));
         } else {
            pw = new PrintWriter(System.out);
            br = new BufferedReader(new InputStreamReader(System.in));
         }
         solve();
         pw.close();
         br.close();
      } catch (IOException e) {
         System.err.println("IO Error");
      }
   }

   private void print(Object o) {
      pw.print(o);
   }

   private void println(Object o) {
      pw.println(o);
   }

   private void println() {
      pw.println();
   }

   int[] nextIntArray(int n) throws IOException {
      int arr[] = new int[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Integer.parseInt(nextToken());
      return arr;
   }

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

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

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

   private String nextToken() throws IOException {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
         tokenizer = new StringTokenizer(br.readLine());
      }

      return tokenizer.nextToken();
   }

   private BufferedReader br;
   private StringTokenizer tokenizer;
   private PrintWriter pw;
   private final boolean isFileIO = false;
}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

   private void solve() throws IOException {
      String str = nextToken();
      char[] good = nextToken().toCharArray();
      int ks[] = new int[str.length() + 1];
      ks[0] = good[str.charAt(0) - 'a'] == '0' ? 1 : 0;
      for (int i = 1; i < str.length(); ++i)
         ks[i] += ks[i - 1] + (good[str.charAt(i) - 'a'] == '0' ? 1 : 0);
      ks[str.length()] = ks[str.length() - 1];
      int k = nextInt();
      int len = str.length();

      Set<String> set = new HashSet<>();

      for (int i = 0; i < len; ++i)
         for (int j = i + 1; j <= len; ++j)
            if (i == 0) {
               if (ks[j - 1] <= k)
                  set.add(str.substring(0, j));
            } else {
               if (ks[j - 1] - ks[i - 1] <= k)
                  set.add(str.substring(i, j));
            }

      println(set.size());
   }

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

   public void run() {
      try {
         if (isFileIO) {
            pw = new PrintWriter(new File("cake_cutting.out"));
            br = new BufferedReader(new FileReader("cake_cutting.txt"));
         } else {
            pw = new PrintWriter(System.out);
            br = new BufferedReader(new InputStreamReader(System.in));
         }
         solve();
         pw.close();
         br.close();
      } catch (IOException e) {
         System.err.println("IO Error");
      }
   }

   private void print(Object o) {
      pw.print(o);
   }

   private void println(Object o) {
      pw.println(o);
   }

   private void println() {
      pw.println();
   }

   int[] nextIntArray(int n) throws IOException {
      int arr[] = new int[n];
      for (int i = 0; i < n; ++i)
         arr[i] = Integer.parseInt(nextToken());
      return arr;
   }

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

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

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

   private String nextToken() throws IOException {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
         tokenizer = new StringTokenizer(br.readLine());
      }

      return tokenizer.nextToken();
   }

   private BufferedReader br;
   private StringTokenizer tokenizer;
   private PrintWriter pw;
   private final boolean isFileIO = false;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Vaibhav Mittal
 */
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.readString();
        String G = in.readString();
        int k = in.readInt();
        int res = 0;
        Node root = new Node();
        for (int i = 0; i < S.length(); ++i) {
            int countBad = 0;
            Node cur = root;
            for (int j = i; j < S.length(); ++j) {
                int which = S.charAt(j) - 'a';
                if (G.charAt(which) == '0') ++countBad;
                if (countBad > k) break;
                if (cur.next[which] == null) {
                    ++res;
                    cur.next[which] = new Node();
                }
                cur = cur.next[which];
            }
        }
        out.println(res);
    }
}

class Node {
    Node[] next;

    public Node() {
        next = new Node[26];
    }
}

class InputReader {
    private BufferedReader reader;
    private 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 (IOException e) {
                throw new RuntimeException();
            }
        }
        return tokenizer.nextToken();
    }

    public String readString() {
        return next();
    }

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


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

public class Code implements Runnable {
    public static void main(String[] args) throws IOException {
        new Thread(new Code()).start();
    }

    private void solve() throws IOException {
        String str = nextToken();
        String type = nextToken();

        int k = nextInt();

        int[] prefix = new int[str.length()];
        for (int i = 0; i < str.length(); ++i) {
            if (type.charAt(str.charAt(i) - 'a') == '0') {
                prefix[i] += 1;
            }

            if (i > 0)
                prefix[i] += prefix[i - 1];
        }

        long[] hashes = new long[str.length()];
        long[] pows = new long[str.length() + 1];
        long mod = 3733;

        pows[0] = 1;
        hashes[0] = str.charAt(0) - 'a' + 1;
        for (int i = 1; i < str.length(); ++i) {
            pows[i] = pows[i - 1] * mod;
            hashes[i] = (hashes[i - 1] * mod + str.charAt(i) - 'a' + 1);
        }

        pows[pows.length - 1] = pows[pows.length - 2] * mod;
        long ans = 0;

        for (int i = 1; i <= str.length(); ++i) {
            Set<Long> strings = new HashSet<Long>();
            for (int j = 0; j + i <= str.length(); ++j) {
                if (prefix[j + i - 1] - (j > 0 ? prefix[j - 1] : 0) <= k) {
                    long hash = hashes[j + i - 1] - (j > 0 ? hashes[j - 1] : 0) * pows[i];
                    strings.add(hash);
                }
            }

            ans += strings.size();
        }

        writer.println(ans);
    }

    private class Pair<E, V> implements Comparable<Pair<E, V>> {
        public Pair(E first, V second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public int compareTo(Pair<E, V> obj) {
            if (first.equals(obj.first)) return ((Comparable) second).compareTo(obj.second);
            return ((Comparable) first).compareTo(obj.first);
        }

        @Override
        public boolean equals(Object obj) {
            Pair other = (Pair) obj;
            return first.equals(other.first) && second.equals(other.second);
        }

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

        public E first;
        public V second;
    }

    @Override
    public void run() {
        try {
            if (in.equals(""))
                reader = new BufferedReader(new InputStreamReader(System.in));
            else
                reader = new BufferedReader(new FileReader(in));

            if (out.equals(""))
                writer = new PrintWriter(System.out, false);
            else
                writer = new PrintWriter(new FileWriter(out), false);

            solve();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //writer.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");

            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

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

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

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

    private float nextFloat() throws IOException {
        return Float.parseFloat(nextToken());
    }

    private String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(reader.readLine());

        return st.nextToken();
    }

    private String in = "", out = "";
    private BufferedReader reader;
    private PrintWriter writer;
    private StringTokenizer st;
}


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

public class Code implements Runnable {
    public static void main(String[] args) throws IOException {
        new Thread(new Code()).start();
    }

    private void solve() throws IOException {
        String str = nextToken();
        String type = nextToken();

        int k = nextInt();

        int[] prefix = new int[str.length()];
        for (int i = 0; i < str.length(); ++i) {
            if (type.charAt(str.charAt(i) - 'a') == '0') {
                prefix[i] += 1;
            }

            if (i > 0)
                prefix[i] += prefix[i - 1];
        }

        long[] hashes = new long[str.length()];
        long[] pows = new long[str.length() + 1];
        long mod = 3337;

        pows[0] = 1;
        hashes[0] = str.charAt(0) - 'a' + 1;
        for (int i = 1; i < str.length(); ++i) {
            pows[i] = pows[i - 1] * mod;
            hashes[i] = (hashes[i - 1] * mod + str.charAt(i) - 'a' + 1);
        }

        pows[pows.length - 1] = pows[pows.length - 2] * mod;
        long ans = 0;

        for (int i = 1; i <= str.length(); ++i) {
            Set<Long> strings = new HashSet<Long>();
            for (int j = 0; j + i <= str.length(); ++j) {
                if (prefix[j + i - 1] - (j > 0 ? prefix[j - 1] : 0) <= k) {
                    long hash = hashes[j + i - 1] - (j > 0 ? hashes[j - 1] : 0) * pows[i];
                    strings.add(hash);
                }
            }

            ans += strings.size();
        }

        writer.println(ans);
    }

    private class Pair<E, V> implements Comparable<Pair<E, V>> {
        public Pair(E first, V second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public int compareTo(Pair<E, V> obj) {
            if (first.equals(obj.first)) return ((Comparable) second).compareTo(obj.second);
            return ((Comparable) first).compareTo(obj.first);
        }

        @Override
        public boolean equals(Object obj) {
            Pair other = (Pair) obj;
            return first.equals(other.first) && second.equals(other.second);
        }

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

        public E first;
        public V second;
    }

    @Override
    public void run() {
        try {
            if (in.equals(""))
                reader = new BufferedReader(new InputStreamReader(System.in));
            else
                reader = new BufferedReader(new FileReader(in));

            if (out.equals(""))
                writer = new PrintWriter(System.out, false);
            else
                writer = new PrintWriter(new FileWriter(out), false);

            solve();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //writer.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 + " KB");

            try {
                reader.close();
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

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

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

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

    private float nextFloat() throws IOException {
        return Float.parseFloat(nextToken());
    }

    private String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(reader.readLine());

        return st.nextToken();
    }

    private String in = "", out = "";
    private BufferedReader reader;
    private PrintWriter writer;
    private StringTokenizer st;
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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 {

    private class Pair{
        long hash1, hash2;
        public Pair( long h1, long h2 ) {
            hash1=h1;
            hash2=h2;
        }

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

            Pair pair = (Pair) o;

            if (hash1 != pair.hash1) return false;
            if (hash2 != pair.hash2) return false;

            return true;
        }

        public int hashCode() {
            int result = (int) (hash1 ^ (hash1 >>> 32));
            result = 31 * result + (int) (hash2 ^ (hash2 >>> 32));
            return result;
        }
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char s[]=in.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Pair> set=new HashSet<Pair>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            long hash1=0, hash2=0;
            for( int j=i; j<n; j++ ) {
                hash1=31L*hash1+s[j];
                hash2=31L*hash2+s[j]-'a';
                if( numBad[j]-numBad[i]+(bad[s[i]-'a']=='1'?0:1)<=k )
                    set.add( new Pair(hash1, hash2) );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Integer> set=new HashSet<Integer>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            int hash=0;
            for( int j=i; j<n; j++ ) {
                hash=31*hash+s[j];
                if( numBad[j]-numBad[i]+(bad[s[i]-'a']=='1'?0:1)<=k )
                    set.add( hash );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Integer> set=new HashSet<Integer>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            int hash=0;
            for( int j=i; j<n; j++ ) {
                hash=31*hash+s[j];
                if( numBad[j]-numBad[i]+(bad[i]=='1'?0:1)<=k )
                    set.add( hash );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Integer> set=new HashSet<Integer>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            int hash=0;
            for( int j=i; j<n; j++ ) {
                hash=31*hash+s[j];
                if( numBad[j]-numBad[i]+(bad[s[i]-'a']=='1'?0:1)<=k )
                    set.add( hash );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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 {

    private class Pair{
        long hash1, hash2;
        public Pair( long h1, long h2 ) {
            hash1=h1;
            hash2=h2;
        }

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

            Pair pair = (Pair) o;

            if (hash1 != pair.hash1) return false;
            if (hash2 != pair.hash2) return false;

            return true;
        }

        public int hashCode() {
            int result = (int) (hash1 ^ (hash1 >>> 32));
            result = 31 * result + (int) (hash2 ^ (hash2 >>> 32));
            return result;
        }
    }

    public void solve(int testNumber, InputReader in, OutputWriter out) {
        char s[]=in.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Pair> set=new HashSet<Pair>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            long hash1=0, hash2=0;
            for( int j=i; j<n; j++ ) {
                hash1=31L*hash1+s[j];
                hash2=37L*hash2+s[j];
                if( numBad[j]-numBad[i]+(bad[s[i]-'a']=='1'?0:1)<=k )
                    set.add( new Pair(hash1, hash2) );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.Set;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.HashSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Diego Huerfano ( diego.link )
 */
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.readString().toCharArray();
        final int n=s.length;
        char bad[]=in.readString().toCharArray();
        final int k=in.readInt();

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

        Set<Long> set=new HashSet<Long>( n*(n-1)/2 +n );
        for( int i=0; i<n; i++ ) {
            long hash=0;
            for( int j=i; j<n; j++ ) {
                hash=31L*hash+s[j];
                if( numBad[j]-numBad[i]+(bad[s[i]-'a']=='1'?0:1)<=k )
                    set.add( hash );
            }
        }
        out.printLine( set.size() );

    }
}

class InputReader {

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

    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 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 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

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 close() {
        writer.close();
    }
}


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

public class D {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer stok;

	String nextToken() throws IOException {
		while (stok == null || !stok.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			stok = new StringTokenizer(s);
		}
		return stok.nextToken();
	}

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

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

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

	char nextChar() throws IOException {
		return (char) (br.read());
	}

	String nextLine() throws IOException {
		return br.readLine();
	}
	final long MOD = 1000000000000007L;
	void solve() throws IOException {
		String s = nextLine();
		String p = nextLine();
		int k = nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		al.add(-1);
		for (int i = 0; i < s.length(); i++) {
			if (p.charAt(s.charAt(i) - 'a') == '0') al.add(i);
		}
		HashSet<Long> set = new HashSet<Long>();
		long[] pp = new long[1531];
		pp[0] = 1;
		for (int i = 1; i < 1531; i++) {
			pp[i] = (pp[i-1] * 347) % MOD;;
		}
		long[][] hash = new long[1531][1531];
		for (int i = 0; i < s.length(); i++) {
			long h = 0;
			for (int j = i; j < s.length(); j++) {
				h = (h + pp[j - i] * s.charAt(j)) % MOD;
				hash[i][j] = h;
			}
		}
		for (int left = 0; left < s.length(); left++) {
			for (int right = left; right < s.length(); right++) {
				int l = 0;
				int r = al.size();
				int m;
				while (l < r - 1) {
					m = (l + r) / 2;
					if (al.get(m) < left) l = m; else r = m;
				}
				int q = l;
				int e;
				if (left == 0 && right == 2)
					e = 1;
				l = 0;
				r = al.size();
				while (l < r - 1) {
					m = (l + r) / 2;
					if (al.get(m) <= right) l = m; else r = m;
				}
				int kol = l - q;
				if (kol <= k) {
					long h = hash[left][right];
					if (!set.contains(h)) {
						set.add(h);
						//out.println(left + " " + right);
					}
				}
			}
		}
		out.println(set.size());
	}

	void run() throws IOException {
		// br = new BufferedReader(new FileReader("input.txt"));
		// out = new PrintWriter("output.txt");
		 br = new BufferedReader(new InputStreamReader(System.in));
		 out = new PrintWriter(System.out);
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		// Localea.setDefault(Locale.US);
		new D().run();
	}
}


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

public class D {
	BufferedReader br;
	PrintWriter out;
	StringTokenizer stok;

	String nextToken() throws IOException {
		while (stok == null || !stok.hasMoreTokens()) {
			String s = br.readLine();
			if (s == null) {
				return null;
			}
			stok = new StringTokenizer(s);
		}
		return stok.nextToken();
	}

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

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

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

	char nextChar() throws IOException {
		return (char) (br.read());
	}

	String nextLine() throws IOException {
		return br.readLine();
	}
	final long MOD = 1000000007L;
	void solve() throws IOException {
		String s = nextLine();
		String p = nextLine();
		int k = nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		al.add(-1);
		for (int i = 0; i < s.length(); i++) {
			if (p.charAt(s.charAt(i) - 'a') == '0') al.add(i);
		}
		HashSet<Long> set = new HashSet<Long>();
		long[] pp = new long[1531];
		pp[0] = 1;
		for (int i = 1; i < 1531; i++) {
			pp[i] = (pp[i-1] * 347) % MOD;;
		}
		long[][] hash = new long[1531][1531];
		for (int i = 0; i < s.length(); i++) {
			long h = 0;
			for (int j = i; j < s.length(); j++) {
				h = (h + pp[j - i] * s.charAt(j)) % MOD;
				hash[i][j] = h;
			}
		}
		for (int left = 0; left < s.length(); left++) {
			for (int right = left; right < s.length(); right++) {
				int l = 0;
				int r = al.size();
				int m;
				while (l < r - 1) {
					m = (l + r) / 2;
					if (al.get(m) < left) l = m; else r = m;
				}
				int q = l;
				int e;
				if (left == 0 && right == 2)
					e = 1;
				l = 0;
				r = al.size();
				while (l < r - 1) {
					m = (l + r) / 2;
					if (al.get(m) <= right) l = m; else r = m;
				}
				int kol = l - q;
				if (kol <= k) {
					long h = hash[left][right];
					if (!set.contains(h)) {
						set.add(h);
						//out.println(left + " " + right);
					}
				}
			}
		}
		out.println(set.size());
	}

	void run() throws IOException {
		// br = new BufferedReader(new FileReader("input.txt"));
		// out = new PrintWriter("output.txt");
		 br = new BufferedReader(new InputStreamReader(System.in));
		 out = new PrintWriter(System.out);
		solve();
		br.close();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		// Localea.setDefault(Locale.US);
		new D().run();
	}
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class D {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String line = s.nextLine();
        String mask = s.nextLine();
        int k = s.nextInt();

        int n = line.length();
        byte[] bytes = new byte[n];
        for (int i = 0; i < n; i++) {
            bytes[i] = (byte) (line.charAt(i) - 'a');
        }
        short[] count = new short[n + 1];
        for (int i = 1; i <= n; i++) {
            count[i] = count[i - 1];
            if (mask.charAt(bytes[i - 1]) == '0') {
                count[i]++;
            }
        }
        int ans = 0;
        ArrayList<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> initList = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            initList.add(i);
        }
        al.add(initList);
        for (int l = 1; l <= n; l++) {
            ArrayList<ArrayList<Integer>> nal = new ArrayList<ArrayList<Integer>>();
            for (ArrayList<Integer> list : al) {
                HashMap<Byte, ArrayList<Integer>> map = new HashMap<Byte, ArrayList<Integer>>();
                for (Integer i : list) {
                    if (i < n) {
                        int bad = count[i + 1] - count[i + 1 - l];
                        if (bad <= k) {
                            if (map.containsKey(bytes[i])) {
                                map.get(bytes[i]).add(i + 1);
                            } else {
                                ans++;
                                ArrayList<Integer> tmpList = new ArrayList<Integer>();
                                tmpList.add(i + 1);
                                map.put(bytes[i], tmpList);
                            }
                        }
                    }
                }
                nal.addAll(map.values());
            }
            al = nal;
        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String line = s.nextLine();
        char[] str = line.toCharArray();
        String mask = s.nextLine();
        int k = s.nextInt();
        int n = line.length();
        int[] count = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            count[i] = count[i - 1];
            if (mask.charAt(str[i - 1] - 'a') == '0') {
                count[i]++;
            }
        }
        int ans = 0;
        ArrayList<HashSet<Integer>> al = new ArrayList<HashSet<Integer>>();
        HashSet<Integer> initSet = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            initSet.add(i);
        }
        al.add(initSet);
        for (int l = 1; l <= n; l++) { // length of substring
            ArrayList<HashSet<Integer>> nal = new ArrayList<HashSet<Integer>>();
            for (HashSet<Integer> set : al) {
                HashMap<Character, HashSet<Integer>> map = new HashMap<Character, HashSet<Integer>>();
                for (Integer i : set) {
                    int bad = count[i + 1] - count[i + 1 - l];
                    if (bad <= k) {
                        if (map.containsKey(str[i])) {
                            if (i < n - 1) {
                                map.get(str[i]).add(i + 1);
                            }
                        } else {
                            ans++;
                            if (i < n - 1) {
                                HashSet<Integer> tmpSet = new HashSet<Integer>();
                                tmpSet.add(i + 1);
                                map.put(str[i], tmpSet);
                            }
                        }
                    }
                }
                nal.addAll(map.values());
            }
            al = nal;
        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String line = s.nextLine();
        String mask = s.nextLine();
        int k = s.nextInt();

        int n = line.length();
        byte[] bytes = new byte[n];
        for (int i = 0; i < n; i++) {
            bytes[i] = (byte) (line.charAt(i) - 'a');
        }
        short[] count = new short[n + 1];
        for (int i = 1; i <= n; i++) {
            count[i] = count[i - 1];
            if (mask.charAt(bytes[i - 1]) == '0') {
                count[i]++;
            }
        }
        int ans = 0;
        ArrayList<ArrayList<Integer>> al = new ArrayList<ArrayList<Integer>>();
        ArrayList<Integer> initList = new ArrayList<Integer>();
        for (int i = 0; i < n; i++) {
            initList.add(i);
        }
        al.add(initList);
        for (int l = 1; l <= n; l++) { // length of substring
            ArrayList<ArrayList<Integer>> nal = new ArrayList<ArrayList<Integer>>();
            for (ArrayList<Integer> list : al) {
                HashMap<Byte, ArrayList<Integer>> map = new HashMap<Byte, ArrayList<Integer>>();
                for (Integer i : list) {
                    if (i < n) {
                        int bad = count[i + 1] - count[i + 1 - l];
                        if (bad <= k) { // it is good
                            if (map.containsKey(bytes[i])) {
                                // counted before
                                map.get(bytes[i]).add(i + 1);
                            } else {
                                // new character, not counted
                                ans++;
                                ArrayList<Integer> tmpList = new ArrayList<Integer>();
                                tmpList.add(i + 1);
                                map.put(bytes[i], tmpList);
                            }
                        }
                    }
                }
                nal.addAll(map.values());
            }
            al = nal;
        }
        System.out.println(ans);
    }
}


import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class D {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String line = s.nextLine();
        char[] str = line.toCharArray();
        String mask = s.nextLine();
        int k = s.nextInt();
        int n = str.length;
        int[] count = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            count[i] = count[i - 1];
            if (mask.charAt(str[i - 1] - 'a') == '0') {
                count[i]++;
            }
        }
        int ans = 0;
        ArrayList<HashSet<Integer>> al = new ArrayList<HashSet<Integer>>();
        HashSet<Integer> initSet = new HashSet<Integer>();
        for (int i = 0; i < n; i++) {
            initSet.add(i);
        }
        al.add(initSet);
        for (int l = 1; l <= n; l++) { // length of substring
            ArrayList<HashSet<Integer>> nal = new ArrayList<HashSet<Integer>>();
            for (HashSet<Integer> set : al) {
                HashMap<Character, HashSet<Integer>> map = new HashMap<Character, HashSet<Integer>>();
                for (Integer i : set) {
                    if (i < n) {
                        int bad = count[i + 1] - count[i + 1 - l];
                        if (bad <= k) { // it is good
                            if (map.containsKey(str[i])) {
                                // counted before
                                map.get(str[i]).add(i + 1);
                            } else {
                                // new character, not counted
                                ans++;
                                HashSet<Integer> tmpSet = new HashSet<Integer>();
                                tmpSet.add(i + 1);
                                map.put(str[i], tmpSet);
                            }
                        }
                    }
                }
                nal.addAll(map.values());
            }
            al = nal;
        }
        System.out.println(ans);
    }
}


def checkList(arr,word):
    for i in arr:
        if i == word:
            return True
    return False

def getRoot(word):
    newWord = ""
    for i in range(26):
        if checkList(word,chr(i+97)):
            newWord += chr(i+97)
    return newWord

num = int(input())
array = input().split(' ')
roots = []
for i in array:
    if not checkList(roots,getRoot(i)):
        roots.append(getRoot(i))
print(len(roots))


n=int(input())
a=input().split()
v=[]
for i in a:
    b=sorted(i)
    b="".join(set(i))
    v.append(b)

print(len(set(v)))


n=int(input())
a=input().split()
v=[]
for i in a:
    sorted("".join(i))
    v.append("".join(set(i)))

print(len(set(v)))


n=int(input())
a=input().split()
v=[]
for i in a:
    v.append("".join(set(i)))
print(len(set(v)))


n=int(input())

s=[x for x in input().split()]
a=[]
for i in s:
    u=sorted(set(i))
    x=''.join(u)
    a.append(x)
print(len(set(a)))


n = int(input())
s = list(input())
s = "".join(s).split()
lst = []
for i in s:
   lst.append("".join(list(sorted(set(list(i))))))
print(lst)
print(len(list(set(lst))))


n = int(input())
s = list(input())
s = "".join(s).split()
lst = []
for i in s:
   lst.append("".join(list(sorted(set(list(i))))))
print(len(list(set(lst))))


n = int(input())
s = list(input())
s = "".join(s).split()
lst = []
for i in s:
   lst.append("".join(list(set(list(i)))))
print(len(list(set(lst))))


'''
3
amer arem mrea
'''
n = int(input())
x = [x for x in input().split()]
ans = set()
for a in x:
    for y in a:
        ans.add(y)
return len(ans)


'''
3
amer arem mrea
'''
#again
n = int(input())
x = [x for x in input().split()]
ans = set()
for a in x:
    for y in a:
        ans.add(y)
return len(ans)


'''
3
amer arem mrea
'''
n = int(input())
x = [x for x in input().split()]
ans = set{}
for a in x:
    for y in x:
        ans.add(y)
return len(ans)


'''
3
amer arem mrea
'''
n = int(input())
x = [x for x in input().split()]
ans = set{}
for a in x:
    for y in x:
        ans.add(y)
print(len(ans)   )


n = int(input())
ans = []
arr = [x for x in input().split()]
for a in arr:
    curr = sorted(set(a))
    if curr not in ans:
        ans.append(curr)
print(len(ans))


n = int(input())
words = input().split(" ")
mySet = set()
for i in words:
    l = list(i)
    ts = {item for item in l}
    mySet.add(str(ts))
print(len(mySet))


n = int(input())
words = input().split(" ")
mySet = set()
for i in words:
    l = list(i)
    l.sort()
    ts = {item for item in l}
    mySet.add(str(ts))
print(len(mySet))


input()
print(len(set(map(lambda x: repr(set(x)), input().split()))))


input();x = map(lambda x: repr(set(sorted(x))), input().split())
print(len(set(x)))


#!/usr/bin/env python3

input()
words = input().split(' ')

print(len(set(tuple(sorted(set(w))) for w in words)))


#!/usr/bin/env python3

print(len(set(tuple(sorted(set(w))) for w in (input(), input().split(' '))[1])))


n = int(input())
a = set()
s = input().split()
for i in range(n):
    b = str(set(s[i]))
    a.add(b)
print(len(a))


n = int(input())
a = []
s = input().split()
ans = 0
for i in range(n):
    if set(s[i]) not in a:
        a.append(set(s[i]))
        ans += 1
print(ans)


n=int(input())
list1=input().split()
final=[]
for i in list1:
    string=""
    summer=0
    for x in i:
        if x not in string:
            string+=x
            summer+=ord(x)
    if summer not in final:
        final.append(summer)
print(len(final))


n=int(input())
list1=input().split()
final=[]
for i in list1:
    string=""
    summer=0
    for x in i:
        if x not in string:
            string+=x
            temp=list(string)
            temp.sort()
            string="".join(temp)
    if string not in final:
        final.append(string)
print(len(final))


input(); print(len(set(''.join(set(x)) for x in input().split())))


input(); print(len(set(''.join(sorted(set(x))) for x in input().split())))


n=int(input())
a=list(input().split())
q=[]
for i in a:
    w=sorted(list(set(list(i))))
    if w not in q:
        q.append(w)

print(len(q))


n=int(input())
a=list(input().split())
q=[]
for i in a:
    w=list(set(list(i)))
    if w not in q:
        q.append(w)
print(len(q))


n=int(input())
a=[x for x in input().split()]
for i in range(len(a)):
    a[i]="".join(sorted(a[i]))
print(len(set(a)))


n=int(input())
a=[x for x in input().split()]
for i in range(len(a)):
    a[i]=str(sorted(set(a[i])))
print(len(set(a)))


n=int(input())
a=[x for x in input().split()]
for i in range(len(a)):
    a[i]=set(a[i])
for i in range(len(a)):
    a[i]="".join(list(a[i]))
print(len(set(a)))


n=int(input())
a=[x for x in input().split()]
for i in range(len(a)):
    a[i]=str(set(a[i]))
print(len(set(a)))


n = int(input())
a = list(input().split())
f = [[0] * 26 for i in range(n)]
for i in range(n):
    for j in range(len(a[i])):
        f[i][ord(a[i][j]) - ord('a')] = 1
k1 = 0
for i in range(n):
    a[i] = ''
    for j in range(26):
        if (f[i][j]):
            a[i] += str(ord('a') + j)
a.sort()
a = ['0'] + a
i = 1
while (i < len(a) ):
    if a[i] == a[i - 1]:
        a = a[:i - 1] + a[i:]
    else:
        i += 1
print(len(a) - 1)


n = int(input())
a = list(input().split())
f = [[0] * 26 for i in range(n)]
for i in range(n):
    for j in range(len(a[i])):
        f[i][ord(a[i][j]) - ord('a')] = 1
k1 = 0
for i in range(n):
    for j in range(i + 1, n):
        fl = True
        for k in range(26):
            if f[i][k] != f[j][k]:
                fl = False
                break
        if (fl): #одинаковые
            a[j] = a[i]
a.sort()
a = ['0'] + a
i = 1
while (i < len(a)):
    if a[i] == a[i - 1]:
        a = a[:i - 1] + a[i:]
    else:
        i += 1
print(len(a) - 1)


"""Aramic script.

http://codeforces.com/contest/975/problem/A

In Aramic language words can only represent objects.

Words in Aramic have special properties:

- A word is a root if it does not contain the same letter more than once.

- A root and all its permutations represent the same object.

- The root x of a word y is the word that contains all letters that appear in y
in a way that each letter appears once. For example, the root of "aaaa", "aa",
"aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab".

- Any word in Aramic represents the same object as its root.

You have an ancient script in Aramic. What is the number of different objects
mentioned in the script?

"""

def solution(s):
    roots = set()
    for w in s:
        roots.add(tuple(sorted(set(w))))
    return len(roots)

if __name__ == '__main__':
    n = int(input().strip())
    s = input().strip().split()[:n]
    print(solution(s))


"""Aramic script.

http://codeforces.com/contest/975/problem/A

In Aramic language words can only represent objects.

Words in Aramic have special properties:

- A word is a root if it does not contain the same letter more than once.

- A root and all its permutations represent the same object.

- The root x of a word y is the word that contains all letters that appear in y
in a way that each letter appears once. For example, the root of "aaaa", "aa",
"aaa" is "a", the root of "aabb", "bab", "baabb", "ab" is "ab".

- Any word in Aramic represents the same object as its root.

You have an ancient script in Aramic. What is the number of different objects
mentioned in the script?
"""

def count_objects(array):
    roots = {tuple(sorted(set(s))) for s in array}
    return len(roots)

if __name__ == '__main__':
    n = int(input().strip())
    s = input().strip().split()[:n]
    print(count_objects(s))


n = int(input())
l = input().split()
roots = {}
res = 0
for i in l:
    if "".join(sorted(set(i))) not in roots:
        res += 1
        roots["".join(sorted(set(i)))] = 1
print(res)


n = int(input())
l = input().split()
roots = {}
for i in l:
    roots["".join(set(i))] = 1
print(len(roots.keys()))


n= int(input())
s= input().split()
li1= list(s)
'''li2= list(set(li1[0]))
poo= ''.join(i for i in li2)
print(poo)'''

li2 = []
li3= []

for i in li1:
    li4= list(set(i))
    poo= ''.join(m for m in li4)
    li2.append(poo)

#print(li2)
fin= set(li2)
output= len(fin)
print(output)


n= int(input())
s= input().split()
li1= list(s)

li2 = []
li3= []

for i in li1:
    li4= list(set(i))
    #print(li4)
    li4.sort()
    poo= ''.join(m for m in li4)
    #print(poo)
    li2.insert(-1,poo)

#print(li2)
fin= set(li2)
#output= len(fin)
print(len(fin))


n= int(input())
s= input().split()
li1= list(s)
'''li2= list(set(li1[0]))
poo= ''.join(i for i in li2)
print(poo)'''

li2 = []
li3= []

for i in li1:
    li4= list(set(i))
    #print(li4)
    li4.sort()
    poo= ''.join(m for m in li4)
    #print(poo)
    li2.insert(-1,poo)

#print(li2)
fin= set(li2)
#output= len(fin)
print(len(fin)


n=int(input())
script=input().split()
l=[]
for i in script:
  k=list("".join(set(i)))
  k.sort()
  k=str(k)
  if k not in l:
    l.append(k)
print(len(l))