#include <bits/stdc++.h>
using namespace std;
void optimizeIO() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  optimizeIO();
  string s, bin;
  cin >> s;
  cin >> bin;
  int k, len = s.size();
  cin >> k;
  vector<long long> pw(len + 1), hs(len);
  vector<long long> pw2(len + 1), hs2(len);
  const int p = 31;
  const int p2 = 43;
  pw[0] = 1;
  pw2[0] = 1;
  for (int i = 1; i < len + 1; i++) {
    pw[i] = (pw[i - 1] * p) % 1000000007;
    pw2[i] = (pw2[i - 1] * p2) % 1000000007;
  }
  hs[0] = (s[0] - 'a' + 1);
  hs2[0] = (s[0] - 'a' + 1);
  for (int i = 1; i < len; i++) {
    hs[i] = ((s[i] - 'a' + 1) * pw[i]) % 1000000007;
    hs2[i] = ((s[i] - 'a' + 1) * pw2[i]) % 1000000007;
  }
  vector<int> bad(len);
  for (int i = 0; i < len; i++) {
    bad[i] = !(bin[s[i] - 'a'] - '0');
  }
  set<pair<long long, long long> > res;
  for (int i = 0; i < len; i++) {
    int cnt = 0;
    long long sub = 0;
    long long sub2 = 0;
    if (i) sub = hs[i - 1], sub2 = hs2[i - 1];
    long long tot = 0, tot2 = 0, tt2, tt;
    int lg = 0;
    for (int j = i; j < len; j++) {
      cnt += bad[j];
      if (cnt > k) break;
      lg++;
      tot = (tot + hs[j]) % 1000000007;
      tot2 = (tot2 + hs2[j]) % 1000000007;
      tt = (tot * pw[len - j]) % 1000000007;
      tt2 = (tot2 * pw2[len - j]) % 1000000007;
      res.insert({tt, tt2});
    }
  }
  cout << res.size() << endl;
  return 0;
}
