#include <bits/stdc++.h>
using namespace std;
char s[2010], t[2010];
int dp[2010][2010];
int val[2010];
int main() {
  scanf("%s", s + 1);
  scanf("%s", t);
  int k;
  scanf("%d", &k);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    int x = s[i] - 'a';
    if (t[x] == '0')
      val[i] = 1;
    else
      val[i] = 0;
    val[i] += val[i - 1];
  }
  for (int i = n; i >= 1; i--) {
    for (int j = n; j >= 1; j--) {
      if (s[i] == s[j]) dp[i][j] = dp[i + 1][j + 1] + 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int sz = 0;
    for (int j = 1; j < i; j++) sz = max(sz, dp[i][j]);
    for (int j = i + sz; j <= n; j++) {
      if (val[j] - val[i - 1] <= k) ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}
