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

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

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

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

Input

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

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

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

Output

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

Examples

Input

ababab
01000000000000000000000000
1


Output

5


Input

acbacbacaa
00000000000000000000000000
2


Output

8

Note

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

In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.BigInteger;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;


public class Main
{
    static StringTokenizer st;//=new StringTokenizer("");
    static BufferedReader br;
    ///////////////////////////////////////////////////////////////////////////////////
    
    public static void main(String args[]) throws FileNotFoundException, IOException, Exception
    {
        //Scanner in =new Scanner(new FileReader("input.txt"));
        //PrintWriter out = new PrintWriter(new FileWriter("output.txt"));
        //Scanner in=new Scanner(System.in);
        br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out=new PrintWriter(System.out);
        //StringTokenizer st;//=new StringTokenizer(br.readLine());
        //////////////////////////////////////////////////////////////////////////////////////
        
        String s = br.readLine();
        String s2 = br.readLine();
        long MOD = Long.parseLong("9223372036854775783");
        int k = Integer.parseInt(br.readLine());
        boolean[] good = new boolean[26];
        for(int i=0; i<26; i++) good[i] = (s2.charAt(i) == '1');
        int[] count = new int[s.length() + 1];
        count[0] = 0;
        Set<Long> codes = new HashSet<Long>();
        for(int i=1; i<=s.length(); i++) count[i] = count[i-1] + (good[s.charAt(i-1)-'a'] ? 0 : 1);
        for(int start = 0; start<s.length(); start++) {
                long code = 0;
                for(int end = start+1; end<=s.length(); end++) {
                        code *= 29; code += s.charAt(end-1) - 'a' + 1; code %= MOD;
                        if(count[end] - count[start] <= k) {
                                //System.out.println(cur + " " + code);
                                codes.add(code);
                        }
                }
        }
       
        //int c = 0;
        //for(int i=0; i<codes.length; i++) if(codes[i]) c++;
        System.out.println(codes.size());
        
        //////////////////////////////////////////////////////////////////////////////////////
	out.close();
    }
    
    static class RMQ
    {
        int INF=(1<<30)-1;
        int bit[];
        int n1;
        RMQ(int n)
        {
            n1=1;
            for(;n1<n;n1*=2);
            bit=new int[2*n1-1];
            for(int i=0;i<2*n1-1;i++)
                bit[i]=INF;
        }
        void insert(int i,int val)
        {
            i+=n1-1;
            bit[i]=val;
            while(i>0)
            {
                i=(i-1)/2;
                bit[i]=bit[2*i+1]&bit[2*i+2];
            }
        }
        int and(int a,int b,int k,int l,int r)
        {
            if(r<=a || l>=b) return INF;
            if(l>=a && r<=b) return bit[k];
            int v1=and(a,b,2*k+1,l,(l+r)/2);
            int v2=and(a,b,2*k+2,(l+r)/2,r);
            return v1&v2;
        }
    }
    static class BIT
    {
        private int c[];
        BIT(int n){c=new int[n+1];}
        public int lowbit(int i)
        {
            return i&(i^(i-1));
        }
        public int sum(int k)
        {
            int res=0;
            while(k>0)
            {
                res+=c[k];
                k-=lowbit(k);
            }
            return res;
        }
        public void insert(int i,int v)
        {
            while(i<c.length)
            {
                c[i]+=v;
                i+=lowbit(i);
            }
        }
    }
    ///////////////////////////////////////////////////////////////////////////////
    
    private static int gcd(int a,int b)
    {
        if(b==0)
            return a;
        return gcd(b,a%b);
    }
    private static class pair implements Comparable<pair>
    {
        int first;
        int second;
        pair()
        {
            first=0;
            second=0;
        }
        pair(int f,int s)
        {
            first=f;
            second=s;
        }

        public int compareTo(pair o)
        {
            if(first+second >  o.first+o.second)
                return 1;
            else if(first+second < o.first+o.second)
                return -1;
            else
                return 0;
        }
    }
    
    public static Integer ni() throws Exception
    {
        if(!st.hasMoreTokens())
            st=new StringTokenizer(br.readLine());
        return Integer.parseInt(st.nextToken());
    }
    public static BigInteger nb()throws Exception
    {
        if(!st.hasMoreElements())
            st=new StringTokenizer(br.readLine());
        return BigInteger.valueOf(Long.parseLong(st.nextToken()));
    }
    public static Long nl() throws Exception
    {
        if(!st.hasMoreTokens())
            st=new StringTokenizer(br.readLine());
        return Long.parseLong(st.nextToken());
    }
    public static Double nd()throws Exception
    {
        if(!st.hasMoreElements())
            st=new StringTokenizer(br.readLine());
        return Double.parseDouble(st.nextToken());
    }
    public static String ns()throws Exception
    {
        if(!st.hasMoreElements())
            st=new StringTokenizer(br.readLine());
        return st.nextToken();
    }
}