#include <bits/stdc++.h>
using namespace std;
void c_p_c() {}
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
long long make_hash(string here) {
  long long ans = 0;
  long long mod = 1e9 + 7;
  for (int i = 0; i < here.size(); i++) {
    ans = (ans + ((here[i]) * (long long)binpow(33, i, mod)) % mod) % mod;
  }
  return ans;
}
long long make_hash2(string here) {
  long long mod = 1e7 + 3;
  long long ans = 0;
  for (int i = 0; i < here.size(); i++) {
    ans = (ans + ((here[i]) * (long long)binpow(32, i, mod)) % mod) % mod;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  c_p_c();
  string s;
  string isgood;
  int k;
  cin >> s >> isgood >> k;
  set<pair<long long, long long>> done;
  long long mod = 1e9 + 3;
  for (int i = 0; i < s.size(); i++) {
    long long badone = 0;
    long long curhash = 0;
    long long curhash2 = 0;
    for (int j = i; j < s.size(); j++) {
      if (isgood[s[j] - 'a'] == '0') badone += 1;
      curhash = (curhash + binpow(300, j - i, 1000000009) * s[j]) % 1000000009;
      curhash2 = (curhash2 + binpow(252, j - i, mod) * s[j]) % mod;
      if (badone <= k) {
        done.insert({curhash, curhash2});
      }
    }
  }
  cout << done.size();
  return 0;
}
