#include <bits/stdc++.h>
using namespace std;
const int ms = 1e5 * 27, sigma = 27;
int check[26];
int trie[ms][sigma], z;
bool terminal[ms];
void init() {
  memset(trie[0], 0, sizeof(trie[0]));
  z = 1;
}
int get_id(char c) { return c - 'a'; }
void insert(string &p) {
  int cur = 0;
  for (int i = 0; i < int(p.size()); i++) {
    int id = get_id(p[i]);
    if (trie[cur][id] == 0) {
      memset(trie[z], 0, sizeof(trie[z]));
      trie[cur][id] = z++;
    }
    cur = trie[cur][id];
    terminal[cur] = 1;
  }
}
int ans(int cur) {
  int ret = terminal[cur];
  for (int i = 0; i < sigma; i++) {
    if (trie[cur][i] != 0) ret += ans(trie[cur][i]);
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  init();
  string str, good;
  int k;
  cin >> str >> good >> k;
  for (int i = 0; i < int(good.size()); i++) {
    if (good[i] - '0') check[i] = 1;
  }
  vector<int> strG;
  int aux = 0;
  for (int i = 0; i < int(str.size()); i++) {
    aux += !check[str[i] - 'a'];
    strG.push_back(aux);
  }
  for (int i = 0; i < int(str.size()); i++) {
    int up = upper_bound(strG.begin(), strG.end(),
                         strG[i] + k - !check[str[i] - 'a']) -
             strG.begin();
    string ins = str.substr(i, up - i);
    insert(ins);
  }
  if (!check[str[0] - 'a']) terminal[0] = 0;
  cout << ans(0) << "\n";
  return 0;
}
