#include <bits/stdc++.h>
using namespace std;
int const N = 2500;
int const INF = 1e9 + 7;
long long const MOD = 1e9 + 7;
long long P = 31;
map<pair<long long, long long>, bool> used;
int ans;
string s, t;
int k;
long long p1[N], p2[N], h1[N], h2[N];
long long get1(int l, int r) {
  long long h = h1[r];
  if (l > 0) h -= h1[l - 1];
  h *= p1[s.size() - 1 - r];
  return h;
}
long long get2(int l, int r) {
  long long h = h2[r];
  if (l > 0) h = (h - h2[l - 1] + MOD) % MOD;
  h = (h * p2[s.size() - 1 - r]) % MOD;
  return h;
}
int pref[N];
int main() {
  getline(cin, s);
  getline(cin, t);
  cin >> k;
  p1[0] = p2[0] = 1;
  for (int c = 1; c < s.size(); c++) {
    p1[c] = p1[c - 1] * P;
    p2[c] = (p2[c - 1] * P) % MOD;
  }
  h1[0] = s[0] - 'a' + 1;
  h2[0] = (s[0] - 'a' + 1) % MOD;
  for (int c = 1; c < s.size(); c++) {
    h1[c] = h1[c - 1] + p1[c] * (s[c] - 'a' + 1);
    h2[c] = (h2[c - 1] + p2[c] * (s[c] - 'a' + 1)) % MOD;
  }
  for (int c = 0; c < s.size(); c++) {
    if (t[int(s[c] - 'a')] == '0') pref[c] = 1;
    if (c > 0) pref[c] += pref[c - 1];
  }
  for (int c = 0; c < s.size(); c++) {
    for (int i = c; i < s.size(); i++) {
      int kol = pref[i];
      if (c > 0) kol -= pref[c - 1];
      if (kol <= k) {
        pair<long long, long long> cur = {get1(c, i), get2(c, i)};
        if (!used[cur]) {
          ans++;
          used[cur] = true;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
