#include <bits/stdc++.h>
using namespace std;
string bad;
int k, ans = 0;
struct node {
  node *edges[26];
  node() {
    for (int i = 0; i < 26; i++) edges[i] = NULL;
  }
};
void insert(node *trie, string s) {
  for (int i = 0; i < s.size(); i++) {
    if (trie->edges[s[i] - 'a'] == NULL) trie->edges[s[i] - 'a'] = new node();
    trie = trie->edges[s[i] - 'a'];
  }
}
void dfs(node *trie, int b) {
  if (b <= k) ans++;
  for (int i = 0; i < 26; i++) {
    if (trie->edges[i]) {
      int add = 0;
      if (bad[i] == '0') add++;
      dfs(trie->edges[i], b + add);
    }
  }
}
int main() {
  string s;
  cin >> s >> bad >> k;
  node *root = new node();
  string t = "";
  for (int i = s.size() - 1; i >= 0; i--) {
    t = s[i] + t;
    insert(root, t);
  }
  dfs(root, 0);
  cout << ans - 1;
  return 0;
}
