#include <bits/stdc++.h>
using namespace std;
struct tree {
  string str;
  int val;
  struct tree *child[26];
  tree() {
    str = "";
    val = 0;
    for (int i = 0; i < 26; i++) child[i] = NULL;
  }
};
string a, b, temp;
int k, ans = 0;
void insert(tree *head, int size) {
  for (int i = 0; i < size; i++) {
    if (head->child[temp[i] - 'a'] == NULL) {
      head->child[temp[i] - 'a'] = new tree;
      head->str += temp[i];
      head->child[temp[i] - 'a']->val = (b[temp[i] - 'a']) == '1' ? 0 : 1;
    }
    head = head->child[temp[i] - 'a'];
  }
}
void dfs(tree *head, int val) {
  val += head->val;
  if (val > k) return;
  ans++;
  for (int i = 0; i < head->str.length(); i++)
    dfs(head->child[head->str[i] - 'a'], val);
}
int main() {
  int count = 1;
  cin >> a >> b;
  cin >> k;
  tree *head = new tree;
  for (int i = a.length() - 1; i >= 0; i--) {
    temp = a.substr(i, count++);
    insert(head, count - 1);
  }
  for (int i = 0; i < head->str.length(); i++)
    dfs(head->child[head->str[i] - 'a'], 0);
  printf("%d\n", ans);
}
