#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 100;
const int M = 40 + 5;
const int P = 229;
const int P2 = 229;
const long long MOD = 1e9 + 13;
const long long MOD2 = 1e9 + 7;
const int rx[4] = {1, -1, 0, 0};
const int ry[4] = {0, 0, 1, -1};
vector<int> h;
vector<int> h2;
long long p[N];
long long p2[N];
long long kol[N];
void Hash(string s) {
  h[0] = int(s[0] - 'a') + 1;
  for (int i = 1; i < (int)s.size(); i++) {
    h[i] = (h[i - 1] * (1ll) * P) % MOD;
    h[i] = (h[i] + (int(s[i] - 'a') + 1)) % MOD;
  }
  h2[0] = int(s[0] - 'a') + 1;
  for (int i = 1; i < (int)s.size(); i++) {
    h2[i] = (h2[i - 1] * (1ll) * P2) % MOD2;
    h2[i] = (h2[i] + (int(s[i] - 'a') + 1)) % MOD2;
  }
}
long long get(int l, int r) {
  int len = r - l + 1;
  int res = h[r];
  if (l > 0) {
    res -= ((h[l - 1] * p[len]) % MOD);
  }
  res += MOD;
  res %= MOD;
  return res;
}
long long get2(int l, int r) {
  int len = r - l + 1;
  int res = h2[r];
  if (l > 0) {
    res -= ((h2[l - 1] * p2[len]) % MOD2);
  }
  res += MOD2;
  res %= MOD2;
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  string s;
  cin >> s;
  string god;
  cin >> god;
  h.resize(s.size());
  h2.resize(s.size());
  int k;
  cin >> k;
  p[0] = 1;
  p2[0] = 1;
  int n = s.size();
  for (int i = 1; i <= n; i++) {
    p[i] = (p[i - 1] * P) % MOD;
    p2[i] = (p2[i - 1] * P2) % MOD2;
  }
  for (int i = 0; i < n; i++) {
    int now = int(s[i] - 'a');
    if (i > 0) kol[i] = kol[i - 1];
    if (god[now] == '0') {
      kol[i]++;
    }
  }
  Hash(s);
  set<pair<int, int> > st;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int ans1 = get(i, j);
      int ans2 = get2(i, j);
      int bad = kol[j];
      if (i > 0) bad -= kol[i - 1];
      if (bad > k) continue;
      st.insert({ans1, ans2});
    }
  }
  cout << st.size();
  return 0;
}
