#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
const int mod = 1e9 + 9;
const int pp = 31;
const int ppp = 56;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, j, k, n;
  string s, t;
  cin >> s >> t >> k;
  n = s.length();
  vector<int> a(n), p(n);
  for (i = 0; i < n; ++i) {
    a[i] = t[s[i] - 'a'] - '0';
  }
  p[0] = a[0];
  for (i = 1; i < n; i++) p[i] = p[i - 1] + a[i];
  set<pair<long long, long long>> sz;
  vector<long long> p_pow(n + 1), pp_pow(n + 1);
  p_pow[0] = 1;
  pp_pow[0] = 1;
  for (i = 1; i <= n; i++) {
    p_pow[i] = (p_pow[i - 1] * pp) % mod;
    pp_pow[i] = (pp_pow[i - 1] * ppp) % mod;
  }
  vector<long long> hsh(n + 1, 0), hshh(n + 1, 0);
  for (i = 0; i < n; i++) {
    hsh[i + 1] = (hsh[i] + p_pow[i] * (s[i] - 'a' + 1)) % mod;
    hshh[i + 1] = (hshh[i] + pp_pow[i] * (s[i] - 'a' + 1)) % mod;
  }
  for (i = 1; i <= n; i++) {
    for (j = 0; j < n - i + 1; ++j) {
      long long cur_h_1 = (hsh[j + i] + mod - hsh[j]) % mod;
      long long cur_h_2 = (hshh[j + i] + mod - hshh[j]) % mod;
      if (j > 0 && (i - p[j + i - 1] + p[j - 1]) <= k)
        sz.insert({cur_h_1 * p_pow[n - j - 1] % mod,
                   cur_h_2 * pp_pow[n - j - 1] % mod});
      else if (j == 0 && (i - p[j + i - 1]) <= k) {
        sz.insert({cur_h_1 * p_pow[n - j - 1] % mod,
                   cur_h_2 * pp_pow[n - j - 1] % mod});
      }
    }
  }
  cout << sz.size();
}
