#include <bits/stdc++.h>
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template <typename T>
inline T Bigmod(T base, T power, T MOD) {
  T ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int main() {
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  int k;
  cin >> k;
  int bad[(int)s.size() + 1];
  memset(bad, 0, sizeof(bad));
  bad[0] = 0;
  for (int i = 0; i < (int)s.size(); i++) {
    if (t[s[i] - 'a'] == '0') {
      bad[i + 1]++;
    }
    bad[i + 1] += bad[i];
  }
  int n = (int)s.size();
  const int p = 31;
  const int m = 1e9 + 9;
  vector<long long> p_pow(n);
  p_pow[0] = 1;
  for (int i = 1; i < n; i++) {
    p_pow[i] = (p_pow[i - 1] * p) % m;
  }
  vector<long long> h(n + 1, 0);
  for (int i = 0; i < n; i++) {
    h[i + 1] = (h[i] + (s[i] - 'a' + 1) * p_pow[i]) % m;
  }
  int cnt = 0;
  for (int l = 1; l <= n; l++) {
    set<long long> hs;
    for (int i = 0; i <= n - l; i++) {
      if (bad[i + l] - bad[i] > k) continue;
      long long cur_h = (h[i + l] + m - h[i]) % m;
      cur_h = (cur_h * p_pow[n - i - 1]) % m;
      hs.insert(cur_h);
    }
    cnt += hs.size();
  }
  cout << cnt << "\n";
  return 0;
}
