#include <bits/stdc++.h>
using namespace std;
int Trie[2000006][28], u, i, j, k, pos, sdf, sz, t;
char s[1503], ss[1503];
string str;
int main() {
  scanf(" %s %s%d", s, ss, &k);
  u = strlen(s);
  for (i = 0; i < u; i++) {
    sdf = 0;
    str = "";
    for (j = i; j < u; j++) {
      if ((sdf += !(ss[s[j] - 'a'] - '0')) > k) break;
      str += s[j];
    }
    for (pos = j = 0; j < str.size(); j++) {
      t = str[j] - 'a' + 1;
      if (Trie[pos][t])
        pos = Trie[pos][t];
      else
        pos = Trie[pos][t] = ++sz;
    }
  }
  cout << sz;
  return 0;
}
