#include <bits/stdc++.h>
const int N = 1500 + 228;
const long long BASE = 2011;
using namespace std;
bool ok[256];
unsigned long long hsh[N];
unsigned long long f[N];
string s;
int k;
unordered_map<unsigned long long, bool> mp;
unsigned long long get_hsh(int l, int r) {
  return (hsh[r] - ((hsh[l - 1] * f[r - l + 1])));
}
int main() {
  ios_base::sync_with_stdio(false);
  f[0] = 1;
  for (int i = 1; i < N; i++) f[i] = (f[i - 1] * BASE);
  string str;
  cin >> s >> str >> k;
  s = '#' + s;
  for (int i = 1; i < (int)s.size(); i++) hsh[i] = (hsh[i - 1] * BASE + s[i]);
  for (int i = 0; i < (int)str.size(); i++)
    if (str[i] == '1') ok[i + 'a'] = true;
  int cnt;
  long long hh;
  int ans = 0;
  for (int i = 1; i < (int)s.size(); i++) {
    cnt = 0;
    for (int j = i; j < (int)s.size(); j++) {
      if (!ok[s[j]]) cnt++;
      if (cnt > k) break;
      hh = get_hsh(i, j);
      if (!mp[hh]) ans++, mp[hh] = true;
    }
  }
  cout << ans;
  return 0;
}
