#include <bits/stdc++.h>
using namespace std;
long long int modInverse(long long int a, long long int m) {
  long long int m0 = m;
  long long int y = 0, x = 1;
  if (m == 1) return 0;
  while (a > 1) {
    long long int q = a / m;
    long long int t = m;
    m = a % m, a = t;
    t = y;
    y = x - q * y;
    x = t;
  }
  if (x < 0) x += m0;
  return x;
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long int n = s.size();
  string g;
  cin >> g;
  long long int k;
  cin >> k;
  std::vector<long long int> bad(n);
  for (long long int i = 0; i < n; i++) bad[i] = (g[s[i] - 'a'] == '0');
  std::vector<long long int> presum(n + 1, 0);
  for (long long int i = 0; i < n; i++) {
    presum[i + 1] = presum[i] + bad[i];
  }
  long long int p1 = 937, p2 = 991;
  std::vector<long long int> p1pow(n), p2pow(n);
  p1pow[0] = 1;
  p2pow[0] = 1;
  for (long long int i = 1; i < n; i++) {
    p1pow[i] = (p1pow[i - 1] * p1) % 1000000007;
    p2pow[i] = (p2pow[i - 1] * p2) % 1000000007;
  }
  std::vector<long long int> h1(n + 1, 0), h2(n + 1, 0);
  h1[0] = p1pow[0] * s[0];
  h2[0] = p2pow[0] * s[0];
  for (long long int i = 1; i < n; ++i) {
    h1[i] = (h1[i - 1] + p1pow[i] * s[i]) % 1000000007;
    h2[i] = (h2[i - 1] + p2pow[i] * s[i]) % 1000000007;
  }
  std::vector<long long int> mm1(n), mm2(n);
  for (long long int i = 0; i < n; i++) {
    mm1[i] = modInverse(p1pow[i], 1000000007);
    mm2[i] = modInverse(p2pow[i], 1000000007);
  }
  set<pair<long long int, long long int> > goodhash;
  for (long long int i = 0; i < n; i++) {
    for (long long int e = i; e < n; e++) {
      if (presum[e + 1] - presum[i] <= k) {
        long long int l = i, r = e;
        if (r < l)
          continue;
        else if (l == 0) {
          goodhash.insert({h1[r], h2[r]});
        } else {
          long long int hash1 = 0, hash2 = 0;
          hash1 = (h1[r] - h1[l - 1] + 1000000007) * mm1[l] % 1000000007;
          hash2 = (h2[r] - h2[l - 1] + 1000000007) * mm2[l] % 1000000007;
          goodhash.insert({hash1, hash2});
        }
      }
    }
  }
  cout << goodhash.size();
  return 0;
}
