#include <bits/stdc++.h>
using namespace std;
struct TTTT {
  TTTT *next[26];
} * root;
char s1[1616], s2[1616];
int n, k, ans, a[1616], f[1616];
void Ins(TTTT *&p, int sum, int now) {
  if (sum > k) return;
  if (p == NULL) {
    ++ans;
    p = new (TTTT);
    for (int i = 1; i <= 26; ++i) p->next[i - 1] = NULL;
  }
  if (now > n) return;
  Ins(p->next[a[now]], sum + f[a[now]], now + 1);
}
int main() {
  scanf("%s%s%d", &s1, &s2, &k);
  n = strlen(s1);
  for (int i = 1; i <= n; ++i) a[i] = (int)(s1[i - 1] - 'a');
  for (int i = 0; i <= 25; ++i) f[i] = (int)(s2[i] == '0');
  root = NULL;
  for (int i = 1; i <= n; ++i) Ins(root, 0, i);
  printf("%d\n", ans - 1);
  return 0;
}
