#include <bits/stdc++.h>
using namespace std;
class TrieNode {
 public:
  unordered_map<char, TrieNode *> mp;
};
bool is_good(char ch, string &bad) { return bad[ch - 'a'] == '1'; }
int cnt_good_sub(string &s, string &bad, int k) {
  TrieNode *root = new TrieNode();
  int ans = 0;
  for (int start = 0; start < s.length(); start++) {
    int cnt = 0;
    TrieNode *temp = root;
    for (int end = start; end < s.length(); end++) {
      char ch = s[end];
      if (!is_good(ch, bad)) cnt++;
      if (cnt > k) break;
      if (temp->mp.find(ch) != temp->mp.end())
        temp = temp->mp[ch];
      else {
        ans++;
        temp->mp[ch] = new TrieNode();
        temp = temp->mp[ch];
      }
    }
  }
  return ans;
}
int main() {
  string s;
  cin >> s;
  string bad;
  cin >> bad;
  int k;
  cin >> k;
  cout << cnt_good_sub(s, bad, k);
}
