#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
int main() {
  string t, t1;
  long long int k, i, j, cn, ans;
  while (cin >> t) {
    cin >> t1 >> k;
    ans = 0;
    map<string, long long int> mp;
    map<char, long long int> mp1;
    for (i = 0; i < 26; i++) {
      mp1['a' + i] = t1[i] - 48;
    }
    map<long long int, long long int> mp2;
    for (i = 0; i < t.size(); i++) {
      long long int hash1 = 0;
      cn = 0;
      for (j = i; j < t.size(); j++) {
        if (mp1[t[j]] == 0) cn++;
        if (cn > k) break;
        hash1 = hash1 * 103 + t[j];
        if (mp2[hash1] == 0) {
          ans++;
          mp2[hash1] = 1;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
