#include <bits/stdc++.h>
using namespace std;
void debug() {
  fflush(stdin);
  printf("Press any key to continue");
  getc(stdin);
  fflush(stdin);
}
struct Node {
  bool checked = false;
  Node* child[26];
  Node() {
    for (int i = 0; i < 26; i++) child[i] = NULL;
  }
};
string s;
string table;
int k, ans = 0;
Node* root = new Node();
void insert(int id) {
  Node* cur = root;
  for (int i = id; i < s.length(); i++) {
    if (cur->child[s[i] - 'a'] == NULL) cur->child[s[i] - 'a'] = new Node();
    cur = cur->child[s[i] - 'a'];
  }
}
void build_tree() {
  for (int i = s.length() - 1; i >= 0; i--) insert(i);
}
void traverse(int id) {
  int c = 0;
  Node* cur = root;
  for (int i = id; i < s.length(); i++) {
    cur = cur->child[s[i] - 'a'];
    if (table[s[i] - 'a'] == '0') c++;
    if (c > k) return;
    if (cur->checked == false) {
      cur->checked = true;
      ans++;
    }
  }
}
void fun() {
  for (int i = 0; i < s.length(); i++) {
    traverse(i);
  }
}
int main() {
  cin >> s;
  cin >> table;
  scanf("%d", &k);
  build_tree();
  fun();
  printf("%d\n", ans);
  return 0;
}
