#include <bits/stdc++.h>
using namespace std;
const int MAX_NUMBER_OF_NODES = 2300 * 1000;
const int MAX_ASCII_CODE = 30;
int x[MAX_NUMBER_OF_NODES][MAX_ASCII_CODE];
int nxt = 1;
int main() {
  for (int i = 0; i < 2300 * 1000; i++) {
    for (int j = 0; j < 30; j++) {
      x[i][j] = -1;
    }
  }
  int K;
  string s, ch;
  cin >> s >> ch >> K;
  int tot = 0;
  for (int i = 0; i < s.size(); i++) {
    int j = i, v = 0;
    int bads = 0;
    while (j < s.size()) {
      if (ch[s[j] - 'a'] == '0') bads++;
      if (bads > K) break;
      if (x[v][s[j] - 'a'] == -1) {
        v = x[v][s[j++] - 'a'] = nxt++;
        tot++;
      } else {
        v = x[v][s[j++] - 'a'];
      }
    }
  }
  cout << tot;
  return 0;
}
