#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> operator+(pair<long long, long long> a,
                                     long long x) {
  return {a.first + x, a.second + x};
}
pair<long long, long long> operator-(pair<long long, long long> a,
                                     long long x) {
  return {a.first - x, a.second - x};
}
pair<long long, long long> operator*(pair<long long, long long> a,
                                     long long x) {
  return {a.first * x, a.second * x};
}
pair<long long, long long> operator+(pair<long long, long long> x,
                                     pair<long long, long long> y) {
  return {x.first + y.first, x.second + y.second};
}
pair<long long, long long> operator-(pair<long long, long long> x,
                                     pair<long long, long long> y) {
  return {x.first - y.first, x.second - y.second};
}
pair<long long, long long> operator*(pair<long long, long long> x,
                                     pair<long long, long long> y) {
  return {x.first * y.first, x.second * y.second};
}
pair<long long, long long> operator%(pair<long long, long long> x,
                                     pair<long long, long long> y) {
  return {x.first % y.first, x.second % y.second};
}
long long bigMod(long long x, long long n, long long mod) {
  if (n == 0) return 1LL;
  long long t = bigMod(x, n / 2, mod);
  t = (t % mod * t % mod) % mod;
  if (n % 2 == 1) {
    t = (t % mod * x % mod) % mod;
  }
  return t;
}
pair<long long, long long> base = {37, 41};
pair<long long, long long> mod = {1000000007, 1000000009};
pair<long long, long long> pwr[1501];
pair<long long, long long> prefHash[1501];
void calcPwr() {
  pwr[0] = {1, 1};
  for (int i = 1; i < 1501; i++) {
    pwr[i] = (pwr[i - 1] * base) % mod;
  }
}
int cumSum[1501];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int i, j, k, l;
  string s, gb;
  cin >> s;
  cin >> gb;
  cin >> k;
  for (i = 1; i <= s.size(); i++) {
    cumSum[i] = gb[s[i - 1] - 'a'] - '0';
    cumSum[i] += cumSum[i - 1];
  }
  calcPwr();
  set<pair<long long, long long> > ans;
  for (l = 1; l <= s.size(); l++) {
    pair<long long, long long> h = {0, 0};
    for (i = 1; i <= l; i++) {
      h = (h + (pwr[l - i] * (s[i - 1] - 'a' + 1)) % mod) % mod;
    }
    i = 1;
    j = i + l - 1;
    if (l - cumSum[j] - cumSum[i - 1] <= k) {
      ans.insert(h);
    }
    for (i = l + 1; i <= s.size(); i++) {
      h = h - (pwr[l - 1] * (s[i - l - 1] - 'a' + 1)) % mod;
      h = (h + mod) % mod;
      h = (h * base) % mod;
      h = (h + (s[i - 1] - 'a' + 1)) % mod;
      j = i - l + 1;
      if (l - (cumSum[i] - cumSum[j - 1]) <= k) {
        ans.insert(h);
      }
    }
  }
  cout << ans.size();
  return 0;
}
