#include <bits/stdc++.h>
using namespace std;
template <class T>
T cdiv(T num, T den) {
  return (num / den) + (num % den > 0);
}
template <typename TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class t>
t mag(t a) {
  return a > 0 ? a : -a;
}
int tc = 1;
string s, c;
int k, n, trie[2250002][26], num, v, cnt, ans;
int escape() {
  cin >> s >> c >> k;
  n = s.size();
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n))) {
    v = 0;
    cnt = 0;
    for (__typeof(n) j = (i) - ((i) > (n)); j != (n) - ((i) > (n));
         j += 1 - 2 * ((i) > (n))) {
      cnt += c[s[j] - 'a'] == '0';
      if (cnt > k) break;
      if (trie[v][s[j] - 'a'] == 0) {
        ans++;
        trie[v][s[j] - 'a'] = ++num;
      }
      v = trie[v][s[j] - 'a'];
    }
  }
  cout << ans;
  return 0;
}
int main() {
  cout.precision(std::numeric_limits<double>::max_digits10);
  ios_base::sync_with_stdio(false);
  while (tc--) escape();
}
