#include <bits/stdc++.h>
using namespace std;
int pref[1600];
int main() {
  string s;
  cin >> s;
  string good;
  cin >> good;
  int k;
  cin >> k;
  int ans = 0;
  const int n = s.size();
  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + (good[s[i - 1] - 'a'] == '0');
  }
  set<string> subs;
  for (int len = 1; len <= n; len++) {
    for (int i = 0; i + len <= n; i++) {
      if (pref[i + len] - pref[i] <= k) {
        subs.insert(s.substr(i, len));
      }
    }
    ans += subs.size();
    subs.clear();
  }
  cout << ans << '\n';
  return 0;
}
