#include <bits/stdc++.h>
using namespace std;
string s, b;
int k;
vector<bool> isGood(26);
struct Trie {
  Trie* next[26];
  Trie() {
    for (int i = 0; i < 26; ++i) next[i] = NULL;
  }
  void print() {
    for (int i = 0; i < 26; ++i) printf("%u ", next[i]);
    puts("");
  }
};
inline void translateGood() {
  for (int i = 0; i < b.length(); ++i) isGood[i] = b[i] == '1';
}
int main() {
  while (cin >> s >> b >> k) {
    int ans = 0;
    translateGood();
    Trie* root = new Trie;
    for (int i = 0; i < s.length(); ++i) {
      int kk = 0;
      int idx = i;
      Trie* cur = root;
      while (idx < s.length()) {
        if (!isGood[s[idx] - 'a']) {
          kk++;
          if (kk > k) break;
        }
        if (cur->next[s[idx] - 'a'] == NULL) {
          cur->next[s[idx] - 'a'] = new Trie;
          ans++;
        }
        cur = cur->next[s[idx] - 'a'];
        idx++;
      }
    }
    printf("%d\n", ans);
  }
}
