#include <bits/stdc++.h>
using namespace std;
class sort_indices {
 private:
  long long *arr;

 public:
  sort_indices(long long *temp) : arr(temp) {}
  bool operator()(int i, int j) { return (arr[i] < arr[j]); }
};
long long power(long long base, long long exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % 1000000009;
    base = (base * base) % 1000000009;
    exp /= 2;
  }
  return (res % 1000000009);
}
long long distinct_substrings(char *str, int *badness, int len, int size,
                              int lim) {
  int num = len - size + 1;
  long long *hash = (long long *)calloc(num, sizeof(long long));
  long long *badness_count = (long long *)calloc(num, sizeof(long long));
  int *index = (int *)calloc(num, sizeof(int));
  long long temp_ll = 0;
  badness_count[0] = 0;
  for (int i = 0; i < size; i++) {
    temp_ll = (((temp_ll * 26) % 1000000009) + str[i]) % 1000000009;
    badness_count[0] += badness[str[i] - 'a'];
  }
  hash[0] = temp_ll;
  index[0] = 0;
  long long temp = power(26, size - 1);
  for (int i = size; i < len; i++) {
    hash[i - size + 1] =
        (hash[i - size] - (str[i - size] * temp) % 1000000009 + 1000000009) %
        1000000009;
    hash[i - size + 1] =
        ((hash[i - size + 1] * 26) % 1000000009 + str[i]) % 1000000009;
    badness_count[i - size + 1] = badness_count[i - size] -
                                  badness[str[i - size] - 'a'] +
                                  badness[str[i] - 'a'];
    index[i - size + 1] = i - size + 1;
  }
  sort(index, index + num, sort_indices(hash));
  long long ans = 0;
  if (badness_count[index[0]] <= lim) ans++;
  for (int i = 1; i < num; i++) {
    if ((hash[index[i]] != hash[index[i - 1]] ||
         badness_count[index[i]] != badness_count[index[i - 1]]) &&
        badness_count[index[i]] <= lim) {
      ans++;
    } else {
      int j = index[i], k = index[i - 1], lim2 = index[i] + size;
      while (j < lim2) {
        if (str[j] != str[k]) break;
        j++;
        k++;
      }
      if (j < lim2 && badness_count[index[i]] <= lim) {
        ans++;
      }
    }
  }
  free(hash);
  free(badness_count);
  free(index);
  return ans;
}
int main() {
  int lim;
  char str[1501], badness[27];
  int badness_i[26];
  scanf("%s%s%d", str, badness, &lim);
  for (int i = 0; i < 26; i++) {
    if (badness[i] == '0')
      badness_i[i] = 1;
    else
      badness_i[i] = 0;
  }
  int len = strlen(str);
  long long ans = 0;
  for (int i = 1; i <= len; i++) {
    ans += distinct_substrings(str, badness_i, len, i, lim);
  }
  printf("%lld\n", ans);
  return 0;
}
