#include <bits/stdc++.h>
using namespace std;
long long n, k;
string s, temp;
long long trie[1200005][26];
long long nex = 1;
void solve() {
  cin >> s;
  n = (long long)s.size();
  cin >> temp;
  cin >> k;
  for (long long i = 0; i < n; ++i) {
    long long curr = 0;
    long long j = i;
    long long cnt = 0;
    while (j < n) {
      cnt += 1 - (temp[s[j] - 'a'] - '0');
      if (cnt > k) break;
      if (trie[curr][s[j] - 'a'] == 0) trie[curr][s[j] - 'a'] = nex++;
      curr = trie[curr][s[j] - 'a'];
      j++;
    }
  }
  cout << nex - 1 << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  srand(static_cast<unsigned>(time(0)));
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
