#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[1502], a;
  int n, i, j, k, ans = 0, m, c;
  cin >> s[0];
  n = s[0].length();
  for (i = 1; i < n; i++) s[i] = s[i - 1].substr(1, n - i);
  sort(s, s + n);
  cin >> a;
  scanf("%d", &m);
  c = 0;
  for (j = 0; j < s[0].length(); j++) {
    c += 1 - (a[s[0][j] - 'a'] - '0');
    if (c <= m) ans++;
  }
  for (i = 1; i < n; i++) {
    k = min(s[i].length(), s[i - 1].length());
    for (j = 0; j < k; j++) {
      if (s[i][j] != s[i - 1][j]) break;
    }
    c = 0;
    for (k = 0; k < j; k++) c += 1 - (a[s[i][k] - 'a'] - '0');
    for (j; j < s[i].length(); j++) {
      c += 1 - (a[s[i][j] - 'a'] - '0');
      if (c <= m) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
