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*  =  *s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>...*s*<sub class="lower-index">|*s*|</sub> (where |*s*| is the length of string *s*) is string  *s*<sub class="lower-index">*l*</sub>*s*<sub class="lower-index">*l* + 1</sub>...*s*<sub class="lower-index">*r*</sub>.

The substring *s*[*l*...*r*] is good, if among the letters  *s*<sub class="lower-index">*l*</sub>, *s*<sub class="lower-index">*l* + 1</sub>, ..., *s*<sub class="lower-index">*r*</sub> 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*].
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.
import sys, os
ONLINE_JUDGE = not bool(os.environ.get("AURELIONY"))
if not ONLINE_JUDGE:
    import psutil, timeit
    process = psutil.Process(os.getpid())
    start = timeit.default_timer()
from io import BytesIO, IOBase
from math import *
import operator
from copy import *
from bisect import *
from collections import *
from itertools import *
from functools import *
from heapq import *
from array import array
from fractions import Fraction
from decimal import Decimal
from random import *
from string import *
import threading

class DSU:
    def __init__(self, sz):
        self.parent = list(range(sz))
        self.sz = [1] * sz

    def find(self, x):
        if self.parent[x] == x: return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def link(self, a, b): # b becomes an ancestor of a
        a = self.find(a)
        b = self.find(b)
        if a!=b:
            self.parent[a] = b
            self.sz[b] += self.sz[a]

    def union(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if a!=b:
            if self.sz[a] < self.sz[b]:
                self.parent[a] = b
                self.sz[b] += self.sz[a]
            else:
                self.parent[b] = a
                self.sz[a] += self.sz[b]

    def is_connected(self,a,b):
        return self.find(a) == self.find(b)

    def size(self, a):
        return self.sz[self.find(a)]

def sieve(maxprime):
    if maxprime == 1: return [0,0]
    prime = array('b', [True]) * (maxprime+1)
    prime[0] = False
    prime[1] = False
    p = 2
    prime[p] = True
    while p*p <= maxprime:
        if prime[p]:
            for e in range(p+p, maxprime+1, p):
                prime[e] = False
        p+=1
    return prime

def segmented_sieve(l, r):
    n = int(sqrt(int(r+1)))+1
    prime = sieve(n)
    isPrime = array('b', [True]) * (r-l+1)
    if l == 0:
        isPrime[0] = False
        isPrime[1] = False
    if l==1: isPrime[0] = False
    for i in range(len(prime)):
        if not prime[i]: continue
        for j in range(max(i*i, (l+i-1)//i*i), r+1, i):
            isPrime[j-l] = False
    return isPrime

TIME_LIMIT = 1
MEMORY_LIMIT = 256
FAST_INPUT = FAST_OUTPUT = 1

# MOD = 998244353
MOD = 1000000007
sys.setrecursionlimit(int(1e9))
# threading.stack_size(2**26) # USES MORE RAM

def solve():
    s = gs()
    A = gs()
    k = gi()
    subs = sorted(s[i:] for i in range(len(s)))
    prev = ''
    ans = 0
    for sub in subs:
        bad = 0
        unique = 0
        for i in range(len(sub)):
            if i+1 > len(prev) or sub[i] != prev[i]:
                # ensure uniqueness of current substring by comparing with the length and character of previous substring
                unique = 1
            if A[ord(sub[i]) - ord('a')] == '0':
                bad += 1
            if bad > k:
                break
            if unique:
                ans += 1
        prev = sub
    print(ans)

def main(t = 1):
    # t = getint()
    for i in range(t):
        solve()
    # debug(1)
 
def debug(state=0):
    if ONLINE_JUDGE:
        return
    end = timeit.default_timer()
    memory_usage = process.memory_info().rss / 1048576
    if end-start > TIME_LIMIT or memory_usage > MEMORY_LIMIT:
        if FAST_OUTPUT:
            sys.stdout.buffer.buffer.truncate(0)
            sys.stdout.buffer.buffer.seek(0)
        if end-start > TIME_LIMIT: print("TLE")
        if memory_usage > MEMORY_LIMIT: print("MLE")
        print(f"TIME: {round(end-start,2)}s")
        print(f"MEMORY: {round(memory_usage)}MB")
        sys.stdout.flush()
        exit(0)
    if state==1:
        sys.stdout.flush()
        print(f"TIME: {round(end-start,2)}s")
        print(f"MEMORY: {round(memory_usage)}MB")
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.buffer_size = 8192
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self.buffer_size))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, self.buffer_size))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
if FAST_INPUT: sys.stdin = IOWrapper(sys.stdin)
if FAST_OUTPUT: sys.stdout = IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
INF = 0x3f3f3f3f
INF64 = 0x3f3f3f3f3f3f3f3f
EPS = sys.float_info.epsilon
def gs(): return input()
def gi(): return int(input())
def gis(): return list(map(int, input().split()))
def gf(): return float(input())
def gfs(): return list(map(float, input().split()))
def impossible(): print(-1), exit(0)
def printarr(arr): print(*arr)
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
if __name__=="__main__":
    # main()
    threading.Thread(target=main).start()