You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.

A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string  slsl + 1...sr.

The substring s[l...r] is good, if among the letters  sl, sl + 1, ..., sr there are at most k bad ones (look at the sample's explanation to understand it more clear).

Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] ≠ s[p...q].

Input

The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.

The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.

The third line of the input consists a single integer k (0 ≤ k ≤ |s|) — the maximum acceptable number of bad characters in a good substring.

Output

Print a single integer — the number of distinct good substrings of string s.

Examples

Input

ababab
01000000000000000000000000
1


Output

5


Input

acbacbacaa
00000000000000000000000000
2


Output

8

Note

In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".

In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
//package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

public class A implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    A() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("output.txt"));
    }

    StringTokenizer stringTokenizer;

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

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

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

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

    private int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    int inv(int x) {
        return pow(x, MOD - 2);
    }

    void solve() throws IOException {
        class SuffixTree {
            final char[] s;

            public SuffixTree(char[] s) {
                this.s = s;
            }
            class Node {
                Node suffixLink;
                Node parent;
                int pi;//which parent key leads to this node
                Node[] children = new Node[26];
                int[] f = new int[26], t = new int[26];

                int lenToChild(int ci) {
                    return t[ci] - f[ci];
                }

                char getChar(int ci, int depth) {
                    int start = f[ci];
                    return s[start + depth];
                }

                Node makeLeaf(int suffixIndex) {
                    Node leaf = new Node();
                    leaf.parent = this;
                    leaf.pi = s[suffixIndex] - 'a';
                    children[leaf.pi] = leaf;
                    f[leaf.pi] = suffixIndex;
                    t[leaf.pi] = s.length;
                    return leaf;
                }

                void print(int depth) {
                    char[] tab = new char[depth];
                    Arrays.fill(tab, ' ');
                    for (int i = 0; i < 26; i++) {
                        if (children[i] != null) {
                            System.out.print(tab);
                            for (int j = f[i]; j < t[i]; j++) {
                                System.out.print(s[j]);
                            }
                            System.out.println();
                            children[i].print(depth + t[i] - f[i]);
                        }
                    }
                }
            }

            Node construct() {
                Node dummy = new Node();
                Node root = new Node();
                root.suffixLink = root.parent = dummy;
                for (int i = 0; i < s.length; i++) {
                    int j = s[i] - 'a';
                    if(dummy.children[j] == null) {
                        dummy.children[j] = root;
                        dummy.f[j] = i;
                        dummy.t[j] = i + 1;
                        root.pi = j;
                    }
                }
                Node activePointParent = root;
                int activePointGoesWhere = 0;
                int activePointGoesDown = 0;
                for (int i = 0; i < s.length; i++) {
                    List<Node> createdInner = new ArrayList<>();
                    //while active point is implicit
                    while (activePointGoesDown > 0) {
                        while (activePointGoesDown > 0 && activePointGoesDown >= activePointParent.lenToChild(activePointGoesWhere)) {
                            int l = activePointParent.lenToChild(activePointGoesWhere);
                            int newGoesWhere = activePointParent.getChar(activePointGoesWhere, l) - 'a';
                            activePointGoesDown -= l;
                            activePointParent = activePointParent.children[activePointGoesWhere];
                            activePointGoesWhere = newGoesWhere;
                        }
                        if (activePointGoesDown == 0) {
                            break;
                        }
                        int newGoesWhere = activePointParent.getChar(activePointGoesWhere, activePointGoesDown) - 'a';
                        if (newGoesWhere == s[i] - 'a') {
                            break;
                        }
                        //split and reassign
                        Node old = activePointParent.children[activePointGoesWhere];
                        Node active = new Node();
                        active.parent = activePointParent;
                        active.pi = activePointGoesWhere;
                        active.children[newGoesWhere] = old;
                        active.f[newGoesWhere] = activePointParent.f[activePointGoesWhere] + activePointGoesDown;
                        active.t[newGoesWhere] = activePointParent.t[activePointGoesWhere];
                        old.parent = active;
                        old.pi = newGoesWhere;
                        activePointParent.children[activePointGoesWhere] = active;
                        activePointParent.t[activePointGoesWhere] = activePointParent.f[activePointGoesWhere] + activePointGoesDown;
                        //add new leaf and proceed
                        active.makeLeaf(i);
                        createdInner.add(active);
                        Node newParent = activePointParent.suffixLink;
                        int newDirection = activePointGoesWhere;
                        int sumL = 0;
                        while (activePointGoesDown > 0 && activePointGoesDown >= newParent.lenToChild(newDirection)) {
                            int l = newParent.lenToChild(newDirection);
                            sumL += l;
                            newParent = newParent.children[newDirection];
                            newDirection = activePointParent.getChar(activePointGoesWhere, sumL) - 'a';
                            activePointGoesDown -= l;
                        }
                        activePointParent = newParent;
                        activePointGoesWhere = newDirection;
                    }
                    //create suffix links
                    createdInner.add(activePointParent);
                    for (int j = 0; j < createdInner.size() - 1; j++) {
                        createdInner.get(j).suffixLink = createdInner.get(j + 1);
                    }
                    //while not end point
                    while (activePointGoesDown == 0 && activePointParent.children[s[i] - 'a'] == null) {
                        activePointParent.makeLeaf(i);
                        activePointParent = activePointParent.suffixLink;
                    }
                    if (activePointGoesDown == 0) {
                        activePointGoesWhere = s[i] - 'a';
                    }
                    activePointGoesDown++;
                }
//                root.print(0);
                return root;
            }
        }
        class SuffixTreeTest {
            {
                Random random = new Random();
                for(int k = 0; k < 100; k++) {
                    int len = 5 + k;
                    char[] s = new char[len];
                    for(int i = 0; i < len; i++) {
                        s[i] = (char)('a' + random.nextInt(2));
                    }
//                    s = "bbaabaabb".toCharArray(); len = s.length;
                    try {
                        SuffixTree.Node root = new SuffixTree(s).construct();
                        for (int i = 0; i < len; i++) {
                            SuffixTree.Node node = root;
                            for (int si = i; si < len; si++) {
                                int ci = s[si] - 'a';
                                for (int j = node.f[ci]; j < node.t[ci] && si < len; j++) {
                                    if (s[j] != s[si]) {
                                        throw new RuntimeException("failed for " + new String(s) + "\n");
                                    }
                                    si++;
                                }
                                si--;
                                node = node.children[ci];
                            }
                        }
                    } catch (Exception e) {
                        new SuffixTree(s).construct().print(0);
                        throw new RuntimeException("failed for " + new String(s), e);
                    }
                }
            }
        }
//        new SuffixTreeTest();
        final char[] s = next().toCharArray();
        final char[] good = next().toCharArray();
        final int k = nextInt();
        class Utils {
            final int[] p = new int[s.length + 1];

            {
                for (int i = 1; i < p.length; i++) {
                    p[i] = p[i - 1] + 1 - (good[s[i - 1] - 'a'] - '0');
                }
            }

            int[] when = new int[s.length + 1];

            {
                for (int i = s.length; i >= 0; i--) {
                    when[p[i]] = i;
                }
            }

            int countGoodPrefixes(int from, int limit) {
                int c = p[from];
                return when[c + limit + 1] - 1 - from;
            }

            int countGood(SuffixTree.Node node, int bad) {
                int result = 0;
                for(int i = 0; i < 26; i++) {
                    if(node.children[i] != null) {
                        int badInPath = p[node.t[i]] - p[node.f[i]];
                        if(bad + badInPath <= k) {
                            result += node.t[i] - node.f[i];
                            result += countGood(node.children[i], bad + badInPath);
                        } else {
                            result += countGoodPrefixes(node.f[i], k - bad);
                       /*     int f = 0;
                            for(int j = node.f[i]; j < node.t[i]; j++) {
                                if(good[s[j] - 'a'] == '0') {
                                    f++;
                                }
                                if(bad + f > k) {
                                    break;
                                }
                                result++;
                            }*/
                        }
                    }
                }
                return result;
            }
        }
        writer.println(new Utils().countGood(new SuffixTree(s).construct(), 0));
    }

    public static void main(String[] args) throws IOException {
        try (A a = new A()) {
            a.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}