#include <bits/stdc++.h>
using namespace std;
int z_func(string s) {
  int res = 0;
  vector<int> z(s.length(), 0);
  for (int i = 1, l = 0, r = 0; i < s.length(); i++) {
    if (i <= r) z[i] = min(z[i - l], r - i + 1);
    while (i + z[i] < s.length() && s[i + z[i]] == s[z[i]]) ++z[i];
    if (i + z[i] - 1 > r) {
      l = i;
      r = i + z[i] - 1;
    }
    res = max(res, z[i]);
  }
  return res;
}
int p[2000], ans;
int main() {
  string s, b;
  cin >> s >> b;
  int k;
  cin >> k;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (b[s[i] - 'a'] == '0') cnt++;
    p[i] = cnt;
  }
  string cur = "";
  for (int i = 0; i < s.size(); i++) {
    cur += s[i];
    string q = cur;
    reverse(q.begin(), q.end());
    int zmax = z_func(q);
    for (int j = 0; j <= i - zmax; j++) {
      int w = p[i];
      if (j > 0) {
        w -= p[j - 1];
      }
      if (w <= k) ans++;
    }
  }
  cout << ans;
}
