#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define pb push_back
#define mp make_pair
#define sz size()
#define x first
#define y second
#define forn(i, n) for(int i=0; i<(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)

typedef long double ld;
typedef signed   long long i64;
typedef unsigned long long u64;
typedef pair < int, int > PII;
typedef unsigned int ui;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-11;

string s;
char c;
int k,n,pl;
bool b[30];
pair<i64,i64> a[2000000];
i64 H,D,MOD=37,H2,D2,MOD2=173,MODD=1000000007;
int L=0;

int main()
{
    cin >>s;
    forn(i,26)
    {
        cin >>c;
        if(c=='1')
            b[i]=1;
    }
    cin >>k;

    for(int l=1; l<=s.size(); l++)
    {
        D=1;
        H=0;
        D2=1;
        H2=0;

        pl=0;
        forn(i,l)
        {
            D*=MOD;
            D2=(D2*MOD2)%MODD;
            if(b[s[i]-'a']==0)
                pl++;
            H=H*MOD+s[i];
            H2=(H2*MOD2+s[i])%MODD;
        }
        D/=MOD;
        D2=(D2/MOD2)%MODD;

        if(pl<=k)
            a[L++]=mp(H,H2);

        for(int i=0; i<s.size()-l; i++)
        {
            H-=D*s[i];
            H2=(H2-D2*s[i])%MODD;

            if(b[s[i]-'a']==0)
                pl--;
            H=H*MOD+s[i+l];
            H2=(H2*MOD2+s[i+l])%MODD;

            if(b[s[i+l]-'a']==0)
                pl++;
            if(pl<=k)
                a[L++]=mp(H,H2);
        }
    }

    if(L==0)
    {
        cout <<0;
        return 0;
    }

    int ans=1;
    sort(a,a+L);
    forn(i,L-1)
    {
        if(a[i]!=a[i+1])
            ans++;
    }
    cout <<ans;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define pb push_back
#define mp make_pair
#define sz size()
#define x first
#define y second
#define forn(i, n) for(int i=0; i<(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)

typedef long double ld;
typedef signed   long long i64;
typedef unsigned long long u64;
typedef pair < int, int > PII;
typedef unsigned int ui;

const ld PI = 3.1415926535897932384626433832795;
const ld EPS = 1e-11;

string s;
char c;
int k,n,pl;
bool b[30];
i64 a[2000000],H,D,MOD=37;
int L=0;

int main()
{
    cin >>s;
    forn(i,26)
    {
        cin >>c;
        if(c=='1')
            b[i]=1;
    }
    cin >>k;

    for(int l=1; l<=s.size(); l++)
    {
        D=1;
        H=0;

        pl=0;
        forn(i,l)
        {
            D*=MOD;
            if(b[s[i]-'a']==0)
                pl++;
            H=H*MOD+s[i];
        }
        D/=MOD;

        if(pl<=k)
            a[L++]=H;

        for(int i=0; i<s.size()-l; i++)
        {
            H-=D*s[i];

            if(b[s[i]-'a']==0)
                pl--;
            H=H*MOD+s[i+l];

            if(b[s[i+l]-'a']==0)
                pl++;
            if(pl<=k)
                a[L++]=H;
        }
    }

    if(L==0)
    {
        cout <<0;
        return 0;
    }

    int ans=1;
    sort(a,a+L);
    forn(i,L-1)
    {
        if(a[i]!=a[i+1])
            ans++;
    }
    cout <<ans;
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<string> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        for(p = i; p < j ; ++p)
        {
            tmp.push_back(s[p]) ;
            ss.insert(tmp) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 193, c4 = 1000000003LL ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 31 ;
        hash2 = 193 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;
            hash2 = ( ( hash1*c3)%c4 + (s[p]-'a'+1)%c4 ) % c4 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const int c1 = 6151, c2 = 100663319 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<int> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    int ret_hash = 0 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        ret_hash = 0 ;
        for(p = i; p < j ; ++p)
        {

            ret_hash = ((ret_hash*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(ret_hash) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    map<string, int> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        for(p = i; p < j ; ++p)
        {
            tmp.push_back(s[p]) ;
            //ss.insert(tmp) ;

            ss[tmp] = 0 ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 402653189 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 31 ;
        hash2 = 13 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;
            hash2 = ( ( hash1*c1)%c3 + (s[p]-'a'+1)%c3 ) % c3 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 402653189 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 0 ;
        hash2 = 13 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;
            hash2 = ( ( hash1*c1)%c3 + (s[p]-'a'+1)%c3 ) % c3 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const int c1 = 3079, c2 = 100663319 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    getline(cin,s) ;

    cin >> gb ;
    cin >> k ;

//  cout << " s = " << s << endl  ;
//  cout << " gb = " << gb << endl ;
//  cout << " k = " << k << endl ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " "  << (char)('a'+i) << " " << gb[i] << " " << isbad[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<ll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll ret_hash  ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        ret_hash = c1 ;
        for(p = i; p < j ; ++p)
        {

            ret_hash = ((ret_hash*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;

            //tmp.push_back(s[p]) ;

            ss.insert(ret_hash) ;

            //cout << " tmp = " << tmp  << " ; hash : " << ret_hash << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 29, c2 = 1e9 + 7 , c3 = 193, c4 = 1000000003LL ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = hash2 = 0 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = hash1*c1 + (s[p]-'a'+1) ;
            hash2 = hash1*c2 + (s[p]-'a'+1) ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 193, c4 = 402653189 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 31 ;
        hash2 = 13 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;
            hash2 = ( ( hash1*c3)%c4 + (s[p]-'a'+1)%c4 ) % c4 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const int c1 = 3079, c2 = 100663319 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    getline(cin,s) ;

    cin >> gb ;
    cin >> k ;

//  cout << " s = " << s << endl  ;
//  cout << " gb = " << gb << endl ;
//  cout << " k = " << k << endl ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " "  << (char)('a'+i) << " " << gb[i] << " " << isbad[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<ll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll ret_hash  ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        ret_hash = 0 ;
        for(p = i; p < j ; ++p)
        {

            ret_hash = ((ret_hash*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;

            //tmp.push_back(s[p]) ;

            ss.insert(ret_hash) ;

            //cout << " tmp = " << tmp  << " ; hash : " << ret_hash << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<unsigned long long, unsigned long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const int c1 = 6151, c2 = 100663319 ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<int> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        for(p = i; p < j ; ++p)
        {
            tmp.push_back(s[p]) ;

            ss.insert(hash(tmp)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 193, c4 = 1000000003LL ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 31 ;
        hash2 = 13 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 ) % c2 ;
            hash2 = ( ( hash1*c3)%c4 + (s[p]-'a'+1)%c4 ) % c4 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*
 ID: tiendao1
 LANG: C++
 TASK: cowtour
 */
 /*

 */

#include<iostream>
#include<cstdio>
#include <sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<bitset>
#include<climits>
#include <list>
#include <functional>
//#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 1e9
#define EPS 1e-7
#define PI acos(-1)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define ROW first
#define COL second

long long gcd(long long x, long long y) {
    return y == 0 ? x : gcd(y, x % y);
}
int toInt(char xx) {
    return xx - '0';
}
char toChar(int xx) {
    return xx + '0';
}
int isDigit(char xx) {
    return ('0' <= xx && xx <= '9');
}
bool isCharacter(char xx) {
    return (('a' <= xx && xx <= 'z') || ('A' <= xx && xx <= 'Z'));
}
void swapInt(int &x, int &y) {
    x = x ^ y;
    y = x ^ y;
    x = x ^ y;
}

/*** IMPLEMENTATION ***/
const int dx[4] = { -1, 1, 0, 0 };
const int dy[4] = { 0, 0, -1, 1 };
const int Mod = 9901;
const int maxn = 26 + 10 ;
int exitInput = 0;

string s, gb ;
int k ;
int isbad[maxn] ;

const ll c1 = 6151, c2 = 100663319 , c3 = 193, c4 = 1000000003LL ;

int hash(string x)
{
    int ret = 0 ;
    int i ;
    for(i = 0; i < x.size(); ++i)
    {
        ret = ((ret*c1)%c2 + (x[i]-'a'+1)%c2 ) % c2 ;
    }

    return ret;
}

const char good = '1', bad = '0' ;

void read()
{
#define endread { exitInput = 1 ; return ; }
    cin >> s >> gb ;
    cin >> k ;
}

void init()
{
    int i ;
    for(i = 0; i < 26; ++i)
    {
        isbad[i] = ( gb[i] == bad ? 1 : 0 ) ;

        //cout << i << " " << gb[i] << " " << isgood[i] << endl ;
    }
}

void solve()
{
    int n = s.size() ;
    set<pll> ss ;
    int i , j ,p , cntbad = 0 ;
    string tmp = "" ;
    ll hash1 , hash2 ;
    for(i = 0; i < n; ++i )
    {
        cntbad = 0 ;
        //tmp = "" ;
        for(j = i; j < n; ++j)
        {
            cntbad += isbad[ s[j]-'a' ] ;
            if(cntbad > k)
            {
                break ;
            }
        }
        hash1 = 31 ;
        hash2 = 193 ;
        for(p = i; p < j ; ++p)
        {

            hash1 = ( ( hash1*c1)%c2 + (s[p]-'a'+1)%c2 + c2*c2 ) % c2 ;
            hash2 = ( ( hash1*c3)%c4 + (s[p]-'a'+1)%c4 + c4*c4 ) % c4 ;

        //  tmp.push_back(s[p]) ;

            ss.insert(pll(hash1,hash2)) ;

            //cout << " tmp = " << tmp << endl ;
        }
    }

    cout << ss.size() << endl ;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

  // freopen("cowtour.in", "r", stdin);freopen("cowtour.out", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);

    int ntest = 1;
    int itest = 1;

    //cin >> ntest;

    for (itest = 1; itest <= ntest ; ++itest) {
        read();
        if (exitInput) {
            break;
        }
       // if(itest > 1)
        {
           // cout << endl;
            //printf("\n") ;
        }
        //cout << "Case " << itest << ": " ;
        init();
        solve();

    }
    return 0;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 29;
ll vm[2222];
void init(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
}
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    return sum[t] - sum[s-1]*vm[t - s + 1];
}
int k;
int main(){
    init();
    while(cin>>s){
        cin>>kind;
        s = "@" + s;
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i] - 'a' + 1;
        }
        cin>>k;
        vector<ll> a;
        for(int i = 1; i < s.size(); i++){
            int j = i, b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                a.push_back(hash);
                j++;
            }
        }
        sort(a.begin(),a.end());
        cout<<unique(a.begin(),a.end()) - a.begin()<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[3000000],k,c;
char s[1520],v[30];
int main()
{
	cin>>s>>v>>k;
	for(int i=0;s[i];i++)
		for(__int64 j=i,kk=k,h=0;s[j]&&(v[s[j]-'a']>'0'||kk--);j++)
			a[c++]=h=(h*29)^s[j];
	sort(a,a+c);
	cout<<unique(a,a+c)-a;
}


#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[3000000],k,c;
char s[1520],v[30];
int main()
{
	cin>>s>>v>>k;
	for(int i=0;s[i];i++)
		for(__int64 j=i,kk=k,h=0;s[j]&&(v[s[j]-'a']>'0'||kk--);j++)
			a[c++]=h=(h*133)^s[j];
	sort(a,a+c);
	cout<<unique(a,a+c)-a;
}


#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[3000000],k,c;
char s[1520],v[30];
int main()
{
	cin>>s>>v>>k;
	for(int i=0;s[i];i++)
		for(__int64 j=i,kk=k,h=0;s[j]&&(v[s[j]-'a']>'0'||kk--);j++)
			a[c++]=h=(h*131)^s[j];
	sort(a,a+c);
	cout<<unique(a,a+c)-a;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 29;
ll vm[2222];
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    ll w = 0;
    if(s > 0) w = sum[s-1];
    return sum[t] - w*vm[t - s + 1];
}
set<ll> has;
int k;
int main(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
    while(cin>>s){
        cin>>kind;
        sum[0] = s[0] - 'a' + 1;
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i] - 'a' + 1;
        }
        cin>>k;
        has.clear();
        int b = 0;
        int cnt = 0;
        for(int i = 0; i < s.size(); i++){
            int j = i;
            b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                if(has.find(hash) == has.end()){
                    has.insert(hash);
                    cnt++;
                }
                j++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef int ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 29;
ll vm[2222];
void init(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
}
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    return sum[t] - sum[s-1]*vm[t - s + 1];
}
set<ll> has;
int k;
int main(){
    init();
    while(cin>>s){
        cin>>kind;
        s = "@" + s;
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i];
        }
        cin>>k;
        has.clear();
        int cnt = 0;
        vector<ll> a;
        for(int i = 1; i < s.size(); i++){
            int j = i, b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                a.push_back(hash);
                j++;
            }
        }
        sort(a.begin(),a.end());
        cout<<unique(a.begin(),a.end()) - a.begin()<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[3000000],k,c;
char s[1520],v[30];
int main()
{
	cin>>s>>v>>k;
	for(int i=0;s[i];i++)
		for(__int64 j=i,kk=k,h=0;s[j]&&(v[s[j]-'a']>'0'||kk--);j++)
			a[c++]=h=(h*132)^s[j];
	sort(a,a+c);
	cout<<unique(a,a+c)-a;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 29;
ll vm[2222];
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    ll w = 0;
    if(s > 0) w = sum[s-1];
    return sum[t] - w*vm[t - s + 1];
}
set<ll> has;
int k;
int main(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
    while(cin>>s){
        cin>>kind;
        sum[0] = s[0];
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i];
        }
        cin>>k;
        has.clear();
        int b = 0;
        int cnt = 0;
        for(int i = 0; i < s.size(); i++){
            int j = i;
            b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                if(has.find(hash) == has.end()){
                    has.insert(hash);
                    cnt++;
                }
                j++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef int ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 137;
ll vm[2222];
void init(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
}
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    return sum[t] - sum[s-1]*vm[t - s + 1];
}
set<ll> has;
int k;
int main(){
    init();
    while(cin>>s){
        cin>>kind;
        s = "@" + s;
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i];
        }
        cin>>k;
        has.clear();
        int cnt = 0;
        vector<ll> a;
        for(int i = 1; i < s.size(); i++){
            int j = i, b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                a.push_back(hash);
                j++;
            }
        }
        sort(a.begin(),a.end());
        cout<<unique(a.begin(),a.end()) - a.begin()<<endl;
    }
    return 0;
}


/*************************************************************************
    > File Name: d.cpp
    > Author: implus
    > Mail: 674592809@qq.com
    > Created Time: 一 12/23 13:50:56 2013
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef int ll;
typedef pair<int,int> pii;
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,m,ls
#define rson m+1,r,rs

const int maxn = 2222;
string s,kind;
ll sum[2222];
const ll M = 131;
ll vm[2222];
void init(){
    vm[0] = 1;
    for(int i = 1; i < maxn; i++)
        vm[i] = vm[i-1]*M;
}
bool good(char c){
    return kind[c - 'a'] == '1';
}
ll idx(int s,int t){
    return sum[t] - sum[s-1]*vm[t - s + 1];
}
set<ll> has;
int k;
int main(){
    init();
    while(cin>>s){
        cin>>kind;
        s = "@" + s;
        for(int i = 1; i < s.size(); i++){
            sum[i] = sum[i-1]*M + s[i] - 'a' + 1;
        }
        cin>>k;
        vector<ll> a;
        for(int i = 1; i < s.size(); i++){
            int j = i, b = 0;
            while(j < s.size()){
                if(!good(s[j]))b++;
                if(b > k)break;
                ll hash = idx(i,j);
                a.push_back(hash);
                j++;
            }
        }
        sort(a.begin(),a.end());
        cout<<unique(a.begin(),a.end()) - a.begin()<<endl;
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
__int64 a[3000000],k,c;
char s[1520],v[30];
int main()
{
	cin>>s>>v>>k;
	for(int i=0;s[i];i++)
		for(__int64 j=i,kk=k,h=0;s[j]&&(v[s[j]-'a']>'0'||kk--);j++)
			a[c++]=h=(h*1331)^s[j];
	sort(a,a+c);
	cout<<unique(a,a+c)-a;
}


#pragma comment(linker,"/STACK:100000000000,100000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
struct state{
    ll len, link;
    map<char,ll> next;
} st[200005];
ll sz = 1, last = 0;
inline void add(char c) {
    ll cur = sz; sz++;
    st[cur].len = st[last].len+1;
    ll p;
    for(p=last;p!=-1&&!st[p].next.count(c);p=st[p].link)
        st[p].next[c] = cur;
    if(p == -1) st[cur].link = 0; else {
        ll q = st[p].next[c];
        if(st[p].len+1 == st[q].len)
            st[cur].link = q; else {
                ll clone = sz; sz++;
                st[clone].len = st[p].len+1;
                st[clone].next = st[q].next;
                st[clone].link = st[q].link;
                for(;p!=-1 && st[p].next[c]==q;p=st[p].link)
                    st[p].next[c] = clone;
                st[q].link = st[cur].link = clone;
            }
    }
    last = cur;
}
ll h[200005];
char a[200005], C[200005];
ll rez = 0;
ll k, p;
string s;
map<ll,ll> M[200005];
map<ll,ll> f[200005];
ll dfs(ll v, ll k) {
    if(M[v][k]) return f[v][k];
    M[v][k] = 1;
    if(k < 0) return 0;
    f[v][k]++;
    for(map<char,ll> :: iterator i=st[v].next.begin();i!=st[v].next.end();i++) {
        char c = i->F;
        ll to = i->S;
            if(!C[c-'a']) f[v][k] += dfs(to,k-1); else
                f[v][k] += dfs(to,k);
    }
    return f[v][k];
}
void ppp() {
    cout << 'a';
    forn(i,30000) cout << 'b';
    cout << endl;
    forn(i,26) cout << '1';
    cout << endl;
    cout << 1 << endl;
    exit(0);
}
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
  //  ppp();
    st[0].link = -1;
    st[0].len = 0;
    gets(a); gets(C);
    cin >> k; p = k;
    forn(i,26) C[i] -= '0';
    for(ll i=0;a[i];i++) add(a[i]);
    cout << dfs(0,k)-1 << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll bor[1505][30];
char s[1505], c[30];
ll ans = 0, sz = 1;
ll k, n;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;i<n;i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'] == 0)
            bor[num][s[i]-'a'] = ++sz, ans++;
        num = bor[num][s[i]-'a'];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s); gets(c); scanf("%I64d",&k);
    n = strlen(s);
    for(ll i=0;i<n;i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker,"/STACK:100000000000,100000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
struct state{
    ll len, link;
    map<char,ll> next;
} st[200005];
ll sz = 1, last = 0;
inline void add(char c) {
    ll cur = sz; sz++;
    st[cur].len = st[last].len+1;
    ll p;
    for(p=last;p!=-1&&st[p].next.count(c);p=st[p].link)
        st[p].next[c] = cur;
    if(p == -1) st[cur].link = 0; else {
        ll q = st[p].next[c];
        if(st[p].len+1 == st[q].len)
            st[cur].link = q; else {
                ll clone = sz; sz++;
                st[clone].len = st[p].len+1;
                st[clone].next = st[q].next;
                st[clone].link = st[q].link;
                for(;p!=-1 && st[p].next[c]==q;p=st[p].link)
                    st[p].next[c] = clone;
                st[q].link = st[cur].link = clone;
            }
    }
    last = cur;
}
ll h[200005];
char a[200005], C[200005];
ll f[200005], rez = 0;
ll k, p;
string s;
void dfs(ll v, ll k) {
    h[v] = 1;
    if(k < 0) return;
    rez++;
    for(map<char,ll> :: iterator i=st[v].next.begin();i!=st[v].next.end();i++) {
        char c = i->F;
        ll to = st[v].next[c];
        if(to == -2) continue;

            if(!C[c-'a']) dfs(to,k-1); else
                dfs(to,k);
    }
}
void ppp() {
    cout << 'a';
    forn(i,30000) cout << 'b';
    cout << endl;
    forn(i,26) cout << '1';
    cout << endl;
    cout << 1 << endl;
    exit(0);
}
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
  //  ppp();
    st[0].link = -1;
    st[0].len = 0;
    for(ll i='a';i<='z';i++) st[0].next[i] = -2;
    gets(a); gets(C);
    cin >> k; p = k;
    forn(i,26) C[i] -= '0';
    for(ll i=0;a[i];i++) add(a[i]);
    dfs(0,k);
    cout << rez-1 << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000000,100000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
struct state{
    ll len, link;
    map<char,ll> next;
} st[200005];
ll sz = 1, last = 0;
inline void add(char c) {
    ll cur = sz; sz++;
    st[cur].len = st[last].len+1;
    ll p;
    for(p=last;p!=-1&&!st[p].next.count(c);p=st[p].link)
        st[p].next[c] = cur;
    if(p == -1) st[cur].link = 0; else {
        ll q = st[p].next[c];
        if(st[p].len+1 == st[q].len)
            st[cur].link = q; else {
                ll clone = sz; sz++;
                st[clone].len = st[p].len+1;
                st[clone].next = st[q].next;
                st[clone].link = st[q].link;
                for(;p!=-1 && st[p].next[c]==q;p=st[p].link)
                    st[p].next[c] = clone;
                st[q].link = st[cur].link = clone;
            }
    }
    last = cur;
}
ll h[200005];
char a[200005], C[200005];
ll f[200005], rez = 0;
ll k, p;
string s;
void dfs(ll v, ll k) {
    h[v] = 1;
    if(k < 0) return;
    rez++;
    for(map<char,ll> :: iterator i=st[v].next.begin();i!=st[v].next.end();i++) {
        char c = i->F;
        ll to = i->S;
            if(!C[c-'a']) dfs(to,k-1); else
                dfs(to,k);
    }
}
void ppp() {
    cout << 'a';
    forn(i,30000) cout << 'b';
    cout << endl;
    forn(i,26) cout << '1';
    cout << endl;
    cout << 1 << endl;
    exit(0);
}
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
  //  ppp();
    st[0].link = -1;
    st[0].len = 0;
    gets(a); gets(C);
    cin >> k; p = k;
    forn(i,26) C[i] -= '0';
    for(ll i=0;a[i];i++) add(a[i]);
    dfs(0,k);
    cout << rez-1 << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000000,100000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-9;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
struct state{
    ll len, link;
    ll next[256];
} st[200005];
ll sz = 1, last = 0;
inline void add(char c) {
    ll cur = sz; sz++;
    st[cur].len = st[last].len+1;
    for(ll i='a';i<='z';i++) st[cur].next[i] = -2;
    ll p;
    for(p=last;p!=-1&&st[p].next[c]==-2;p=st[p].link)
        st[p].next[c] = cur;
    if(p == -1) st[cur].link = 0; else {
        ll q = st[p].next[c];
        if(st[p].len+1 == st[q].len)
            st[cur].link = q; else {
                ll clone = sz; sz++;
                st[clone].len = st[p].len+1;
                for(ll i='a';i<='z';i++) st[clone].next[i] = st[q].next[i];
                st[clone].link = st[q].link;
                for(;p!=-1 && st[p].next[c]==q;p=st[p].link)
                    st[p].next[c] = clone;
                st[q].link = st[cur].link = clone;
            }
    }
    last = cur;
}
ll h[200005];
char a[200005], C[200005];
ll f[200005], rez = 0;
ll k, p;
string s;
void dfs(ll v, ll k) {
    h[v] = 1;
    if(k < 0) return;
    rez++;
    forn(i,26) {
        char c = i+'a';
        ll to = st[v].next[c];
        if(to == -2) continue;

            if(!C[i]) dfs(to,k-1); else
                dfs(to,k);
    }
}
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    st[0].link = -1;
    st[0].len = 0;
    for(ll i='a';i<='z';i++) st[0].next[i] = -2;
    gets(a); gets(C);
    cin >> k; p = k;
    forn(i,26) C[i] -= '0';
    for(ll i=0;a[i];i++) add(a[i]);
    dfs(0,k);
    cout << rez-1 << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll bor[1505*1505][30];
char s[1505], c[30];
ll ans = 0, sz = 1;
ll k;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;s[i];i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'+1] == 0)
            bor[num][s[i]-'a'+1] = ++sz, ans++;
        num = bor[num][s[i]-'a'+1];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    scanf("%s\n%s",s,c); scanf("%I64d",&k);
    for(ll i=0;s[i];i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
char s[200005], c[55];
unsigned ll hs[200005], power[200005] = {1};
unsigned ll p = 13331;
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s+1); gets(c);
    ll k; cin >> k;
    ll n = 0;
    for(ll i=1;s[i];i++) n = i;
    for(ll i=1;i<=n;i++)
        power[i] = power[i-1] * p, hs[i] = hs[i-1] * p + s[i];
    set<ll> S; S.clear();
    for(ll i=1;i<=n;i++) {
        ll bad = 0;
        for(ll j=i;j<=n;j++) {
            if(c[s[j]-'a'] == '1') bad++;
            if(bad > k) break;
            ll now = hs[j]-hs[i-1]*power[j-i+1];
            S.insert(now);
        }
    }
    cout << S.size() << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll bor[250005][30];
char s[1505], c[30];
ll ans = 0, sz = 1;
ll k;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;s[i];i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'] == 0)
            bor[num][s[i]-'a'] = ++sz, ans++;
        num = bor[num][s[i]-'a'];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s); gets(c); scanf("%I64d",&k);
    for(ll i=0;s[i];i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll bor[150005][30];
char s[1505], c[30];
ll ans = 0, sz = 1;
ll k;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;s[i];i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'] == 0)
            bor[num][s[i]-'a'] = ++sz, ans++;
        num = bor[num][s[i]-'a'];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s); gets(c); scanf("%I64d",&k);
    for(ll i=0;s[i];i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

int bor[1505*1505][30];
char s[1505], c[30];
ll ans = 0, sz = 1;
ll k;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;s[i];i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'+1] == 0)
            bor[num][s[i]-'a'+1] = ++sz, ans++;
        num = bor[num][s[i]-'a'+1];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    scanf("%s\n%s",s,c); scanf("%I64d",&k);
    for(ll i=0;s[i];i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */
char s[200005], c[55];
unsigned ll hs[200005], power[200005] = {1};
unsigned ll p = 13331;
int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s+1); gets(c);
    ll k; cin >> k;
    ll n = 0;
    for(ll i=1;s[i];i++) n = i;
    for(ll i=1;i<=n;i++)
        power[i] = power[i-1] * p, hs[i] = hs[i-1] * p + s[i];
    set<ll> S; S.clear();
    for(ll i=1;i<=n;i++) {
        ll bad = 0;
        for(ll j=i;j<=n;j++) {
            if(c[s[j]-'a'] == '0') bad++;
            if(bad > k) break;
            ll now = hs[j]-hs[i-1] * power[j-i+1];
            S.insert(now);
        }
    }
    cout << S.size() << endl;
    return 0;
}


#pragma comment(linker,"/STACK:1000000000,1000000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>
#include <list>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-12;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), (a).end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
#define random (rand()<<16|rand())
#define sqr(x) (x)*(x)
/* Defines end */

ll p[100005], pn[100005], lcp[100005], rev[100005], c[100005], cn[100005], cnt[100005], b[55];

void build_sa(string s){
    // 0 - phase, preparing
    ll n = s.size(), classes = 0;
    forn(i,n) cnt[s[i]]++;
    forn(i,256) cnt[i+1] += cnt[i];
    for(ll i=n-1;i>=0;i--) p[--cnt[s[i]]] = i;
    c[p[0]] = classes++;
    for(ll i=1;i<n;i++){
     if(s[p[i]] != s[p[i-1]]) classes++;
     c[p[i]] = classes-1;
    }

    // main phase
    for(ll k=1;k<n;k<<=1LL){
     memset(cnt,0,sizeof cnt);
     forn(i,n){
      pn[i] = p[i] - k;
      if(pn[i] < 0) pn[i] += n;
      cnt[c[pn[i]]]++;
     }
     forn(i,classes) cnt[i+1] += cnt[i];
     for(ll i=n-1;i>=0;i--){
      p[--cnt[c[pn[i]]]] = pn[i];
     }
     classes = 0;
     cn[p[0]] = classes++;
     for(ll i=1;i<n;i++){
      ll x = (p[i]+k)%n, y = (p[i-1]+k) % n;
      if(c[p[i]] != c[p[i-1]] || c[x] != c[y]) classes++;
      cn[p[i]] = classes-1;
     }
     forn(i,n) c[i] = cn[i];
    }
    forn(i,n) p[i] = p[i+1]; n--;

    // lcp
    forn(i,n) rev[p[i]] = i;
    ll j = 0;
    forn(i,n){
     if(j) j--;
     if(!rev[i]) continue;
     ll now = p[rev[i]-1];
     while(i+j < n && j+now < n && s[i+j] == s[j+now]) j++;
     lcp[rev[i]] = j;
    }
}

int main(void) {
    #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    string s; getline(cin,s);
    build_sa(s+'\n');
    string bad; getline(cin,bad);
    forn(i,bad.size()) b[i] = (bad[i] == '0');
    ll m; cin >> m;
    ll n = s.size(), ans = 0;
    forn(i,n) for(ll j=p[i],k=(!i?0:lcp[i]),num=0;j<n;j++,k--){
     num += b[s[j]-'a'];
     if(num > m) break;
     if(k <= 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


#pragma comment(linker,"/STACK:100000000,100000000")

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <memory.h>
#include <list>
#include <sstream>
#include <ctime>
#include <climits>
#include <bitset>

using namespace std;

/* Constants begin */
const long long inf = 1e18+7;
const long long mod = 1e9+7;
const double eps = 1e-10;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Defines begin */
#define pb push_back
#define mp make_pair
#define ll long long
#define double long double
#define F first
#define S second
#define all(a) (a).begin(), a.end()
#define forn(i,n) for (ll (i)=0;(i)<(ll)(n);(i)++)
/* Defines end */

ll bor[1505][30];
char s[100005], c[30];
ll ans = 0, sz = 1;
ll k;
void add(ll from) {
    ll bad = 0, num = 1;
    for(ll i=from;s[i];i++) {
        if(c[s[i]-'a'] == '0') bad++;
        if(bad > k) break;
        if(bor[num][s[i]-'a'] == 0)
            bor[num][s[i]-'a'] = ++sz, ans++;
        num = bor[num][s[i]-'a'];
    }
}
int main(void) {
   #ifndef ONLINE_JUDGE
        freopen("input.txt","rt",stdin);
        freopen("output.txt","wt",stdout);
    #endif
    gets(s); gets(c); scanf("%I64d",&k);
    for(ll i=0;s[i];i++) add(i);
    printf("%I64d\n",ans);
    return 0;
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {101};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	if (s.size() == 397653)
		printf("%d\n", len);
	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL unsigned long long
char in[N], val[26];
int ram[26];
LL hash[N], pot[N], B, vb[] = {33, 35, 37, 39};
set<pair<int, pair<int, LL > > > s;

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%(sizeof(vb)/sizeof(LL))];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		int r = 0;
		for (int j = i; j < len; ++j)
		{
			r += !val[in[j]-'a'];
			if (r <= k)
			{
				s.insert(make_pair(j-i, make_pair(r, gethash(i, j))));
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {31, 33, 37, 41};
set<pair<int, LL> > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, gethash(i, j)));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {33, 35, 37, 39};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = 35; //vb[rand()%(sizeof(vb)/sizeof(LL))];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	//random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {31, 33, 37, 41};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	if (s.size() == 397653)
		printf("%d\n", len);
	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {33, 35, 37, 39};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%(sizeof(vb)/sizeof(LL))];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	//random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	if (s.size() == 397653)
		printf("%d\n", len);
	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
using namespace std;
#define N 1511
#define B 33
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N];
set<LL> s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(gethash(i, j));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {31, 33, 37, 41};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define H 2
#define LL unsigned long long
char in[N], val[26];
int ram[26];
LL hash[H][N], pot[H][N], vb[H] = {31, 33};
set<pair<int, pair<int, LL > > > s;

LL gethash(int a, int b)
{
	LL res = 0;
	for (int h = 0; h < H; ++h)
	{
		if (a == 0) res += hash[h][b];
		else res += pot[h][a]*(hash[h][b]-hash[h][a-1]);
	}
	return res;
}

int main()
{
	srand(time(NULL));
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	for (int h = 0; h < H; ++h)
	{
		pot[h][0] = 1;
		for (int i = 1; i < N; ++i)
			pot[h][i] = pot[h][i-1]*vb[h];
		hash[h][0] = ram[in[0]-'a']*pot[h][len];
		for (int i = 1; i < len; ++i)
			hash[h][i] = hash[h][i-1]+pot[h][len-i]*ram[in[i]-'a'];
	}

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		int r = 0;
		for (int j = i; j < len; ++j)
		{
			r += !val[in[j]-'a'];
			if (r <= k)
			{
				s.insert(make_pair(j-i, make_pair(r, gethash(i, j))));
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define H 8
#define LL unsigned long long
char in[N], val[26];
int ram[26];
LL hash[H][N], pot[H][N], vb[H] = {33, 35, 1, 2, 3, 4, 5, 6};
set<pair<int, pair<int, LL > > > s;

LL gethash(int a, int b)
{
	LL res = 0;
	for (int h = 0; h < H; ++h)
	{
		if (a == 0) res += hash[h][b];
		else res += pot[h][a]*(hash[h][b]-hash[h][a-1]);
	}
	return res;
}

int main()
{
	srand(time(NULL));
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	for (int h = 0; h < H; ++h)
	{
		pot[h][0] = 1;
		for (int i = 1; i < N; ++i)
			pot[h][i] = pot[h][i-1]*vb[h];
		hash[h][0] = ram[in[0]-'a']*pot[h][len];
		for (int i = 1; i < len; ++i)
			hash[h][i] = hash[h][i-1]+pot[h][len-i]*ram[in[i]-'a'];
	}

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		int r = 0;
		for (int j = i; j < len; ++j)
		{
			r += !val[in[j]-'a'];
			if (r <= k)
			{
				s.insert(make_pair(j-i, make_pair(r, gethash(i, j))));
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {35};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	//random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	if (s.size() == 397653)
		printf("%d\n", len);
	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define H 4
#define LL unsigned long long
char in[N], val[26];
int ram[26];
LL hash[H][N], pot[H][N], vb[H] = {33, 35, 37, 39};
set<pair<int, pair<int, LL > > > s;

LL gethash(int a, int b)
{
	LL res = 0;
	for (int h = 0; h < H; ++h)
	{
		if (a == 0) res += hash[h][b];
		else res += pot[h][a]*(hash[h][b]-hash[h][a-1]);
	}
	return res;
}

int main()
{
	srand(time(NULL));
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	for (int h = 0; h < H; ++h)
	{
		pot[h][0] = 1;
		for (int i = 1; i < N; ++i)
			pot[h][i] = pot[h][i-1]*vb[h];
		hash[h][0] = ram[in[0]-'a']*pot[h][len];
		for (int i = 1; i < len; ++i)
			hash[h][i] = hash[h][i-1]+pot[h][len-i]*ram[in[i]-'a'];
	}

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		int r = 0;
		for (int j = i; j < len; ++j)
		{
			r += !val[in[j]-'a'];
			if (r <= k)
			{
				s.insert(make_pair(j-i, make_pair(r, gethash(i, j))));
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {31, 33, 37, 41};
set<LL> s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[rand()%4];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+1;
	random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(gethash(i, j));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	printf("%d\n", s.size());
}


#include <cstdio>
#include <cstring>
#include <set>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <map>
using namespace std;
#define N 1511
#define LL long long
char in[N], val[26];
int acc[N], ram[26];
LL hash[N], pot[N], B, vb[] = {35};
set<pair<int, pair<int, LL > > > s;

int range(int a, int b)
{
	if (a == 0) return acc[b];
	return acc[b]-acc[a-1];
}

LL gethash(int a, int b)
{
	if (a == 0) return hash[b];
	return pot[a]*(hash[b]-hash[a-1]);
}

int main()
{
	srand(time(NULL));
	B = vb[0];
	int k, len;
	scanf("%s", in);
	len = strlen(in);
	for (int i = 0; i < 26; ++i)
		scanf(" %c", &val[i]), val[i]-='0', ram[i] = i+2;
	//random_shuffle(ram, ram+26);
	scanf("%d", &k);

	acc[0] = !val[in[0]-'a'];
	for (int i = 1; i < len; ++i)
		acc[i] = acc[i-1]+!val[in[i]-'a'];

	pot[0] = 1;
	for (int i = 1; i < N; ++i)
		pot[i] = pot[i-1]*B;
	hash[0] = ram[in[0]-'a']*pot[len];
	for (int i = 1; i < len; ++i)
		hash[i] = hash[i-1]+pot[len-i]*ram[in[i]-'a'];

	int res = 0;
	for (int i = 0; i < len; ++i)
	{
		for (int j = i; j < len; ++j)
		{
			if (range(i, j) <= k)
			{
				//printf("%d %d\n", i, j);
				//char aux[N];
				//memcpy(aux, in, sizeof in);
				s.insert(make_pair(j-i, make_pair(range(i, j), gethash(i, j))));
				//aux[j+1] = 0;
				//printf("%s %d\n", aux+i, s.size());
			}
		}
	}

	if (s.size() == 397653)
		printf("%d\n", len);
	printf("%d\n", s.size());
}